1 /* Tree lowering pass. This pass converts the GENERIC functions-as-trees
2 tree representation into the GIMPLE form.
3 Copyright (C) 2002-2019 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"
68 #include "omp-offload.h"
71 /* Hash set of poisoned variables in a bind expr. */
72 static hash_set
<tree
> *asan_poisoned_variables
= NULL
;
74 enum gimplify_omp_var_data
77 GOVD_EXPLICIT
= 0x000002,
78 GOVD_SHARED
= 0x000004,
79 GOVD_PRIVATE
= 0x000008,
80 GOVD_FIRSTPRIVATE
= 0x000010,
81 GOVD_LASTPRIVATE
= 0x000020,
82 GOVD_REDUCTION
= 0x000040,
85 GOVD_DEBUG_PRIVATE
= 0x000200,
86 GOVD_PRIVATE_OUTER_REF
= 0x000400,
87 GOVD_LINEAR
= 0x000800,
88 GOVD_ALIGNED
= 0x001000,
90 /* Flag for GOVD_MAP: don't copy back. */
91 GOVD_MAP_TO_ONLY
= 0x002000,
93 /* Flag for GOVD_LINEAR or GOVD_LASTPRIVATE: no outer reference. */
94 GOVD_LINEAR_LASTPRIVATE_NO_OUTER
= 0x004000,
96 GOVD_MAP_0LEN_ARRAY
= 0x008000,
98 /* Flag for GOVD_MAP, if it is always, to or always, tofrom mapping. */
99 GOVD_MAP_ALWAYS_TO
= 0x010000,
101 /* Flag for shared vars that are or might be stored to in the region. */
102 GOVD_WRITTEN
= 0x020000,
104 /* Flag for GOVD_MAP, if it is a forced mapping. */
105 GOVD_MAP_FORCE
= 0x040000,
107 /* Flag for GOVD_MAP: must be present already. */
108 GOVD_MAP_FORCE_PRESENT
= 0x080000,
110 /* Flag for GOVD_MAP: only allocate. */
111 GOVD_MAP_ALLOC_ONLY
= 0x100000,
113 /* Flag for GOVD_MAP: only copy back. */
114 GOVD_MAP_FROM_ONLY
= 0x200000,
116 GOVD_NONTEMPORAL
= 0x400000,
118 /* Flag for GOVD_LASTPRIVATE: conditional modifier. */
119 GOVD_LASTPRIVATE_CONDITIONAL
= 0x800000,
121 GOVD_CONDTEMP
= 0x1000000,
123 /* Flag for GOVD_REDUCTION: inscan seen in {in,ex}clusive clause. */
124 GOVD_REDUCTION_INSCAN
= 0x2000000,
126 GOVD_DATA_SHARE_CLASS
= (GOVD_SHARED
| GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
127 | GOVD_LASTPRIVATE
| GOVD_REDUCTION
| GOVD_LINEAR
134 ORT_WORKSHARE
= 0x00,
135 ORT_TASKGROUP
= 0x01,
139 ORT_COMBINED_PARALLEL
= ORT_PARALLEL
| 1,
142 ORT_UNTIED_TASK
= ORT_TASK
| 1,
143 ORT_TASKLOOP
= ORT_TASK
| 2,
144 ORT_UNTIED_TASKLOOP
= ORT_UNTIED_TASK
| 2,
147 ORT_COMBINED_TEAMS
= ORT_TEAMS
| 1,
148 ORT_HOST_TEAMS
= ORT_TEAMS
| 2,
149 ORT_COMBINED_HOST_TEAMS
= ORT_COMBINED_TEAMS
| 2,
152 ORT_TARGET_DATA
= 0x40,
154 /* Data region with offloading. */
156 ORT_COMBINED_TARGET
= ORT_TARGET
| 1,
158 /* OpenACC variants. */
159 ORT_ACC
= 0x100, /* A generic OpenACC region. */
160 ORT_ACC_DATA
= ORT_ACC
| ORT_TARGET_DATA
, /* Data construct. */
161 ORT_ACC_PARALLEL
= ORT_ACC
| ORT_TARGET
, /* Parallel construct */
162 ORT_ACC_KERNELS
= ORT_ACC
| ORT_TARGET
| 2, /* Kernels construct. */
163 ORT_ACC_HOST_DATA
= ORT_ACC
| ORT_TARGET_DATA
| 2, /* Host data. */
165 /* Dummy OpenMP region, used to disable expansion of
166 DECL_VALUE_EXPRs in taskloop pre body. */
170 /* Gimplify hashtable helper. */
172 struct gimplify_hasher
: free_ptr_hash
<elt_t
>
174 static inline hashval_t
hash (const elt_t
*);
175 static inline bool equal (const elt_t
*, const elt_t
*);
180 struct gimplify_ctx
*prev_context
;
182 vec
<gbind
*> bind_expr_stack
;
184 gimple_seq conditional_cleanups
;
188 vec
<tree
> case_labels
;
189 hash_set
<tree
> *live_switch_vars
;
190 /* The formal temporary table. Should this be persistent? */
191 hash_table
<gimplify_hasher
> *temp_htab
;
194 unsigned into_ssa
: 1;
195 unsigned allow_rhs_cond_expr
: 1;
196 unsigned in_cleanup_point_expr
: 1;
197 unsigned keep_stack
: 1;
198 unsigned save_stack
: 1;
199 unsigned in_switch_expr
: 1;
202 enum gimplify_defaultmap_kind
210 struct gimplify_omp_ctx
212 struct gimplify_omp_ctx
*outer_context
;
213 splay_tree variables
;
214 hash_set
<tree
> *privatized_types
;
216 /* Iteration variables in an OMP_FOR. */
217 vec
<tree
> loop_iter_var
;
219 enum omp_clause_default_kind default_kind
;
220 enum omp_region_type region_type
;
223 bool target_firstprivatize_array_bases
;
227 static struct gimplify_ctx
*gimplify_ctxp
;
228 static struct gimplify_omp_ctx
*gimplify_omp_ctxp
;
230 /* Forward declaration. */
231 static enum gimplify_status
gimplify_compound_expr (tree
*, gimple_seq
*, bool);
232 static hash_map
<tree
, tree
> *oacc_declare_returns
;
233 static enum gimplify_status
gimplify_expr (tree
*, gimple_seq
*, gimple_seq
*,
234 bool (*) (tree
), fallback_t
, bool);
236 /* Shorter alias name for the above function for use in gimplify.c
240 gimplify_seq_add_stmt (gimple_seq
*seq_p
, gimple
*gs
)
242 gimple_seq_add_stmt_without_update (seq_p
, gs
);
245 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
246 NULL, a new sequence is allocated. This function is
247 similar to gimple_seq_add_seq, but does not scan the operands.
248 During gimplification, we need to manipulate statement sequences
249 before the def/use vectors have been constructed. */
252 gimplify_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
254 gimple_stmt_iterator si
;
259 si
= gsi_last (*dst_p
);
260 gsi_insert_seq_after_without_update (&si
, src
, GSI_NEW_STMT
);
264 /* Pointer to a list of allocated gimplify_ctx structs to be used for pushing
265 and popping gimplify contexts. */
267 static struct gimplify_ctx
*ctx_pool
= NULL
;
269 /* Return a gimplify context struct from the pool. */
271 static inline struct gimplify_ctx
*
274 struct gimplify_ctx
* c
= ctx_pool
;
277 ctx_pool
= c
->prev_context
;
279 c
= XNEW (struct gimplify_ctx
);
281 memset (c
, '\0', sizeof (*c
));
285 /* Put gimplify context C back into the pool. */
288 ctx_free (struct gimplify_ctx
*c
)
290 c
->prev_context
= ctx_pool
;
294 /* Free allocated ctx stack memory. */
297 free_gimplify_stack (void)
299 struct gimplify_ctx
*c
;
301 while ((c
= ctx_pool
))
303 ctx_pool
= c
->prev_context
;
309 /* Set up a context for the gimplifier. */
312 push_gimplify_context (bool in_ssa
, bool rhs_cond_ok
)
314 struct gimplify_ctx
*c
= ctx_alloc ();
316 c
->prev_context
= gimplify_ctxp
;
318 gimplify_ctxp
->into_ssa
= in_ssa
;
319 gimplify_ctxp
->allow_rhs_cond_expr
= rhs_cond_ok
;
322 /* Tear down a context for the gimplifier. If BODY is non-null, then
323 put the temporaries into the outer BIND_EXPR. Otherwise, put them
326 BODY is not a sequence, but the first tuple in a sequence. */
329 pop_gimplify_context (gimple
*body
)
331 struct gimplify_ctx
*c
= gimplify_ctxp
;
334 && (!c
->bind_expr_stack
.exists ()
335 || c
->bind_expr_stack
.is_empty ()));
336 c
->bind_expr_stack
.release ();
337 gimplify_ctxp
= c
->prev_context
;
340 declare_vars (c
->temps
, body
, false);
342 record_vars (c
->temps
);
349 /* Push a GIMPLE_BIND tuple onto the stack of bindings. */
352 gimple_push_bind_expr (gbind
*bind_stmt
)
354 gimplify_ctxp
->bind_expr_stack
.reserve (8);
355 gimplify_ctxp
->bind_expr_stack
.safe_push (bind_stmt
);
358 /* Pop the first element off the stack of bindings. */
361 gimple_pop_bind_expr (void)
363 gimplify_ctxp
->bind_expr_stack
.pop ();
366 /* Return the first element of the stack of bindings. */
369 gimple_current_bind_expr (void)
371 return gimplify_ctxp
->bind_expr_stack
.last ();
374 /* Return the stack of bindings created during gimplification. */
377 gimple_bind_expr_stack (void)
379 return gimplify_ctxp
->bind_expr_stack
;
382 /* Return true iff there is a COND_EXPR between us and the innermost
383 CLEANUP_POINT_EXPR. This info is used by gimple_push_cleanup. */
386 gimple_conditional_context (void)
388 return gimplify_ctxp
->conditions
> 0;
391 /* Note that we've entered a COND_EXPR. */
394 gimple_push_condition (void)
396 #ifdef ENABLE_GIMPLE_CHECKING
397 if (gimplify_ctxp
->conditions
== 0)
398 gcc_assert (gimple_seq_empty_p (gimplify_ctxp
->conditional_cleanups
));
400 ++(gimplify_ctxp
->conditions
);
403 /* Note that we've left a COND_EXPR. If we're back at unconditional scope
404 now, add any conditional cleanups we've seen to the prequeue. */
407 gimple_pop_condition (gimple_seq
*pre_p
)
409 int conds
= --(gimplify_ctxp
->conditions
);
411 gcc_assert (conds
>= 0);
414 gimplify_seq_add_seq (pre_p
, gimplify_ctxp
->conditional_cleanups
);
415 gimplify_ctxp
->conditional_cleanups
= NULL
;
419 /* A stable comparison routine for use with splay trees and DECLs. */
422 splay_tree_compare_decl_uid (splay_tree_key xa
, splay_tree_key xb
)
427 return DECL_UID (a
) - DECL_UID (b
);
430 /* Create a new omp construct that deals with variable remapping. */
432 static struct gimplify_omp_ctx
*
433 new_omp_context (enum omp_region_type region_type
)
435 struct gimplify_omp_ctx
*c
;
437 c
= XCNEW (struct gimplify_omp_ctx
);
438 c
->outer_context
= gimplify_omp_ctxp
;
439 c
->variables
= splay_tree_new (splay_tree_compare_decl_uid
, 0, 0);
440 c
->privatized_types
= new hash_set
<tree
>;
441 c
->location
= input_location
;
442 c
->region_type
= region_type
;
443 if ((region_type
& ORT_TASK
) == 0)
444 c
->default_kind
= OMP_CLAUSE_DEFAULT_SHARED
;
446 c
->default_kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
447 c
->defaultmap
[GDMK_SCALAR
] = GOVD_MAP
;
448 c
->defaultmap
[GDMK_AGGREGATE
] = GOVD_MAP
;
449 c
->defaultmap
[GDMK_ALLOCATABLE
] = GOVD_MAP
;
450 c
->defaultmap
[GDMK_POINTER
] = GOVD_MAP
;
455 /* Destroy an omp construct that deals with variable remapping. */
458 delete_omp_context (struct gimplify_omp_ctx
*c
)
460 splay_tree_delete (c
->variables
);
461 delete c
->privatized_types
;
462 c
->loop_iter_var
.release ();
466 static void omp_add_variable (struct gimplify_omp_ctx
*, tree
, unsigned int);
467 static bool omp_notice_variable (struct gimplify_omp_ctx
*, tree
, bool);
469 /* Both gimplify the statement T and append it to *SEQ_P. This function
470 behaves exactly as gimplify_stmt, but you don't have to pass T as a
474 gimplify_and_add (tree t
, gimple_seq
*seq_p
)
476 gimplify_stmt (&t
, seq_p
);
479 /* Gimplify statement T into sequence *SEQ_P, and return the first
480 tuple in the sequence of generated tuples for this statement.
481 Return NULL if gimplifying T produced no tuples. */
484 gimplify_and_return_first (tree t
, gimple_seq
*seq_p
)
486 gimple_stmt_iterator last
= gsi_last (*seq_p
);
488 gimplify_and_add (t
, seq_p
);
490 if (!gsi_end_p (last
))
493 return gsi_stmt (last
);
496 return gimple_seq_first_stmt (*seq_p
);
499 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
500 LHS, or for a call argument. */
503 is_gimple_mem_rhs (tree t
)
505 /* If we're dealing with a renamable type, either source or dest must be
506 a renamed variable. */
507 if (is_gimple_reg_type (TREE_TYPE (t
)))
508 return is_gimple_val (t
);
510 return is_gimple_val (t
) || is_gimple_lvalue (t
);
513 /* Return true if T is a CALL_EXPR or an expression that can be
514 assigned to a temporary. Note that this predicate should only be
515 used during gimplification. See the rationale for this in
516 gimplify_modify_expr. */
519 is_gimple_reg_rhs_or_call (tree t
)
521 return (get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
522 || TREE_CODE (t
) == CALL_EXPR
);
525 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that
526 this predicate should only be used during gimplification. See the
527 rationale for this in gimplify_modify_expr. */
530 is_gimple_mem_rhs_or_call (tree t
)
532 /* If we're dealing with a renamable type, either source or dest must be
533 a renamed variable. */
534 if (is_gimple_reg_type (TREE_TYPE (t
)))
535 return is_gimple_val (t
);
537 return (is_gimple_val (t
)
538 || is_gimple_lvalue (t
)
539 || TREE_CLOBBER_P (t
)
540 || TREE_CODE (t
) == CALL_EXPR
);
543 /* Create a temporary with a name derived from VAL. Subroutine of
544 lookup_tmp_var; nobody else should call this function. */
547 create_tmp_from_val (tree val
)
549 /* Drop all qualifiers and address-space information from the value type. */
550 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (val
));
551 tree var
= create_tmp_var (type
, get_name (val
));
552 if (TREE_CODE (TREE_TYPE (var
)) == COMPLEX_TYPE
553 || TREE_CODE (TREE_TYPE (var
)) == VECTOR_TYPE
)
554 DECL_GIMPLE_REG_P (var
) = 1;
558 /* Create a temporary to hold the value of VAL. If IS_FORMAL, try to reuse
559 an existing expression temporary. */
562 lookup_tmp_var (tree val
, bool is_formal
)
566 /* If not optimizing, never really reuse a temporary. local-alloc
567 won't allocate any variable that is used in more than one basic
568 block, which means it will go into memory, causing much extra
569 work in reload and final and poorer code generation, outweighing
570 the extra memory allocation here. */
571 if (!optimize
|| !is_formal
|| TREE_SIDE_EFFECTS (val
))
572 ret
= create_tmp_from_val (val
);
579 if (!gimplify_ctxp
->temp_htab
)
580 gimplify_ctxp
->temp_htab
= new hash_table
<gimplify_hasher
> (1000);
581 slot
= gimplify_ctxp
->temp_htab
->find_slot (&elt
, INSERT
);
584 elt_p
= XNEW (elt_t
);
586 elt_p
->temp
= ret
= create_tmp_from_val (val
);
599 /* Helper for get_formal_tmp_var and get_initialized_tmp_var. */
602 internal_get_tmp_var (tree val
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
603 bool is_formal
, bool allow_ssa
)
607 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we
608 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */
609 gimplify_expr (&val
, pre_p
, post_p
, is_gimple_reg_rhs_or_call
,
613 && gimplify_ctxp
->into_ssa
614 && is_gimple_reg_type (TREE_TYPE (val
)))
616 t
= make_ssa_name (TYPE_MAIN_VARIANT (TREE_TYPE (val
)));
617 if (! gimple_in_ssa_p (cfun
))
619 const char *name
= get_name (val
);
621 SET_SSA_NAME_VAR_OR_IDENTIFIER (t
, create_tmp_var_name (name
));
625 t
= lookup_tmp_var (val
, is_formal
);
627 mod
= build2 (INIT_EXPR
, TREE_TYPE (t
), t
, unshare_expr (val
));
629 SET_EXPR_LOCATION (mod
, EXPR_LOC_OR_LOC (val
, input_location
));
631 /* gimplify_modify_expr might want to reduce this further. */
632 gimplify_and_add (mod
, pre_p
);
638 /* Return a formal temporary variable initialized with VAL. PRE_P is as
639 in gimplify_expr. Only use this function if:
641 1) The value of the unfactored expression represented by VAL will not
642 change between the initialization and use of the temporary, and
643 2) The temporary will not be otherwise modified.
645 For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
646 and #2 means it is inappropriate for && temps.
648 For other cases, use get_initialized_tmp_var instead. */
651 get_formal_tmp_var (tree val
, gimple_seq
*pre_p
)
653 return internal_get_tmp_var (val
, pre_p
, NULL
, true, true);
656 /* Return a temporary variable initialized with VAL. PRE_P and POST_P
657 are as in gimplify_expr. */
660 get_initialized_tmp_var (tree val
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
663 return internal_get_tmp_var (val
, pre_p
, post_p
, false, allow_ssa
);
666 /* Declare all the variables in VARS in SCOPE. If DEBUG_INFO is true,
667 generate debug info for them; otherwise don't. */
670 declare_vars (tree vars
, gimple
*gs
, bool debug_info
)
677 gbind
*scope
= as_a
<gbind
*> (gs
);
679 temps
= nreverse (last
);
681 block
= gimple_bind_block (scope
);
682 gcc_assert (!block
|| TREE_CODE (block
) == BLOCK
);
683 if (!block
|| !debug_info
)
685 DECL_CHAIN (last
) = gimple_bind_vars (scope
);
686 gimple_bind_set_vars (scope
, temps
);
690 /* We need to attach the nodes both to the BIND_EXPR and to its
691 associated BLOCK for debugging purposes. The key point here
692 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR
693 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */
694 if (BLOCK_VARS (block
))
695 BLOCK_VARS (block
) = chainon (BLOCK_VARS (block
), temps
);
698 gimple_bind_set_vars (scope
,
699 chainon (gimple_bind_vars (scope
), temps
));
700 BLOCK_VARS (block
) = temps
;
706 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound
707 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if
708 no such upper bound can be obtained. */
711 force_constant_size (tree var
)
713 /* The only attempt we make is by querying the maximum size of objects
714 of the variable's type. */
716 HOST_WIDE_INT max_size
;
718 gcc_assert (VAR_P (var
));
720 max_size
= max_int_size_in_bytes (TREE_TYPE (var
));
722 gcc_assert (max_size
>= 0);
725 = build_int_cst (TREE_TYPE (DECL_SIZE_UNIT (var
)), max_size
);
727 = build_int_cst (TREE_TYPE (DECL_SIZE (var
)), max_size
* BITS_PER_UNIT
);
730 /* Push the temporary variable TMP into the current binding. */
733 gimple_add_tmp_var_fn (struct function
*fn
, tree tmp
)
735 gcc_assert (!DECL_CHAIN (tmp
) && !DECL_SEEN_IN_BIND_EXPR_P (tmp
));
737 /* Later processing assumes that the object size is constant, which might
738 not be true at this point. Force the use of a constant upper bound in
740 if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp
)))
741 force_constant_size (tmp
);
743 DECL_CONTEXT (tmp
) = fn
->decl
;
744 DECL_SEEN_IN_BIND_EXPR_P (tmp
) = 1;
746 record_vars_into (tmp
, fn
->decl
);
749 /* Push the temporary variable TMP into the current binding. */
752 gimple_add_tmp_var (tree tmp
)
754 gcc_assert (!DECL_CHAIN (tmp
) && !DECL_SEEN_IN_BIND_EXPR_P (tmp
));
756 /* Later processing assumes that the object size is constant, which might
757 not be true at this point. Force the use of a constant upper bound in
759 if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp
)))
760 force_constant_size (tmp
);
762 DECL_CONTEXT (tmp
) = current_function_decl
;
763 DECL_SEEN_IN_BIND_EXPR_P (tmp
) = 1;
767 DECL_CHAIN (tmp
) = gimplify_ctxp
->temps
;
768 gimplify_ctxp
->temps
= tmp
;
770 /* Mark temporaries local within the nearest enclosing parallel. */
771 if (gimplify_omp_ctxp
)
773 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
775 && (ctx
->region_type
== ORT_WORKSHARE
776 || ctx
->region_type
== ORT_TASKGROUP
777 || ctx
->region_type
== ORT_SIMD
778 || ctx
->region_type
== ORT_ACC
))
779 ctx
= ctx
->outer_context
;
781 omp_add_variable (ctx
, tmp
, GOVD_LOCAL
| GOVD_SEEN
);
790 /* This case is for nested functions. We need to expose the locals
792 body_seq
= gimple_body (current_function_decl
);
793 declare_vars (tmp
, gimple_seq_first_stmt (body_seq
), false);
799 /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
800 nodes that are referenced more than once in GENERIC functions. This is
801 necessary because gimplification (translation into GIMPLE) is performed
802 by modifying tree nodes in-place, so gimplication of a shared node in a
803 first context could generate an invalid GIMPLE form in a second context.
805 This is achieved with a simple mark/copy/unmark algorithm that walks the
806 GENERIC representation top-down, marks nodes with TREE_VISITED the first
807 time it encounters them, duplicates them if they already have TREE_VISITED
808 set, and finally removes the TREE_VISITED marks it has set.
810 The algorithm works only at the function level, i.e. it generates a GENERIC
811 representation of a function with no nodes shared within the function when
812 passed a GENERIC function (except for nodes that are allowed to be shared).
814 At the global level, it is also necessary to unshare tree nodes that are
815 referenced in more than one function, for the same aforementioned reason.
816 This requires some cooperation from the front-end. There are 2 strategies:
818 1. Manual unsharing. The front-end needs to call unshare_expr on every
819 expression that might end up being shared across functions.
821 2. Deep unsharing. This is an extension of regular unsharing. Instead
822 of calling unshare_expr on expressions that might be shared across
823 functions, the front-end pre-marks them with TREE_VISITED. This will
824 ensure that they are unshared on the first reference within functions
825 when the regular unsharing algorithm runs. The counterpart is that
826 this algorithm must look deeper than for manual unsharing, which is
827 specified by LANG_HOOKS_DEEP_UNSHARING.
829 If there are only few specific cases of node sharing across functions, it is
830 probably easier for a front-end to unshare the expressions manually. On the
831 contrary, if the expressions generated at the global level are as widespread
832 as expressions generated within functions, deep unsharing is very likely the
835 /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
836 These nodes model computations that must be done once. If we were to
837 unshare something like SAVE_EXPR(i++), the gimplification process would
838 create wrong code. However, if DATA is non-null, it must hold a pointer
839 set that is used to unshare the subtrees of these nodes. */
842 mostly_copy_tree_r (tree
*tp
, int *walk_subtrees
, void *data
)
845 enum tree_code code
= TREE_CODE (t
);
847 /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
848 copy their subtrees if we can make sure to do it only once. */
849 if (code
== SAVE_EXPR
|| code
== TARGET_EXPR
|| code
== BIND_EXPR
)
851 if (data
&& !((hash_set
<tree
> *)data
)->add (t
))
857 /* Stop at types, decls, constants like copy_tree_r. */
858 else if (TREE_CODE_CLASS (code
) == tcc_type
859 || TREE_CODE_CLASS (code
) == tcc_declaration
860 || TREE_CODE_CLASS (code
) == tcc_constant
)
863 /* Cope with the statement expression extension. */
864 else if (code
== STATEMENT_LIST
)
867 /* Leave the bulk of the work to copy_tree_r itself. */
869 copy_tree_r (tp
, walk_subtrees
, NULL
);
874 /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
875 If *TP has been visited already, then *TP is deeply copied by calling
876 mostly_copy_tree_r. DATA is passed to mostly_copy_tree_r unmodified. */
879 copy_if_shared_r (tree
*tp
, int *walk_subtrees
, void *data
)
882 enum tree_code code
= TREE_CODE (t
);
884 /* Skip types, decls, and constants. But we do want to look at their
885 types and the bounds of types. Mark them as visited so we properly
886 unmark their subtrees on the unmark pass. If we've already seen them,
887 don't look down further. */
888 if (TREE_CODE_CLASS (code
) == tcc_type
889 || TREE_CODE_CLASS (code
) == tcc_declaration
890 || TREE_CODE_CLASS (code
) == tcc_constant
)
892 if (TREE_VISITED (t
))
895 TREE_VISITED (t
) = 1;
898 /* If this node has been visited already, unshare it and don't look
900 else if (TREE_VISITED (t
))
902 walk_tree (tp
, mostly_copy_tree_r
, data
, NULL
);
906 /* Otherwise, mark the node as visited and keep looking. */
908 TREE_VISITED (t
) = 1;
913 /* Unshare most of the shared trees rooted at *TP. DATA is passed to the
914 copy_if_shared_r callback unmodified. */
917 copy_if_shared (tree
*tp
, void *data
)
919 walk_tree (tp
, copy_if_shared_r
, data
, NULL
);
922 /* Unshare all the trees in the body of FNDECL, as well as in the bodies of
923 any nested functions. */
926 unshare_body (tree fndecl
)
928 struct cgraph_node
*cgn
= cgraph_node::get (fndecl
);
929 /* If the language requires deep unsharing, we need a pointer set to make
930 sure we don't repeatedly unshare subtrees of unshareable nodes. */
931 hash_set
<tree
> *visited
932 = lang_hooks
.deep_unsharing
? new hash_set
<tree
> : NULL
;
934 copy_if_shared (&DECL_SAVED_TREE (fndecl
), visited
);
935 copy_if_shared (&DECL_SIZE (DECL_RESULT (fndecl
)), visited
);
936 copy_if_shared (&DECL_SIZE_UNIT (DECL_RESULT (fndecl
)), visited
);
941 for (cgn
= cgn
->nested
; cgn
; cgn
= cgn
->next_nested
)
942 unshare_body (cgn
->decl
);
945 /* Callback for walk_tree to unmark the visited trees rooted at *TP.
946 Subtrees are walked until the first unvisited node is encountered. */
949 unmark_visited_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
953 /* If this node has been visited, unmark it and keep looking. */
954 if (TREE_VISITED (t
))
955 TREE_VISITED (t
) = 0;
957 /* Otherwise, don't look any deeper. */
964 /* Unmark the visited trees rooted at *TP. */
967 unmark_visited (tree
*tp
)
969 walk_tree (tp
, unmark_visited_r
, NULL
, NULL
);
972 /* Likewise, but mark all trees as not visited. */
975 unvisit_body (tree fndecl
)
977 struct cgraph_node
*cgn
= cgraph_node::get (fndecl
);
979 unmark_visited (&DECL_SAVED_TREE (fndecl
));
980 unmark_visited (&DECL_SIZE (DECL_RESULT (fndecl
)));
981 unmark_visited (&DECL_SIZE_UNIT (DECL_RESULT (fndecl
)));
984 for (cgn
= cgn
->nested
; cgn
; cgn
= cgn
->next_nested
)
985 unvisit_body (cgn
->decl
);
988 /* Unconditionally make an unshared copy of EXPR. This is used when using
989 stored expressions which span multiple functions, such as BINFO_VTABLE,
990 as the normal unsharing process can't tell that they're shared. */
993 unshare_expr (tree expr
)
995 walk_tree (&expr
, mostly_copy_tree_r
, NULL
, NULL
);
999 /* Worker for unshare_expr_without_location. */
1002 prune_expr_location (tree
*tp
, int *walk_subtrees
, void *)
1005 SET_EXPR_LOCATION (*tp
, UNKNOWN_LOCATION
);
1011 /* Similar to unshare_expr but also prune all expression locations
1015 unshare_expr_without_location (tree expr
)
1017 walk_tree (&expr
, mostly_copy_tree_r
, NULL
, NULL
);
1019 walk_tree (&expr
, prune_expr_location
, NULL
, NULL
);
1023 /* Return the EXPR_LOCATION of EXPR, if it (maybe recursively) has
1024 one, OR_ELSE otherwise. The location of a STATEMENT_LISTs
1025 comprising at least one DEBUG_BEGIN_STMT followed by exactly one
1026 EXPR is the location of the EXPR. */
1029 rexpr_location (tree expr
, location_t or_else
= UNKNOWN_LOCATION
)
1034 if (EXPR_HAS_LOCATION (expr
))
1035 return EXPR_LOCATION (expr
);
1037 if (TREE_CODE (expr
) != STATEMENT_LIST
)
1040 tree_stmt_iterator i
= tsi_start (expr
);
1043 while (!tsi_end_p (i
) && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
1049 if (!found
|| !tsi_one_before_end_p (i
))
1052 return rexpr_location (tsi_stmt (i
), or_else
);
1055 /* Return TRUE iff EXPR (maybe recursively) has a location; see
1056 rexpr_location for the potential recursion. */
1059 rexpr_has_location (tree expr
)
1061 return rexpr_location (expr
) != UNKNOWN_LOCATION
;
1065 /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
1066 contain statements and have a value. Assign its value to a temporary
1067 and give it void_type_node. Return the temporary, or NULL_TREE if
1068 WRAPPER was already void. */
1071 voidify_wrapper_expr (tree wrapper
, tree temp
)
1073 tree type
= TREE_TYPE (wrapper
);
1074 if (type
&& !VOID_TYPE_P (type
))
1078 /* Set p to point to the body of the wrapper. Loop until we find
1079 something that isn't a wrapper. */
1080 for (p
= &wrapper
; p
&& *p
; )
1082 switch (TREE_CODE (*p
))
1085 TREE_SIDE_EFFECTS (*p
) = 1;
1086 TREE_TYPE (*p
) = void_type_node
;
1087 /* For a BIND_EXPR, the body is operand 1. */
1088 p
= &BIND_EXPR_BODY (*p
);
1091 case CLEANUP_POINT_EXPR
:
1092 case TRY_FINALLY_EXPR
:
1093 case TRY_CATCH_EXPR
:
1094 TREE_SIDE_EFFECTS (*p
) = 1;
1095 TREE_TYPE (*p
) = void_type_node
;
1096 p
= &TREE_OPERAND (*p
, 0);
1099 case STATEMENT_LIST
:
1101 tree_stmt_iterator i
= tsi_last (*p
);
1102 TREE_SIDE_EFFECTS (*p
) = 1;
1103 TREE_TYPE (*p
) = void_type_node
;
1104 p
= tsi_end_p (i
) ? NULL
: tsi_stmt_ptr (i
);
1109 /* Advance to the last statement. Set all container types to
1111 for (; TREE_CODE (*p
) == COMPOUND_EXPR
; p
= &TREE_OPERAND (*p
, 1))
1113 TREE_SIDE_EFFECTS (*p
) = 1;
1114 TREE_TYPE (*p
) = void_type_node
;
1118 case TRANSACTION_EXPR
:
1119 TREE_SIDE_EFFECTS (*p
) = 1;
1120 TREE_TYPE (*p
) = void_type_node
;
1121 p
= &TRANSACTION_EXPR_BODY (*p
);
1125 /* Assume that any tree upon which voidify_wrapper_expr is
1126 directly called is a wrapper, and that its body is op0. */
1129 TREE_SIDE_EFFECTS (*p
) = 1;
1130 TREE_TYPE (*p
) = void_type_node
;
1131 p
= &TREE_OPERAND (*p
, 0);
1139 if (p
== NULL
|| IS_EMPTY_STMT (*p
))
1143 /* The wrapper is on the RHS of an assignment that we're pushing
1145 gcc_assert (TREE_CODE (temp
) == INIT_EXPR
1146 || TREE_CODE (temp
) == MODIFY_EXPR
);
1147 TREE_OPERAND (temp
, 1) = *p
;
1152 temp
= create_tmp_var (type
, "retval");
1153 *p
= build2 (INIT_EXPR
, type
, temp
, *p
);
1162 /* Prepare calls to builtins to SAVE and RESTORE the stack as well as
1163 a temporary through which they communicate. */
1166 build_stack_save_restore (gcall
**save
, gcall
**restore
)
1170 *save
= gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_SAVE
), 0);
1171 tmp_var
= create_tmp_var (ptr_type_node
, "saved_stack");
1172 gimple_call_set_lhs (*save
, tmp_var
);
1175 = gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_RESTORE
),
1179 /* Generate IFN_ASAN_MARK call that poisons shadow of a for DECL variable. */
1182 build_asan_poison_call_expr (tree decl
)
1184 /* Do not poison variables that have size equal to zero. */
1185 tree unit_size
= DECL_SIZE_UNIT (decl
);
1186 if (zerop (unit_size
))
1189 tree base
= build_fold_addr_expr (decl
);
1191 return build_call_expr_internal_loc (UNKNOWN_LOCATION
, IFN_ASAN_MARK
,
1193 build_int_cst (integer_type_node
,
1198 /* Generate IFN_ASAN_MARK call that would poison or unpoison, depending
1199 on POISON flag, shadow memory of a DECL variable. The call will be
1200 put on location identified by IT iterator, where BEFORE flag drives
1201 position where the stmt will be put. */
1204 asan_poison_variable (tree decl
, bool poison
, gimple_stmt_iterator
*it
,
1207 tree unit_size
= DECL_SIZE_UNIT (decl
);
1208 tree base
= build_fold_addr_expr (decl
);
1210 /* Do not poison variables that have size equal to zero. */
1211 if (zerop (unit_size
))
1214 /* It's necessary to have all stack variables aligned to ASAN granularity
1216 if (DECL_ALIGN_UNIT (decl
) <= ASAN_SHADOW_GRANULARITY
)
1217 SET_DECL_ALIGN (decl
, BITS_PER_UNIT
* ASAN_SHADOW_GRANULARITY
);
1219 HOST_WIDE_INT flags
= poison
? ASAN_MARK_POISON
: ASAN_MARK_UNPOISON
;
1222 = gimple_build_call_internal (IFN_ASAN_MARK
, 3,
1223 build_int_cst (integer_type_node
, flags
),
1227 gsi_insert_before (it
, g
, GSI_NEW_STMT
);
1229 gsi_insert_after (it
, g
, GSI_NEW_STMT
);
1232 /* Generate IFN_ASAN_MARK internal call that depending on POISON flag
1233 either poisons or unpoisons a DECL. Created statement is appended
1234 to SEQ_P gimple sequence. */
1237 asan_poison_variable (tree decl
, bool poison
, gimple_seq
*seq_p
)
1239 gimple_stmt_iterator it
= gsi_last (*seq_p
);
1240 bool before
= false;
1245 asan_poison_variable (decl
, poison
, &it
, before
);
1248 /* Sort pair of VAR_DECLs A and B by DECL_UID. */
1251 sort_by_decl_uid (const void *a
, const void *b
)
1253 const tree
*t1
= (const tree
*)a
;
1254 const tree
*t2
= (const tree
*)b
;
1256 int uid1
= DECL_UID (*t1
);
1257 int uid2
= DECL_UID (*t2
);
1261 else if (uid1
> uid2
)
1267 /* Generate IFN_ASAN_MARK internal call for all VARIABLES
1268 depending on POISON flag. Created statement is appended
1269 to SEQ_P gimple sequence. */
1272 asan_poison_variables (hash_set
<tree
> *variables
, bool poison
, gimple_seq
*seq_p
)
1274 unsigned c
= variables
->elements ();
1278 auto_vec
<tree
> sorted_variables (c
);
1280 for (hash_set
<tree
>::iterator it
= variables
->begin ();
1281 it
!= variables
->end (); ++it
)
1282 sorted_variables
.safe_push (*it
);
1284 sorted_variables
.qsort (sort_by_decl_uid
);
1288 FOR_EACH_VEC_ELT (sorted_variables
, i
, var
)
1290 asan_poison_variable (var
, poison
, seq_p
);
1292 /* Add use_after_scope_memory attribute for the variable in order
1293 to prevent re-written into SSA. */
1294 if (!lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE
,
1295 DECL_ATTRIBUTES (var
)))
1296 DECL_ATTRIBUTES (var
)
1297 = tree_cons (get_identifier (ASAN_USE_AFTER_SCOPE_ATTRIBUTE
),
1299 DECL_ATTRIBUTES (var
));
1303 /* Gimplify a BIND_EXPR. Just voidify and recurse. */
1305 static enum gimplify_status
1306 gimplify_bind_expr (tree
*expr_p
, gimple_seq
*pre_p
)
1308 tree bind_expr
= *expr_p
;
1309 bool old_keep_stack
= gimplify_ctxp
->keep_stack
;
1310 bool old_save_stack
= gimplify_ctxp
->save_stack
;
1313 gimple_seq body
, cleanup
;
1315 location_t start_locus
= 0, end_locus
= 0;
1316 tree ret_clauses
= NULL
;
1318 tree temp
= voidify_wrapper_expr (bind_expr
, NULL
);
1320 /* Mark variables seen in this bind expr. */
1321 for (t
= BIND_EXPR_VARS (bind_expr
); t
; t
= DECL_CHAIN (t
))
1325 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
1327 /* Mark variable as local. */
1328 if (ctx
&& ctx
->region_type
!= ORT_NONE
&& !DECL_EXTERNAL (t
))
1330 if (! DECL_SEEN_IN_BIND_EXPR_P (t
)
1331 || splay_tree_lookup (ctx
->variables
,
1332 (splay_tree_key
) t
) == NULL
)
1334 if (ctx
->region_type
== ORT_SIMD
1335 && TREE_ADDRESSABLE (t
)
1336 && !TREE_STATIC (t
))
1337 omp_add_variable (ctx
, t
, GOVD_PRIVATE
| GOVD_SEEN
);
1339 omp_add_variable (ctx
, t
, GOVD_LOCAL
| GOVD_SEEN
);
1341 /* Static locals inside of target construct or offloaded
1342 routines need to be "omp declare target". */
1343 if (TREE_STATIC (t
))
1344 for (; ctx
; ctx
= ctx
->outer_context
)
1345 if ((ctx
->region_type
& ORT_TARGET
) != 0)
1347 if (!lookup_attribute ("omp declare target",
1348 DECL_ATTRIBUTES (t
)))
1350 tree id
= get_identifier ("omp declare target");
1352 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
1353 varpool_node
*node
= varpool_node::get (t
);
1356 node
->offloadable
= 1;
1357 if (ENABLE_OFFLOADING
&& !DECL_EXTERNAL (t
))
1359 g
->have_offload
= true;
1361 vec_safe_push (offload_vars
, t
);
1369 DECL_SEEN_IN_BIND_EXPR_P (t
) = 1;
1371 if (DECL_HARD_REGISTER (t
) && !is_global_var (t
) && cfun
)
1372 cfun
->has_local_explicit_reg_vars
= true;
1375 /* Preliminarily mark non-addressed complex variables as eligible
1376 for promotion to gimple registers. We'll transform their uses
1378 if ((TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
1379 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
1380 && !TREE_THIS_VOLATILE (t
)
1381 && (VAR_P (t
) && !DECL_HARD_REGISTER (t
))
1382 && !needs_to_live_in_memory (t
))
1383 DECL_GIMPLE_REG_P (t
) = 1;
1386 bind_stmt
= gimple_build_bind (BIND_EXPR_VARS (bind_expr
), NULL
,
1387 BIND_EXPR_BLOCK (bind_expr
));
1388 gimple_push_bind_expr (bind_stmt
);
1390 gimplify_ctxp
->keep_stack
= false;
1391 gimplify_ctxp
->save_stack
= false;
1393 /* Gimplify the body into the GIMPLE_BIND tuple's body. */
1395 gimplify_stmt (&BIND_EXPR_BODY (bind_expr
), &body
);
1396 gimple_bind_set_body (bind_stmt
, body
);
1398 /* Source location wise, the cleanup code (stack_restore and clobbers)
1399 belongs to the end of the block, so propagate what we have. The
1400 stack_save operation belongs to the beginning of block, which we can
1401 infer from the bind_expr directly if the block has no explicit
1403 if (BIND_EXPR_BLOCK (bind_expr
))
1405 end_locus
= BLOCK_SOURCE_END_LOCATION (BIND_EXPR_BLOCK (bind_expr
));
1406 start_locus
= BLOCK_SOURCE_LOCATION (BIND_EXPR_BLOCK (bind_expr
));
1408 if (start_locus
== 0)
1409 start_locus
= EXPR_LOCATION (bind_expr
);
1414 /* If the code both contains VLAs and calls alloca, then we cannot reclaim
1415 the stack space allocated to the VLAs. */
1416 if (gimplify_ctxp
->save_stack
&& !gimplify_ctxp
->keep_stack
)
1418 gcall
*stack_restore
;
1420 /* Save stack on entry and restore it on exit. Add a try_finally
1421 block to achieve this. */
1422 build_stack_save_restore (&stack_save
, &stack_restore
);
1424 gimple_set_location (stack_save
, start_locus
);
1425 gimple_set_location (stack_restore
, end_locus
);
1427 gimplify_seq_add_stmt (&cleanup
, stack_restore
);
1430 /* Add clobbers for all variables that go out of scope. */
1431 for (t
= BIND_EXPR_VARS (bind_expr
); t
; t
= DECL_CHAIN (t
))
1434 && !is_global_var (t
)
1435 && DECL_CONTEXT (t
) == current_function_decl
)
1437 if (!DECL_HARD_REGISTER (t
)
1438 && !TREE_THIS_VOLATILE (t
)
1439 && !DECL_HAS_VALUE_EXPR_P (t
)
1440 /* Only care for variables that have to be in memory. Others
1441 will be rewritten into SSA names, hence moved to the
1443 && !is_gimple_reg (t
)
1444 && flag_stack_reuse
!= SR_NONE
)
1446 tree clobber
= build_clobber (TREE_TYPE (t
));
1447 gimple
*clobber_stmt
;
1448 clobber_stmt
= gimple_build_assign (t
, clobber
);
1449 gimple_set_location (clobber_stmt
, end_locus
);
1450 gimplify_seq_add_stmt (&cleanup
, clobber_stmt
);
1453 if (flag_openacc
&& oacc_declare_returns
!= NULL
)
1455 tree
*c
= oacc_declare_returns
->get (t
);
1459 OMP_CLAUSE_CHAIN (*c
) = ret_clauses
;
1463 oacc_declare_returns
->remove (t
);
1465 if (oacc_declare_returns
->is_empty ())
1467 delete oacc_declare_returns
;
1468 oacc_declare_returns
= NULL
;
1474 if (asan_poisoned_variables
!= NULL
1475 && asan_poisoned_variables
->contains (t
))
1477 asan_poisoned_variables
->remove (t
);
1478 asan_poison_variable (t
, true, &cleanup
);
1481 if (gimplify_ctxp
->live_switch_vars
!= NULL
1482 && gimplify_ctxp
->live_switch_vars
->contains (t
))
1483 gimplify_ctxp
->live_switch_vars
->remove (t
);
1489 gimple_stmt_iterator si
= gsi_start (cleanup
);
1491 stmt
= gimple_build_omp_target (NULL
, GF_OMP_TARGET_KIND_OACC_DECLARE
,
1493 gsi_insert_seq_before_without_update (&si
, stmt
, GSI_NEW_STMT
);
1499 gimple_seq new_body
;
1502 gs
= gimple_build_try (gimple_bind_body (bind_stmt
), cleanup
,
1503 GIMPLE_TRY_FINALLY
);
1506 gimplify_seq_add_stmt (&new_body
, stack_save
);
1507 gimplify_seq_add_stmt (&new_body
, gs
);
1508 gimple_bind_set_body (bind_stmt
, new_body
);
1511 /* keep_stack propagates all the way up to the outermost BIND_EXPR. */
1512 if (!gimplify_ctxp
->keep_stack
)
1513 gimplify_ctxp
->keep_stack
= old_keep_stack
;
1514 gimplify_ctxp
->save_stack
= old_save_stack
;
1516 gimple_pop_bind_expr ();
1518 gimplify_seq_add_stmt (pre_p
, bind_stmt
);
1526 *expr_p
= NULL_TREE
;
1530 /* Maybe add early return predict statement to PRE_P sequence. */
1533 maybe_add_early_return_predict_stmt (gimple_seq
*pre_p
)
1535 /* If we are not in a conditional context, add PREDICT statement. */
1536 if (gimple_conditional_context ())
1538 gimple
*predict
= gimple_build_predict (PRED_TREE_EARLY_RETURN
,
1540 gimplify_seq_add_stmt (pre_p
, predict
);
1544 /* Gimplify a RETURN_EXPR. If the expression to be returned is not a
1545 GIMPLE value, it is assigned to a new temporary and the statement is
1546 re-written to return the temporary.
1548 PRE_P points to the sequence where side effects that must happen before
1549 STMT should be stored. */
1551 static enum gimplify_status
1552 gimplify_return_expr (tree stmt
, gimple_seq
*pre_p
)
1555 tree ret_expr
= TREE_OPERAND (stmt
, 0);
1556 tree result_decl
, result
;
1558 if (ret_expr
== error_mark_node
)
1562 || TREE_CODE (ret_expr
) == RESULT_DECL
)
1564 maybe_add_early_return_predict_stmt (pre_p
);
1565 greturn
*ret
= gimple_build_return (ret_expr
);
1566 gimple_set_no_warning (ret
, TREE_NO_WARNING (stmt
));
1567 gimplify_seq_add_stmt (pre_p
, ret
);
1571 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl
))))
1572 result_decl
= NULL_TREE
;
1575 result_decl
= TREE_OPERAND (ret_expr
, 0);
1577 /* See through a return by reference. */
1578 if (TREE_CODE (result_decl
) == INDIRECT_REF
)
1579 result_decl
= TREE_OPERAND (result_decl
, 0);
1581 gcc_assert ((TREE_CODE (ret_expr
) == MODIFY_EXPR
1582 || TREE_CODE (ret_expr
) == INIT_EXPR
)
1583 && TREE_CODE (result_decl
) == RESULT_DECL
);
1586 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
1587 Recall that aggregate_value_p is FALSE for any aggregate type that is
1588 returned in registers. If we're returning values in registers, then
1589 we don't want to extend the lifetime of the RESULT_DECL, particularly
1590 across another call. In addition, for those aggregates for which
1591 hard_function_value generates a PARALLEL, we'll die during normal
1592 expansion of structure assignments; there's special code in expand_return
1593 to handle this case that does not exist in expand_expr. */
1596 else if (aggregate_value_p (result_decl
, TREE_TYPE (current_function_decl
)))
1598 if (TREE_CODE (DECL_SIZE (result_decl
)) != INTEGER_CST
)
1600 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (result_decl
)))
1601 gimplify_type_sizes (TREE_TYPE (result_decl
), pre_p
);
1602 /* Note that we don't use gimplify_vla_decl because the RESULT_DECL
1603 should be effectively allocated by the caller, i.e. all calls to
1604 this function must be subject to the Return Slot Optimization. */
1605 gimplify_one_sizepos (&DECL_SIZE (result_decl
), pre_p
);
1606 gimplify_one_sizepos (&DECL_SIZE_UNIT (result_decl
), pre_p
);
1608 result
= result_decl
;
1610 else if (gimplify_ctxp
->return_temp
)
1611 result
= gimplify_ctxp
->return_temp
;
1614 result
= create_tmp_reg (TREE_TYPE (result_decl
));
1616 /* ??? With complex control flow (usually involving abnormal edges),
1617 we can wind up warning about an uninitialized value for this. Due
1618 to how this variable is constructed and initialized, this is never
1619 true. Give up and never warn. */
1620 TREE_NO_WARNING (result
) = 1;
1622 gimplify_ctxp
->return_temp
= result
;
1625 /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
1626 Then gimplify the whole thing. */
1627 if (result
!= result_decl
)
1628 TREE_OPERAND (ret_expr
, 0) = result
;
1630 gimplify_and_add (TREE_OPERAND (stmt
, 0), pre_p
);
1632 maybe_add_early_return_predict_stmt (pre_p
);
1633 ret
= gimple_build_return (result
);
1634 gimple_set_no_warning (ret
, TREE_NO_WARNING (stmt
));
1635 gimplify_seq_add_stmt (pre_p
, ret
);
1640 /* Gimplify a variable-length array DECL. */
1643 gimplify_vla_decl (tree decl
, gimple_seq
*seq_p
)
1645 /* This is a variable-sized decl. Simplify its size and mark it
1646 for deferred expansion. */
1647 tree t
, addr
, ptr_type
;
1649 gimplify_one_sizepos (&DECL_SIZE (decl
), seq_p
);
1650 gimplify_one_sizepos (&DECL_SIZE_UNIT (decl
), seq_p
);
1652 /* Don't mess with a DECL_VALUE_EXPR set by the front-end. */
1653 if (DECL_HAS_VALUE_EXPR_P (decl
))
1656 /* All occurrences of this decl in final gimplified code will be
1657 replaced by indirection. Setting DECL_VALUE_EXPR does two
1658 things: First, it lets the rest of the gimplifier know what
1659 replacement to use. Second, it lets the debug info know
1660 where to find the value. */
1661 ptr_type
= build_pointer_type (TREE_TYPE (decl
));
1662 addr
= create_tmp_var (ptr_type
, get_name (decl
));
1663 DECL_IGNORED_P (addr
) = 0;
1664 t
= build_fold_indirect_ref (addr
);
1665 TREE_THIS_NOTRAP (t
) = 1;
1666 SET_DECL_VALUE_EXPR (decl
, t
);
1667 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1669 t
= build_alloca_call_expr (DECL_SIZE_UNIT (decl
), DECL_ALIGN (decl
),
1670 max_int_size_in_bytes (TREE_TYPE (decl
)));
1671 /* The call has been built for a variable-sized object. */
1672 CALL_ALLOCA_FOR_VAR_P (t
) = 1;
1673 t
= fold_convert (ptr_type
, t
);
1674 t
= build2 (MODIFY_EXPR
, TREE_TYPE (addr
), addr
, t
);
1676 gimplify_and_add (t
, seq_p
);
1679 /* A helper function to be called via walk_tree. Mark all labels under *TP
1680 as being forced. To be called for DECL_INITIAL of static variables. */
1683 force_labels_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1687 if (TREE_CODE (*tp
) == LABEL_DECL
)
1689 FORCED_LABEL (*tp
) = 1;
1690 cfun
->has_forced_label_in_static
= 1;
1696 /* Gimplify a DECL_EXPR node *STMT_P by making any necessary allocation
1697 and initialization explicit. */
1699 static enum gimplify_status
1700 gimplify_decl_expr (tree
*stmt_p
, gimple_seq
*seq_p
)
1702 tree stmt
= *stmt_p
;
1703 tree decl
= DECL_EXPR_DECL (stmt
);
1705 *stmt_p
= NULL_TREE
;
1707 if (TREE_TYPE (decl
) == error_mark_node
)
1710 if ((TREE_CODE (decl
) == TYPE_DECL
1712 && !TYPE_SIZES_GIMPLIFIED (TREE_TYPE (decl
)))
1714 gimplify_type_sizes (TREE_TYPE (decl
), seq_p
);
1715 if (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
)
1716 gimplify_type_sizes (TREE_TYPE (TREE_TYPE (decl
)), seq_p
);
1719 /* ??? DECL_ORIGINAL_TYPE is streamed for LTO so it needs to be gimplified
1720 in case its size expressions contain problematic nodes like CALL_EXPR. */
1721 if (TREE_CODE (decl
) == TYPE_DECL
1722 && DECL_ORIGINAL_TYPE (decl
)
1723 && !TYPE_SIZES_GIMPLIFIED (DECL_ORIGINAL_TYPE (decl
)))
1725 gimplify_type_sizes (DECL_ORIGINAL_TYPE (decl
), seq_p
);
1726 if (TREE_CODE (DECL_ORIGINAL_TYPE (decl
)) == REFERENCE_TYPE
)
1727 gimplify_type_sizes (TREE_TYPE (DECL_ORIGINAL_TYPE (decl
)), seq_p
);
1730 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
1732 tree init
= DECL_INITIAL (decl
);
1733 bool is_vla
= false;
1735 if (TREE_CODE (DECL_SIZE_UNIT (decl
)) != INTEGER_CST
1736 || (!TREE_STATIC (decl
)
1737 && flag_stack_check
== GENERIC_STACK_CHECK
1738 && compare_tree_int (DECL_SIZE_UNIT (decl
),
1739 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1741 gimplify_vla_decl (decl
, seq_p
);
1745 if (asan_poisoned_variables
1747 && TREE_ADDRESSABLE (decl
)
1748 && !TREE_STATIC (decl
)
1749 && !DECL_HAS_VALUE_EXPR_P (decl
)
1750 && DECL_ALIGN (decl
) <= MAX_SUPPORTED_STACK_ALIGNMENT
1751 && dbg_cnt (asan_use_after_scope
)
1752 && !gimplify_omp_ctxp
)
1754 asan_poisoned_variables
->add (decl
);
1755 asan_poison_variable (decl
, false, seq_p
);
1756 if (!DECL_ARTIFICIAL (decl
) && gimplify_ctxp
->live_switch_vars
)
1757 gimplify_ctxp
->live_switch_vars
->add (decl
);
1760 /* Some front ends do not explicitly declare all anonymous
1761 artificial variables. We compensate here by declaring the
1762 variables, though it would be better if the front ends would
1763 explicitly declare them. */
1764 if (!DECL_SEEN_IN_BIND_EXPR_P (decl
)
1765 && DECL_ARTIFICIAL (decl
) && DECL_NAME (decl
) == NULL_TREE
)
1766 gimple_add_tmp_var (decl
);
1768 if (init
&& init
!= error_mark_node
)
1770 if (!TREE_STATIC (decl
))
1772 DECL_INITIAL (decl
) = NULL_TREE
;
1773 init
= build2 (INIT_EXPR
, void_type_node
, decl
, init
);
1774 gimplify_and_add (init
, seq_p
);
1778 /* We must still examine initializers for static variables
1779 as they may contain a label address. */
1780 walk_tree (&init
, force_labels_r
, NULL
, NULL
);
1787 /* Gimplify a LOOP_EXPR. Normally this just involves gimplifying the body
1788 and replacing the LOOP_EXPR with goto, but if the loop contains an
1789 EXIT_EXPR, we need to append a label for it to jump to. */
1791 static enum gimplify_status
1792 gimplify_loop_expr (tree
*expr_p
, gimple_seq
*pre_p
)
1794 tree saved_label
= gimplify_ctxp
->exit_label
;
1795 tree start_label
= create_artificial_label (UNKNOWN_LOCATION
);
1797 gimplify_seq_add_stmt (pre_p
, gimple_build_label (start_label
));
1799 gimplify_ctxp
->exit_label
= NULL_TREE
;
1801 gimplify_and_add (LOOP_EXPR_BODY (*expr_p
), pre_p
);
1803 gimplify_seq_add_stmt (pre_p
, gimple_build_goto (start_label
));
1805 if (gimplify_ctxp
->exit_label
)
1806 gimplify_seq_add_stmt (pre_p
,
1807 gimple_build_label (gimplify_ctxp
->exit_label
));
1809 gimplify_ctxp
->exit_label
= saved_label
;
1815 /* Gimplify a statement list onto a sequence. These may be created either
1816 by an enlightened front-end, or by shortcut_cond_expr. */
1818 static enum gimplify_status
1819 gimplify_statement_list (tree
*expr_p
, gimple_seq
*pre_p
)
1821 tree temp
= voidify_wrapper_expr (*expr_p
, NULL
);
1823 tree_stmt_iterator i
= tsi_start (*expr_p
);
1825 while (!tsi_end_p (i
))
1827 gimplify_stmt (tsi_stmt_ptr (i
), pre_p
);
1840 /* Callback for walk_gimple_seq. */
1843 warn_switch_unreachable_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
1844 struct walk_stmt_info
*wi
)
1846 gimple
*stmt
= gsi_stmt (*gsi_p
);
1848 *handled_ops_p
= true;
1849 switch (gimple_code (stmt
))
1852 /* A compiler-generated cleanup or a user-written try block.
1853 If it's empty, don't dive into it--that would result in
1854 worse location info. */
1855 if (gimple_try_eval (stmt
) == NULL
)
1858 return integer_zero_node
;
1863 case GIMPLE_EH_FILTER
:
1864 case GIMPLE_TRANSACTION
:
1865 /* Walk the sub-statements. */
1866 *handled_ops_p
= false;
1870 /* Ignore these. We may generate them before declarations that
1871 are never executed. If there's something to warn about,
1872 there will be non-debug stmts too, and we'll catch those. */
1876 if (gimple_call_internal_p (stmt
, IFN_ASAN_MARK
))
1878 *handled_ops_p
= false;
1883 /* Save the first "real" statement (not a decl/lexical scope/...). */
1885 return integer_zero_node
;
1890 /* Possibly warn about unreachable statements between switch's controlling
1891 expression and the first case. SEQ is the body of a switch expression. */
1894 maybe_warn_switch_unreachable (gimple_seq seq
)
1896 if (!warn_switch_unreachable
1897 /* This warning doesn't play well with Fortran when optimizations
1899 || lang_GNU_Fortran ()
1903 struct walk_stmt_info wi
;
1904 memset (&wi
, 0, sizeof (wi
));
1905 walk_gimple_seq (seq
, warn_switch_unreachable_r
, NULL
, &wi
);
1906 gimple
*stmt
= (gimple
*) wi
.info
;
1908 if (stmt
&& gimple_code (stmt
) != GIMPLE_LABEL
)
1910 if (gimple_code (stmt
) == GIMPLE_GOTO
1911 && TREE_CODE (gimple_goto_dest (stmt
)) == LABEL_DECL
1912 && DECL_ARTIFICIAL (gimple_goto_dest (stmt
)))
1913 /* Don't warn for compiler-generated gotos. These occur
1914 in Duff's devices, for example. */;
1916 warning_at (gimple_location (stmt
), OPT_Wswitch_unreachable
,
1917 "statement will never be executed");
1922 /* A label entry that pairs label and a location. */
1929 /* Find LABEL in vector of label entries VEC. */
1931 static struct label_entry
*
1932 find_label_entry (const auto_vec
<struct label_entry
> *vec
, tree label
)
1935 struct label_entry
*l
;
1937 FOR_EACH_VEC_ELT (*vec
, i
, l
)
1938 if (l
->label
== label
)
1943 /* Return true if LABEL, a LABEL_DECL, represents a case label
1944 in a vector of labels CASES. */
1947 case_label_p (const vec
<tree
> *cases
, tree label
)
1952 FOR_EACH_VEC_ELT (*cases
, i
, l
)
1953 if (CASE_LABEL (l
) == label
)
1958 /* Find the last nondebug statement in a scope STMT. */
1961 last_stmt_in_scope (gimple
*stmt
)
1966 switch (gimple_code (stmt
))
1970 gbind
*bind
= as_a
<gbind
*> (stmt
);
1971 stmt
= gimple_seq_last_nondebug_stmt (gimple_bind_body (bind
));
1972 return last_stmt_in_scope (stmt
);
1977 gtry
*try_stmt
= as_a
<gtry
*> (stmt
);
1978 stmt
= gimple_seq_last_nondebug_stmt (gimple_try_eval (try_stmt
));
1979 gimple
*last_eval
= last_stmt_in_scope (stmt
);
1980 if (gimple_stmt_may_fallthru (last_eval
)
1981 && (last_eval
== NULL
1982 || !gimple_call_internal_p (last_eval
, IFN_FALLTHROUGH
))
1983 && gimple_try_kind (try_stmt
) == GIMPLE_TRY_FINALLY
)
1985 stmt
= gimple_seq_last_nondebug_stmt (gimple_try_cleanup (try_stmt
));
1986 return last_stmt_in_scope (stmt
);
2000 /* Collect interesting labels in LABELS and return the statement preceding
2001 another case label, or a user-defined label. Store a location useful
2002 to give warnings at *PREVLOC (usually the location of the returned
2003 statement or of its surrounding scope). */
2006 collect_fallthrough_labels (gimple_stmt_iterator
*gsi_p
,
2007 auto_vec
<struct label_entry
> *labels
,
2008 location_t
*prevloc
)
2010 gimple
*prev
= NULL
;
2012 *prevloc
= UNKNOWN_LOCATION
;
2015 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_BIND
)
2017 /* Recognize the special GIMPLE_BIND added by gimplify_switch_expr,
2018 which starts on a GIMPLE_SWITCH and ends with a break label.
2019 Handle that as a single statement that can fall through. */
2020 gbind
*bind
= as_a
<gbind
*> (gsi_stmt (*gsi_p
));
2021 gimple
*first
= gimple_seq_first_stmt (gimple_bind_body (bind
));
2022 gimple
*last
= gimple_seq_last_stmt (gimple_bind_body (bind
));
2024 && gimple_code (first
) == GIMPLE_SWITCH
2025 && gimple_code (last
) == GIMPLE_LABEL
)
2027 tree label
= gimple_label_label (as_a
<glabel
*> (last
));
2028 if (SWITCH_BREAK_LABEL_P (label
))
2036 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_BIND
2037 || gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_TRY
)
2039 /* Nested scope. Only look at the last statement of
2040 the innermost scope. */
2041 location_t bind_loc
= gimple_location (gsi_stmt (*gsi_p
));
2042 gimple
*last
= last_stmt_in_scope (gsi_stmt (*gsi_p
));
2046 /* It might be a label without a location. Use the
2047 location of the scope then. */
2048 if (!gimple_has_location (prev
))
2049 *prevloc
= bind_loc
;
2055 /* Ifs are tricky. */
2056 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_COND
)
2058 gcond
*cond_stmt
= as_a
<gcond
*> (gsi_stmt (*gsi_p
));
2059 tree false_lab
= gimple_cond_false_label (cond_stmt
);
2060 location_t if_loc
= gimple_location (cond_stmt
);
2063 if (i > 1) goto <D.2259>; else goto D;
2064 we can't do much with the else-branch. */
2065 if (!DECL_ARTIFICIAL (false_lab
))
2068 /* Go on until the false label, then one step back. */
2069 for (; !gsi_end_p (*gsi_p
); gsi_next (gsi_p
))
2071 gimple
*stmt
= gsi_stmt (*gsi_p
);
2072 if (gimple_code (stmt
) == GIMPLE_LABEL
2073 && gimple_label_label (as_a
<glabel
*> (stmt
)) == false_lab
)
2077 /* Not found? Oops. */
2078 if (gsi_end_p (*gsi_p
))
2081 struct label_entry l
= { false_lab
, if_loc
};
2082 labels
->safe_push (l
);
2084 /* Go to the last statement of the then branch. */
2087 /* if (i != 0) goto <D.1759>; else goto <D.1760>;
2093 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_GOTO
2094 && !gimple_has_location (gsi_stmt (*gsi_p
)))
2096 /* Look at the statement before, it might be
2097 attribute fallthrough, in which case don't warn. */
2099 bool fallthru_before_dest
2100 = gimple_call_internal_p (gsi_stmt (*gsi_p
), IFN_FALLTHROUGH
);
2102 tree goto_dest
= gimple_goto_dest (gsi_stmt (*gsi_p
));
2103 if (!fallthru_before_dest
)
2105 struct label_entry l
= { goto_dest
, if_loc
};
2106 labels
->safe_push (l
);
2109 /* And move back. */
2113 /* Remember the last statement. Skip labels that are of no interest
2115 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_LABEL
)
2117 tree label
= gimple_label_label (as_a
<glabel
*> (gsi_stmt (*gsi_p
)));
2118 if (find_label_entry (labels
, label
))
2119 prev
= gsi_stmt (*gsi_p
);
2121 else if (gimple_call_internal_p (gsi_stmt (*gsi_p
), IFN_ASAN_MARK
))
2123 else if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_PREDICT
)
2125 else if (!is_gimple_debug (gsi_stmt (*gsi_p
)))
2126 prev
= gsi_stmt (*gsi_p
);
2129 while (!gsi_end_p (*gsi_p
)
2130 /* Stop if we find a case or a user-defined label. */
2131 && (gimple_code (gsi_stmt (*gsi_p
)) != GIMPLE_LABEL
2132 || !gimple_has_location (gsi_stmt (*gsi_p
))));
2134 if (prev
&& gimple_has_location (prev
))
2135 *prevloc
= gimple_location (prev
);
2139 /* Return true if the switch fallthough warning should occur. LABEL is
2140 the label statement that we're falling through to. */
2143 should_warn_for_implicit_fallthrough (gimple_stmt_iterator
*gsi_p
, tree label
)
2145 gimple_stmt_iterator gsi
= *gsi_p
;
2147 /* Don't warn if the label is marked with a "falls through" comment. */
2148 if (FALLTHROUGH_LABEL_P (label
))
2151 /* Don't warn for non-case labels followed by a statement:
2156 as these are likely intentional. */
2157 if (!case_label_p (&gimplify_ctxp
->case_labels
, label
))
2160 while (!gsi_end_p (gsi
)
2161 && gimple_code (gsi_stmt (gsi
)) == GIMPLE_LABEL
2162 && (l
= gimple_label_label (as_a
<glabel
*> (gsi_stmt (gsi
))))
2163 && !case_label_p (&gimplify_ctxp
->case_labels
, l
))
2164 gsi_next_nondebug (&gsi
);
2165 if (gsi_end_p (gsi
) || gimple_code (gsi_stmt (gsi
)) != GIMPLE_LABEL
)
2169 /* Don't warn for terminated branches, i.e. when the subsequent case labels
2170 immediately breaks. */
2173 /* Skip all immediately following labels. */
2174 while (!gsi_end_p (gsi
)
2175 && (gimple_code (gsi_stmt (gsi
)) == GIMPLE_LABEL
2176 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_PREDICT
))
2177 gsi_next_nondebug (&gsi
);
2179 /* { ... something; default:; } */
2181 /* { ... something; default: break; } or
2182 { ... something; default: goto L; } */
2183 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_GOTO
2184 /* { ... something; default: return; } */
2185 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_RETURN
)
2191 /* Callback for walk_gimple_seq. */
2194 warn_implicit_fallthrough_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
2195 struct walk_stmt_info
*)
2197 gimple
*stmt
= gsi_stmt (*gsi_p
);
2199 *handled_ops_p
= true;
2200 switch (gimple_code (stmt
))
2205 case GIMPLE_EH_FILTER
:
2206 case GIMPLE_TRANSACTION
:
2207 /* Walk the sub-statements. */
2208 *handled_ops_p
= false;
2211 /* Find a sequence of form:
2218 and possibly warn. */
2221 /* Found a label. Skip all immediately following labels. */
2222 while (!gsi_end_p (*gsi_p
)
2223 && gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_LABEL
)
2224 gsi_next_nondebug (gsi_p
);
2226 /* There might be no more statements. */
2227 if (gsi_end_p (*gsi_p
))
2228 return integer_zero_node
;
2230 /* Vector of labels that fall through. */
2231 auto_vec
<struct label_entry
> labels
;
2233 gimple
*prev
= collect_fallthrough_labels (gsi_p
, &labels
, &prevloc
);
2235 /* There might be no more statements. */
2236 if (gsi_end_p (*gsi_p
))
2237 return integer_zero_node
;
2239 gimple
*next
= gsi_stmt (*gsi_p
);
2241 /* If what follows is a label, then we may have a fallthrough. */
2242 if (gimple_code (next
) == GIMPLE_LABEL
2243 && gimple_has_location (next
)
2244 && (label
= gimple_label_label (as_a
<glabel
*> (next
)))
2247 struct label_entry
*l
;
2248 bool warned_p
= false;
2249 auto_diagnostic_group d
;
2250 if (!should_warn_for_implicit_fallthrough (gsi_p
, label
))
2252 else if (gimple_code (prev
) == GIMPLE_LABEL
2253 && (label
= gimple_label_label (as_a
<glabel
*> (prev
)))
2254 && (l
= find_label_entry (&labels
, label
)))
2255 warned_p
= warning_at (l
->loc
, OPT_Wimplicit_fallthrough_
,
2256 "this statement may fall through");
2257 else if (!gimple_call_internal_p (prev
, IFN_FALLTHROUGH
)
2258 /* Try to be clever and don't warn when the statement
2259 can't actually fall through. */
2260 && gimple_stmt_may_fallthru (prev
)
2261 && prevloc
!= UNKNOWN_LOCATION
)
2262 warned_p
= warning_at (prevloc
,
2263 OPT_Wimplicit_fallthrough_
,
2264 "this statement may fall through");
2266 inform (gimple_location (next
), "here");
2268 /* Mark this label as processed so as to prevent multiple
2269 warnings in nested switches. */
2270 FALLTHROUGH_LABEL_P (label
) = true;
2272 /* So that next warn_implicit_fallthrough_r will start looking for
2273 a new sequence starting with this label. */
2284 /* Warn when a switch case falls through. */
2287 maybe_warn_implicit_fallthrough (gimple_seq seq
)
2289 if (!warn_implicit_fallthrough
)
2292 /* This warning is meant for C/C++/ObjC/ObjC++ only. */
2295 || lang_GNU_OBJC ()))
2298 struct walk_stmt_info wi
;
2299 memset (&wi
, 0, sizeof (wi
));
2300 walk_gimple_seq (seq
, warn_implicit_fallthrough_r
, NULL
, &wi
);
2303 /* Callback for walk_gimple_seq. */
2306 expand_FALLTHROUGH_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
2307 struct walk_stmt_info
*wi
)
2309 gimple
*stmt
= gsi_stmt (*gsi_p
);
2311 *handled_ops_p
= true;
2312 switch (gimple_code (stmt
))
2317 case GIMPLE_EH_FILTER
:
2318 case GIMPLE_TRANSACTION
:
2319 /* Walk the sub-statements. */
2320 *handled_ops_p
= false;
2323 if (gimple_call_internal_p (stmt
, IFN_FALLTHROUGH
))
2325 gsi_remove (gsi_p
, true);
2326 if (gsi_end_p (*gsi_p
))
2328 *static_cast<location_t
*>(wi
->info
) = gimple_location (stmt
);
2329 return integer_zero_node
;
2333 location_t loc
= gimple_location (stmt
);
2335 gimple_stmt_iterator gsi2
= *gsi_p
;
2336 stmt
= gsi_stmt (gsi2
);
2337 if (gimple_code (stmt
) == GIMPLE_GOTO
&& !gimple_has_location (stmt
))
2339 /* Go on until the artificial label. */
2340 tree goto_dest
= gimple_goto_dest (stmt
);
2341 for (; !gsi_end_p (gsi2
); gsi_next (&gsi2
))
2343 if (gimple_code (gsi_stmt (gsi2
)) == GIMPLE_LABEL
2344 && gimple_label_label (as_a
<glabel
*> (gsi_stmt (gsi2
)))
2349 /* Not found? Stop. */
2350 if (gsi_end_p (gsi2
))
2353 /* Look one past it. */
2357 /* We're looking for a case label or default label here. */
2358 while (!gsi_end_p (gsi2
))
2360 stmt
= gsi_stmt (gsi2
);
2361 if (gimple_code (stmt
) == GIMPLE_LABEL
)
2363 tree label
= gimple_label_label (as_a
<glabel
*> (stmt
));
2364 if (gimple_has_location (stmt
) && DECL_ARTIFICIAL (label
))
2370 else if (gimple_call_internal_p (stmt
, IFN_ASAN_MARK
))
2372 else if (!is_gimple_debug (stmt
))
2373 /* Anything else is not expected. */
2378 warning_at (loc
, 0, "attribute %<fallthrough%> not preceding "
2379 "a case label or default label");
2388 /* Expand all FALLTHROUGH () calls in SEQ. */
2391 expand_FALLTHROUGH (gimple_seq
*seq_p
)
2393 struct walk_stmt_info wi
;
2395 memset (&wi
, 0, sizeof (wi
));
2396 wi
.info
= (void *) &loc
;
2397 walk_gimple_seq_mod (seq_p
, expand_FALLTHROUGH_r
, NULL
, &wi
);
2398 if (wi
.callback_result
== integer_zero_node
)
2399 /* We've found [[fallthrough]]; at the end of a switch, which the C++
2400 standard says is ill-formed; see [dcl.attr.fallthrough]. */
2401 warning_at (loc
, 0, "attribute %<fallthrough%> not preceding "
2402 "a case label or default label");
2406 /* Gimplify a SWITCH_EXPR, and collect the vector of labels it can
2409 static enum gimplify_status
2410 gimplify_switch_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2412 tree switch_expr
= *expr_p
;
2413 gimple_seq switch_body_seq
= NULL
;
2414 enum gimplify_status ret
;
2415 tree index_type
= TREE_TYPE (switch_expr
);
2416 if (index_type
== NULL_TREE
)
2417 index_type
= TREE_TYPE (SWITCH_COND (switch_expr
));
2419 ret
= gimplify_expr (&SWITCH_COND (switch_expr
), pre_p
, NULL
, is_gimple_val
,
2421 if (ret
== GS_ERROR
|| ret
== GS_UNHANDLED
)
2424 if (SWITCH_BODY (switch_expr
))
2427 vec
<tree
> saved_labels
;
2428 hash_set
<tree
> *saved_live_switch_vars
= NULL
;
2429 tree default_case
= NULL_TREE
;
2430 gswitch
*switch_stmt
;
2432 /* Save old labels, get new ones from body, then restore the old
2433 labels. Save all the things from the switch body to append after. */
2434 saved_labels
= gimplify_ctxp
->case_labels
;
2435 gimplify_ctxp
->case_labels
.create (8);
2437 /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR. */
2438 saved_live_switch_vars
= gimplify_ctxp
->live_switch_vars
;
2439 tree_code body_type
= TREE_CODE (SWITCH_BODY (switch_expr
));
2440 if (body_type
== BIND_EXPR
|| body_type
== STATEMENT_LIST
)
2441 gimplify_ctxp
->live_switch_vars
= new hash_set
<tree
> (4);
2443 gimplify_ctxp
->live_switch_vars
= NULL
;
2445 bool old_in_switch_expr
= gimplify_ctxp
->in_switch_expr
;
2446 gimplify_ctxp
->in_switch_expr
= true;
2448 gimplify_stmt (&SWITCH_BODY (switch_expr
), &switch_body_seq
);
2450 gimplify_ctxp
->in_switch_expr
= old_in_switch_expr
;
2451 maybe_warn_switch_unreachable (switch_body_seq
);
2452 maybe_warn_implicit_fallthrough (switch_body_seq
);
2453 /* Only do this for the outermost GIMPLE_SWITCH. */
2454 if (!gimplify_ctxp
->in_switch_expr
)
2455 expand_FALLTHROUGH (&switch_body_seq
);
2457 labels
= gimplify_ctxp
->case_labels
;
2458 gimplify_ctxp
->case_labels
= saved_labels
;
2460 if (gimplify_ctxp
->live_switch_vars
)
2462 gcc_assert (gimplify_ctxp
->live_switch_vars
->is_empty ());
2463 delete gimplify_ctxp
->live_switch_vars
;
2465 gimplify_ctxp
->live_switch_vars
= saved_live_switch_vars
;
2467 preprocess_case_label_vec_for_gimple (labels
, index_type
,
2470 bool add_bind
= false;
2473 glabel
*new_default
;
2476 = build_case_label (NULL_TREE
, NULL_TREE
,
2477 create_artificial_label (UNKNOWN_LOCATION
));
2478 if (old_in_switch_expr
)
2480 SWITCH_BREAK_LABEL_P (CASE_LABEL (default_case
)) = 1;
2483 new_default
= gimple_build_label (CASE_LABEL (default_case
));
2484 gimplify_seq_add_stmt (&switch_body_seq
, new_default
);
2486 else if (old_in_switch_expr
)
2488 gimple
*last
= gimple_seq_last_stmt (switch_body_seq
);
2489 if (last
&& gimple_code (last
) == GIMPLE_LABEL
)
2491 tree label
= gimple_label_label (as_a
<glabel
*> (last
));
2492 if (SWITCH_BREAK_LABEL_P (label
))
2497 switch_stmt
= gimple_build_switch (SWITCH_COND (switch_expr
),
2498 default_case
, labels
);
2499 /* For the benefit of -Wimplicit-fallthrough, if switch_body_seq
2500 ends with a GIMPLE_LABEL holding SWITCH_BREAK_LABEL_P LABEL_DECL,
2501 wrap the GIMPLE_SWITCH up to that GIMPLE_LABEL into a GIMPLE_BIND,
2502 so that we can easily find the start and end of the switch
2506 gimple_seq bind_body
= NULL
;
2507 gimplify_seq_add_stmt (&bind_body
, switch_stmt
);
2508 gimple_seq_add_seq (&bind_body
, switch_body_seq
);
2509 gbind
*bind
= gimple_build_bind (NULL_TREE
, bind_body
, NULL_TREE
);
2510 gimple_set_location (bind
, EXPR_LOCATION (switch_expr
));
2511 gimplify_seq_add_stmt (pre_p
, bind
);
2515 gimplify_seq_add_stmt (pre_p
, switch_stmt
);
2516 gimplify_seq_add_seq (pre_p
, switch_body_seq
);
2526 /* Gimplify the LABEL_EXPR pointed to by EXPR_P. */
2528 static enum gimplify_status
2529 gimplify_label_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2531 gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p
))
2532 == current_function_decl
);
2534 tree label
= LABEL_EXPR_LABEL (*expr_p
);
2535 glabel
*label_stmt
= gimple_build_label (label
);
2536 gimple_set_location (label_stmt
, EXPR_LOCATION (*expr_p
));
2537 gimplify_seq_add_stmt (pre_p
, label_stmt
);
2539 if (lookup_attribute ("cold", DECL_ATTRIBUTES (label
)))
2540 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_COLD_LABEL
,
2542 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label
)))
2543 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_HOT_LABEL
,
2549 /* Gimplify the CASE_LABEL_EXPR pointed to by EXPR_P. */
2551 static enum gimplify_status
2552 gimplify_case_label_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2554 struct gimplify_ctx
*ctxp
;
2557 /* Invalid programs can play Duff's Device type games with, for example,
2558 #pragma omp parallel. At least in the C front end, we don't
2559 detect such invalid branches until after gimplification, in the
2560 diagnose_omp_blocks pass. */
2561 for (ctxp
= gimplify_ctxp
; ; ctxp
= ctxp
->prev_context
)
2562 if (ctxp
->case_labels
.exists ())
2565 tree label
= CASE_LABEL (*expr_p
);
2566 label_stmt
= gimple_build_label (label
);
2567 gimple_set_location (label_stmt
, EXPR_LOCATION (*expr_p
));
2568 ctxp
->case_labels
.safe_push (*expr_p
);
2569 gimplify_seq_add_stmt (pre_p
, label_stmt
);
2571 if (lookup_attribute ("cold", DECL_ATTRIBUTES (label
)))
2572 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_COLD_LABEL
,
2574 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label
)))
2575 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_HOT_LABEL
,
2581 /* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
2585 build_and_jump (tree
*label_p
)
2587 if (label_p
== NULL
)
2588 /* If there's nowhere to jump, just fall through. */
2591 if (*label_p
== NULL_TREE
)
2593 tree label
= create_artificial_label (UNKNOWN_LOCATION
);
2597 return build1 (GOTO_EXPR
, void_type_node
, *label_p
);
2600 /* Gimplify an EXIT_EXPR by converting to a GOTO_EXPR inside a COND_EXPR.
2601 This also involves building a label to jump to and communicating it to
2602 gimplify_loop_expr through gimplify_ctxp->exit_label. */
2604 static enum gimplify_status
2605 gimplify_exit_expr (tree
*expr_p
)
2607 tree cond
= TREE_OPERAND (*expr_p
, 0);
2610 expr
= build_and_jump (&gimplify_ctxp
->exit_label
);
2611 expr
= build3 (COND_EXPR
, void_type_node
, cond
, expr
, NULL_TREE
);
2617 /* *EXPR_P is a COMPONENT_REF being used as an rvalue. If its type is
2618 different from its canonical type, wrap the whole thing inside a
2619 NOP_EXPR and force the type of the COMPONENT_REF to be the canonical
2622 The canonical type of a COMPONENT_REF is the type of the field being
2623 referenced--unless the field is a bit-field which can be read directly
2624 in a smaller mode, in which case the canonical type is the
2625 sign-appropriate type corresponding to that mode. */
2628 canonicalize_component_ref (tree
*expr_p
)
2630 tree expr
= *expr_p
;
2633 gcc_assert (TREE_CODE (expr
) == COMPONENT_REF
);
2635 if (INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
2636 type
= TREE_TYPE (get_unwidened (expr
, NULL_TREE
));
2638 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
2640 /* One could argue that all the stuff below is not necessary for
2641 the non-bitfield case and declare it a FE error if type
2642 adjustment would be needed. */
2643 if (TREE_TYPE (expr
) != type
)
2645 #ifdef ENABLE_TYPES_CHECKING
2646 tree old_type
= TREE_TYPE (expr
);
2650 /* We need to preserve qualifiers and propagate them from
2652 type_quals
= TYPE_QUALS (type
)
2653 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr
, 0)));
2654 if (TYPE_QUALS (type
) != type_quals
)
2655 type
= build_qualified_type (TYPE_MAIN_VARIANT (type
), type_quals
);
2657 /* Set the type of the COMPONENT_REF to the underlying type. */
2658 TREE_TYPE (expr
) = type
;
2660 #ifdef ENABLE_TYPES_CHECKING
2661 /* It is now a FE error, if the conversion from the canonical
2662 type to the original expression type is not useless. */
2663 gcc_assert (useless_type_conversion_p (old_type
, type
));
2668 /* If a NOP conversion is changing a pointer to array of foo to a pointer
2669 to foo, embed that change in the ADDR_EXPR by converting
2674 where L is the lower bound. For simplicity, only do this for constant
2676 The constraint is that the type of &array[L] is trivially convertible
2680 canonicalize_addr_expr (tree
*expr_p
)
2682 tree expr
= *expr_p
;
2683 tree addr_expr
= TREE_OPERAND (expr
, 0);
2684 tree datype
, ddatype
, pddatype
;
2686 /* We simplify only conversions from an ADDR_EXPR to a pointer type. */
2687 if (!POINTER_TYPE_P (TREE_TYPE (expr
))
2688 || TREE_CODE (addr_expr
) != ADDR_EXPR
)
2691 /* The addr_expr type should be a pointer to an array. */
2692 datype
= TREE_TYPE (TREE_TYPE (addr_expr
));
2693 if (TREE_CODE (datype
) != ARRAY_TYPE
)
2696 /* The pointer to element type shall be trivially convertible to
2697 the expression pointer type. */
2698 ddatype
= TREE_TYPE (datype
);
2699 pddatype
= build_pointer_type (ddatype
);
2700 if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr
)),
2704 /* The lower bound and element sizes must be constant. */
2705 if (!TYPE_SIZE_UNIT (ddatype
)
2706 || TREE_CODE (TYPE_SIZE_UNIT (ddatype
)) != INTEGER_CST
2707 || !TYPE_DOMAIN (datype
) || !TYPE_MIN_VALUE (TYPE_DOMAIN (datype
))
2708 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype
))) != INTEGER_CST
)
2711 /* All checks succeeded. Build a new node to merge the cast. */
2712 *expr_p
= build4 (ARRAY_REF
, ddatype
, TREE_OPERAND (addr_expr
, 0),
2713 TYPE_MIN_VALUE (TYPE_DOMAIN (datype
)),
2714 NULL_TREE
, NULL_TREE
);
2715 *expr_p
= build1 (ADDR_EXPR
, pddatype
, *expr_p
);
2717 /* We can have stripped a required restrict qualifier above. */
2718 if (!useless_type_conversion_p (TREE_TYPE (expr
), TREE_TYPE (*expr_p
)))
2719 *expr_p
= fold_convert (TREE_TYPE (expr
), *expr_p
);
2722 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions
2723 underneath as appropriate. */
2725 static enum gimplify_status
2726 gimplify_conversion (tree
*expr_p
)
2728 location_t loc
= EXPR_LOCATION (*expr_p
);
2729 gcc_assert (CONVERT_EXPR_P (*expr_p
));
2731 /* Then strip away all but the outermost conversion. */
2732 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p
, 0));
2734 /* And remove the outermost conversion if it's useless. */
2735 if (tree_ssa_useless_type_conversion (*expr_p
))
2736 *expr_p
= TREE_OPERAND (*expr_p
, 0);
2738 /* If we still have a conversion at the toplevel,
2739 then canonicalize some constructs. */
2740 if (CONVERT_EXPR_P (*expr_p
))
2742 tree sub
= TREE_OPERAND (*expr_p
, 0);
2744 /* If a NOP conversion is changing the type of a COMPONENT_REF
2745 expression, then canonicalize its type now in order to expose more
2746 redundant conversions. */
2747 if (TREE_CODE (sub
) == COMPONENT_REF
)
2748 canonicalize_component_ref (&TREE_OPERAND (*expr_p
, 0));
2750 /* If a NOP conversion is changing a pointer to array of foo
2751 to a pointer to foo, embed that change in the ADDR_EXPR. */
2752 else if (TREE_CODE (sub
) == ADDR_EXPR
)
2753 canonicalize_addr_expr (expr_p
);
2756 /* If we have a conversion to a non-register type force the
2757 use of a VIEW_CONVERT_EXPR instead. */
2758 if (CONVERT_EXPR_P (*expr_p
) && !is_gimple_reg_type (TREE_TYPE (*expr_p
)))
2759 *expr_p
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (*expr_p
),
2760 TREE_OPERAND (*expr_p
, 0));
2762 /* Canonicalize CONVERT_EXPR to NOP_EXPR. */
2763 if (TREE_CODE (*expr_p
) == CONVERT_EXPR
)
2764 TREE_SET_CODE (*expr_p
, NOP_EXPR
);
2769 /* Gimplify a VAR_DECL or PARM_DECL. Return GS_OK if we expanded a
2770 DECL_VALUE_EXPR, and it's worth re-examining things. */
2772 static enum gimplify_status
2773 gimplify_var_or_parm_decl (tree
*expr_p
)
2775 tree decl
= *expr_p
;
2777 /* ??? If this is a local variable, and it has not been seen in any
2778 outer BIND_EXPR, then it's probably the result of a duplicate
2779 declaration, for which we've already issued an error. It would
2780 be really nice if the front end wouldn't leak these at all.
2781 Currently the only known culprit is C++ destructors, as seen
2782 in g++.old-deja/g++.jason/binding.C. */
2784 && !DECL_SEEN_IN_BIND_EXPR_P (decl
)
2785 && !TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)
2786 && decl_function_context (decl
) == current_function_decl
)
2788 gcc_assert (seen_error ());
2792 /* When within an OMP context, notice uses of variables. */
2793 if (gimplify_omp_ctxp
&& omp_notice_variable (gimplify_omp_ctxp
, decl
, true))
2796 /* If the decl is an alias for another expression, substitute it now. */
2797 if (DECL_HAS_VALUE_EXPR_P (decl
))
2799 *expr_p
= unshare_expr (DECL_VALUE_EXPR (decl
));
2806 /* Recalculate the value of the TREE_SIDE_EFFECTS flag for T. */
2809 recalculate_side_effects (tree t
)
2811 enum tree_code code
= TREE_CODE (t
);
2812 int len
= TREE_OPERAND_LENGTH (t
);
2815 switch (TREE_CODE_CLASS (code
))
2817 case tcc_expression
:
2823 case PREDECREMENT_EXPR
:
2824 case PREINCREMENT_EXPR
:
2825 case POSTDECREMENT_EXPR
:
2826 case POSTINCREMENT_EXPR
:
2827 /* All of these have side-effects, no matter what their
2836 case tcc_comparison
: /* a comparison expression */
2837 case tcc_unary
: /* a unary arithmetic expression */
2838 case tcc_binary
: /* a binary arithmetic expression */
2839 case tcc_reference
: /* a reference */
2840 case tcc_vl_exp
: /* a function call */
2841 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
2842 for (i
= 0; i
< len
; ++i
)
2844 tree op
= TREE_OPERAND (t
, i
);
2845 if (op
&& TREE_SIDE_EFFECTS (op
))
2846 TREE_SIDE_EFFECTS (t
) = 1;
2851 /* No side-effects. */
2859 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
2863 : min_lval '[' val ']'
2865 | compound_lval '[' val ']'
2866 | compound_lval '.' ID
2868 This is not part of the original SIMPLE definition, which separates
2869 array and member references, but it seems reasonable to handle them
2870 together. Also, this way we don't run into problems with union
2871 aliasing; gcc requires that for accesses through a union to alias, the
2872 union reference must be explicit, which was not always the case when we
2873 were splitting up array and member refs.
2875 PRE_P points to the sequence where side effects that must happen before
2876 *EXPR_P should be stored.
2878 POST_P points to the sequence where side effects that must happen after
2879 *EXPR_P should be stored. */
2881 static enum gimplify_status
2882 gimplify_compound_lval (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
2883 fallback_t fallback
)
2886 enum gimplify_status ret
= GS_ALL_DONE
, tret
;
2888 location_t loc
= EXPR_LOCATION (*expr_p
);
2889 tree expr
= *expr_p
;
2891 /* Create a stack of the subexpressions so later we can walk them in
2892 order from inner to outer. */
2893 auto_vec
<tree
, 10> expr_stack
;
2895 /* We can handle anything that get_inner_reference can deal with. */
2896 for (p
= expr_p
; ; p
= &TREE_OPERAND (*p
, 0))
2899 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */
2900 if (TREE_CODE (*p
) == INDIRECT_REF
)
2901 *p
= fold_indirect_ref_loc (loc
, *p
);
2903 if (handled_component_p (*p
))
2905 /* Expand DECL_VALUE_EXPR now. In some cases that may expose
2906 additional COMPONENT_REFs. */
2907 else if ((VAR_P (*p
) || TREE_CODE (*p
) == PARM_DECL
)
2908 && gimplify_var_or_parm_decl (p
) == GS_OK
)
2913 expr_stack
.safe_push (*p
);
2916 gcc_assert (expr_stack
.length ());
2918 /* Now EXPR_STACK is a stack of pointers to all the refs we've
2919 walked through and P points to the innermost expression.
2921 Java requires that we elaborated nodes in source order. That
2922 means we must gimplify the inner expression followed by each of
2923 the indices, in order. But we can't gimplify the inner
2924 expression until we deal with any variable bounds, sizes, or
2925 positions in order to deal with PLACEHOLDER_EXPRs.
2927 So we do this in three steps. First we deal with the annotations
2928 for any variables in the components, then we gimplify the base,
2929 then we gimplify any indices, from left to right. */
2930 for (i
= expr_stack
.length () - 1; i
>= 0; i
--)
2932 tree t
= expr_stack
[i
];
2934 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
2936 /* Gimplify the low bound and element type size and put them into
2937 the ARRAY_REF. If these values are set, they have already been
2939 if (TREE_OPERAND (t
, 2) == NULL_TREE
)
2941 tree low
= unshare_expr (array_ref_low_bound (t
));
2942 if (!is_gimple_min_invariant (low
))
2944 TREE_OPERAND (t
, 2) = low
;
2945 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
,
2946 post_p
, is_gimple_reg
,
2948 ret
= MIN (ret
, tret
);
2953 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
, post_p
,
2954 is_gimple_reg
, fb_rvalue
);
2955 ret
= MIN (ret
, tret
);
2958 if (TREE_OPERAND (t
, 3) == NULL_TREE
)
2960 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0)));
2961 tree elmt_size
= unshare_expr (array_ref_element_size (t
));
2962 tree factor
= size_int (TYPE_ALIGN_UNIT (elmt_type
));
2964 /* Divide the element size by the alignment of the element
2967 = size_binop_loc (loc
, EXACT_DIV_EXPR
, elmt_size
, factor
);
2969 if (!is_gimple_min_invariant (elmt_size
))
2971 TREE_OPERAND (t
, 3) = elmt_size
;
2972 tret
= gimplify_expr (&TREE_OPERAND (t
, 3), pre_p
,
2973 post_p
, is_gimple_reg
,
2975 ret
= MIN (ret
, tret
);
2980 tret
= gimplify_expr (&TREE_OPERAND (t
, 3), pre_p
, post_p
,
2981 is_gimple_reg
, fb_rvalue
);
2982 ret
= MIN (ret
, tret
);
2985 else if (TREE_CODE (t
) == COMPONENT_REF
)
2987 /* Set the field offset into T and gimplify it. */
2988 if (TREE_OPERAND (t
, 2) == NULL_TREE
)
2990 tree offset
= unshare_expr (component_ref_field_offset (t
));
2991 tree field
= TREE_OPERAND (t
, 1);
2993 = size_int (DECL_OFFSET_ALIGN (field
) / BITS_PER_UNIT
);
2995 /* Divide the offset by its alignment. */
2996 offset
= size_binop_loc (loc
, EXACT_DIV_EXPR
, offset
, factor
);
2998 if (!is_gimple_min_invariant (offset
))
3000 TREE_OPERAND (t
, 2) = offset
;
3001 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
,
3002 post_p
, is_gimple_reg
,
3004 ret
= MIN (ret
, tret
);
3009 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
, post_p
,
3010 is_gimple_reg
, fb_rvalue
);
3011 ret
= MIN (ret
, tret
);
3016 /* Step 2 is to gimplify the base expression. Make sure lvalue is set
3017 so as to match the min_lval predicate. Failure to do so may result
3018 in the creation of large aggregate temporaries. */
3019 tret
= gimplify_expr (p
, pre_p
, post_p
, is_gimple_min_lval
,
3020 fallback
| fb_lvalue
);
3021 ret
= MIN (ret
, tret
);
3023 /* And finally, the indices and operands of ARRAY_REF. During this
3024 loop we also remove any useless conversions. */
3025 for (; expr_stack
.length () > 0; )
3027 tree t
= expr_stack
.pop ();
3029 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
3031 /* Gimplify the dimension. */
3032 if (!is_gimple_min_invariant (TREE_OPERAND (t
, 1)))
3034 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), pre_p
, post_p
,
3035 is_gimple_val
, fb_rvalue
);
3036 ret
= MIN (ret
, tret
);
3040 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t
, 0));
3042 /* The innermost expression P may have originally had
3043 TREE_SIDE_EFFECTS set which would have caused all the outer
3044 expressions in *EXPR_P leading to P to also have had
3045 TREE_SIDE_EFFECTS set. */
3046 recalculate_side_effects (t
);
3049 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */
3050 if ((fallback
& fb_rvalue
) && TREE_CODE (*expr_p
) == COMPONENT_REF
)
3052 canonicalize_component_ref (expr_p
);
3055 expr_stack
.release ();
3057 gcc_assert (*expr_p
== expr
|| ret
!= GS_ALL_DONE
);
3062 /* Gimplify the self modifying expression pointed to by EXPR_P
3065 PRE_P points to the list where side effects that must happen before
3066 *EXPR_P should be stored.
3068 POST_P points to the list where side effects that must happen after
3069 *EXPR_P should be stored.
3071 WANT_VALUE is nonzero iff we want to use the value of this expression
3072 in another expression.
3074 ARITH_TYPE is the type the computation should be performed in. */
3076 enum gimplify_status
3077 gimplify_self_mod_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
3078 bool want_value
, tree arith_type
)
3080 enum tree_code code
;
3081 tree lhs
, lvalue
, rhs
, t1
;
3082 gimple_seq post
= NULL
, *orig_post_p
= post_p
;
3084 enum tree_code arith_code
;
3085 enum gimplify_status ret
;
3086 location_t loc
= EXPR_LOCATION (*expr_p
);
3088 code
= TREE_CODE (*expr_p
);
3090 gcc_assert (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
3091 || code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
);
3093 /* Prefix or postfix? */
3094 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
3095 /* Faster to treat as prefix if result is not used. */
3096 postfix
= want_value
;
3100 /* For postfix, make sure the inner expression's post side effects
3101 are executed after side effects from this expression. */
3105 /* Add or subtract? */
3106 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3107 arith_code
= PLUS_EXPR
;
3109 arith_code
= MINUS_EXPR
;
3111 /* Gimplify the LHS into a GIMPLE lvalue. */
3112 lvalue
= TREE_OPERAND (*expr_p
, 0);
3113 ret
= gimplify_expr (&lvalue
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
3114 if (ret
== GS_ERROR
)
3117 /* Extract the operands to the arithmetic operation. */
3119 rhs
= TREE_OPERAND (*expr_p
, 1);
3121 /* For postfix operator, we evaluate the LHS to an rvalue and then use
3122 that as the result value and in the postqueue operation. */
3125 ret
= gimplify_expr (&lhs
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
3126 if (ret
== GS_ERROR
)
3129 lhs
= get_initialized_tmp_var (lhs
, pre_p
, NULL
);
3132 /* For POINTERs increment, use POINTER_PLUS_EXPR. */
3133 if (POINTER_TYPE_P (TREE_TYPE (lhs
)))
3135 rhs
= convert_to_ptrofftype_loc (loc
, rhs
);
3136 if (arith_code
== MINUS_EXPR
)
3137 rhs
= fold_build1_loc (loc
, NEGATE_EXPR
, TREE_TYPE (rhs
), rhs
);
3138 t1
= fold_build2 (POINTER_PLUS_EXPR
, TREE_TYPE (*expr_p
), lhs
, rhs
);
3141 t1
= fold_convert (TREE_TYPE (*expr_p
),
3142 fold_build2 (arith_code
, arith_type
,
3143 fold_convert (arith_type
, lhs
),
3144 fold_convert (arith_type
, rhs
)));
3148 gimplify_assign (lvalue
, t1
, pre_p
);
3149 gimplify_seq_add_seq (orig_post_p
, post
);
3155 *expr_p
= build2 (MODIFY_EXPR
, TREE_TYPE (lvalue
), lvalue
, t1
);
3160 /* If *EXPR_P has a variable sized type, wrap it in a WITH_SIZE_EXPR. */
3163 maybe_with_size_expr (tree
*expr_p
)
3165 tree expr
= *expr_p
;
3166 tree type
= TREE_TYPE (expr
);
3169 /* If we've already wrapped this or the type is error_mark_node, we can't do
3171 if (TREE_CODE (expr
) == WITH_SIZE_EXPR
3172 || type
== error_mark_node
)
3175 /* If the size isn't known or is a constant, we have nothing to do. */
3176 size
= TYPE_SIZE_UNIT (type
);
3177 if (!size
|| poly_int_tree_p (size
))
3180 /* Otherwise, make a WITH_SIZE_EXPR. */
3181 size
= unshare_expr (size
);
3182 size
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, expr
);
3183 *expr_p
= build2 (WITH_SIZE_EXPR
, type
, expr
, size
);
3186 /* Helper for gimplify_call_expr. Gimplify a single argument *ARG_P
3187 Store any side-effects in PRE_P. CALL_LOCATION is the location of
3188 the CALL_EXPR. If ALLOW_SSA is set the actual parameter may be
3189 gimplified to an SSA name. */
3191 enum gimplify_status
3192 gimplify_arg (tree
*arg_p
, gimple_seq
*pre_p
, location_t call_location
,
3195 bool (*test
) (tree
);
3198 /* In general, we allow lvalues for function arguments to avoid
3199 extra overhead of copying large aggregates out of even larger
3200 aggregates into temporaries only to copy the temporaries to
3201 the argument list. Make optimizers happy by pulling out to
3202 temporaries those types that fit in registers. */
3203 if (is_gimple_reg_type (TREE_TYPE (*arg_p
)))
3204 test
= is_gimple_val
, fb
= fb_rvalue
;
3207 test
= is_gimple_lvalue
, fb
= fb_either
;
3208 /* Also strip a TARGET_EXPR that would force an extra copy. */
3209 if (TREE_CODE (*arg_p
) == TARGET_EXPR
)
3211 tree init
= TARGET_EXPR_INITIAL (*arg_p
);
3213 && !VOID_TYPE_P (TREE_TYPE (init
)))
3218 /* If this is a variable sized type, we must remember the size. */
3219 maybe_with_size_expr (arg_p
);
3221 /* FIXME diagnostics: This will mess up gcc.dg/Warray-bounds.c. */
3222 /* Make sure arguments have the same location as the function call
3224 protected_set_expr_location (*arg_p
, call_location
);
3226 /* There is a sequence point before a function call. Side effects in
3227 the argument list must occur before the actual call. So, when
3228 gimplifying arguments, force gimplify_expr to use an internal
3229 post queue which is then appended to the end of PRE_P. */
3230 return gimplify_expr (arg_p
, pre_p
, NULL
, test
, fb
, allow_ssa
);
3233 /* Don't fold inside offloading or taskreg regions: it can break code by
3234 adding decl references that weren't in the source. We'll do it during
3235 omplower pass instead. */
3238 maybe_fold_stmt (gimple_stmt_iterator
*gsi
)
3240 struct gimplify_omp_ctx
*ctx
;
3241 for (ctx
= gimplify_omp_ctxp
; ctx
; ctx
= ctx
->outer_context
)
3242 if ((ctx
->region_type
& (ORT_TARGET
| ORT_PARALLEL
| ORT_TASK
)) != 0)
3244 else if ((ctx
->region_type
& ORT_HOST_TEAMS
) == ORT_HOST_TEAMS
)
3246 /* Delay folding of builtins until the IL is in consistent state
3247 so the diagnostic machinery can do a better job. */
3248 if (gimple_call_builtin_p (gsi_stmt (*gsi
)))
3250 return fold_stmt (gsi
);
3253 /* Gimplify the CALL_EXPR node *EXPR_P into the GIMPLE sequence PRE_P.
3254 WANT_VALUE is true if the result of the call is desired. */
3256 static enum gimplify_status
3257 gimplify_call_expr (tree
*expr_p
, gimple_seq
*pre_p
, bool want_value
)
3259 tree fndecl
, parms
, p
, fnptrtype
;
3260 enum gimplify_status ret
;
3263 bool builtin_va_start_p
= false;
3264 location_t loc
= EXPR_LOCATION (*expr_p
);
3266 gcc_assert (TREE_CODE (*expr_p
) == CALL_EXPR
);
3268 /* For reliable diagnostics during inlining, it is necessary that
3269 every call_expr be annotated with file and line. */
3270 if (! EXPR_HAS_LOCATION (*expr_p
))
3271 SET_EXPR_LOCATION (*expr_p
, input_location
);
3273 /* Gimplify internal functions created in the FEs. */
3274 if (CALL_EXPR_FN (*expr_p
) == NULL_TREE
)
3279 nargs
= call_expr_nargs (*expr_p
);
3280 enum internal_fn ifn
= CALL_EXPR_IFN (*expr_p
);
3281 auto_vec
<tree
> vargs (nargs
);
3283 for (i
= 0; i
< nargs
; i
++)
3285 gimplify_arg (&CALL_EXPR_ARG (*expr_p
, i
), pre_p
,
3286 EXPR_LOCATION (*expr_p
));
3287 vargs
.quick_push (CALL_EXPR_ARG (*expr_p
, i
));
3290 gcall
*call
= gimple_build_call_internal_vec (ifn
, vargs
);
3291 gimple_call_set_nothrow (call
, TREE_NOTHROW (*expr_p
));
3292 gimplify_seq_add_stmt (pre_p
, call
);
3296 /* This may be a call to a builtin function.
3298 Builtin function calls may be transformed into different
3299 (and more efficient) builtin function calls under certain
3300 circumstances. Unfortunately, gimplification can muck things
3301 up enough that the builtin expanders are not aware that certain
3302 transformations are still valid.
3304 So we attempt transformation/gimplification of the call before
3305 we gimplify the CALL_EXPR. At this time we do not manage to
3306 transform all calls in the same manner as the expanders do, but
3307 we do transform most of them. */
3308 fndecl
= get_callee_fndecl (*expr_p
);
3309 if (fndecl
&& fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
3310 switch (DECL_FUNCTION_CODE (fndecl
))
3312 CASE_BUILT_IN_ALLOCA
:
3313 /* If the call has been built for a variable-sized object, then we
3314 want to restore the stack level when the enclosing BIND_EXPR is
3315 exited to reclaim the allocated space; otherwise, we precisely
3316 need to do the opposite and preserve the latest stack level. */
3317 if (CALL_ALLOCA_FOR_VAR_P (*expr_p
))
3318 gimplify_ctxp
->save_stack
= true;
3320 gimplify_ctxp
->keep_stack
= true;
3323 case BUILT_IN_VA_START
:
3325 builtin_va_start_p
= TRUE
;
3326 if (call_expr_nargs (*expr_p
) < 2)
3328 error ("too few arguments to function %<va_start%>");
3329 *expr_p
= build_empty_stmt (EXPR_LOCATION (*expr_p
));
3333 if (fold_builtin_next_arg (*expr_p
, true))
3335 *expr_p
= build_empty_stmt (EXPR_LOCATION (*expr_p
));
3341 case BUILT_IN_EH_RETURN
:
3342 cfun
->calls_eh_return
= true;
3348 if (fndecl
&& fndecl_built_in_p (fndecl
))
3350 tree new_tree
= fold_call_expr (input_location
, *expr_p
, !want_value
);
3351 if (new_tree
&& new_tree
!= *expr_p
)
3353 /* There was a transformation of this call which computes the
3354 same value, but in a more efficient way. Return and try
3361 /* Remember the original function pointer type. */
3362 fnptrtype
= TREE_TYPE (CALL_EXPR_FN (*expr_p
));
3364 /* There is a sequence point before the call, so any side effects in
3365 the calling expression must occur before the actual call. Force
3366 gimplify_expr to use an internal post queue. */
3367 ret
= gimplify_expr (&CALL_EXPR_FN (*expr_p
), pre_p
, NULL
,
3368 is_gimple_call_addr
, fb_rvalue
);
3370 nargs
= call_expr_nargs (*expr_p
);
3372 /* Get argument types for verification. */
3373 fndecl
= get_callee_fndecl (*expr_p
);
3376 parms
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
3378 parms
= TYPE_ARG_TYPES (TREE_TYPE (fnptrtype
));
3380 if (fndecl
&& DECL_ARGUMENTS (fndecl
))
3381 p
= DECL_ARGUMENTS (fndecl
);
3386 for (i
= 0; i
< nargs
&& p
; i
++, p
= TREE_CHAIN (p
))
3389 /* If the last argument is __builtin_va_arg_pack () and it is not
3390 passed as a named argument, decrease the number of CALL_EXPR
3391 arguments and set instead the CALL_EXPR_VA_ARG_PACK flag. */
3394 && TREE_CODE (CALL_EXPR_ARG (*expr_p
, nargs
- 1)) == CALL_EXPR
)
3396 tree last_arg
= CALL_EXPR_ARG (*expr_p
, nargs
- 1);
3397 tree last_arg_fndecl
= get_callee_fndecl (last_arg
);
3400 && fndecl_built_in_p (last_arg_fndecl
, BUILT_IN_VA_ARG_PACK
))
3402 tree call
= *expr_p
;
3405 *expr_p
= build_call_array_loc (loc
, TREE_TYPE (call
),
3406 CALL_EXPR_FN (call
),
3407 nargs
, CALL_EXPR_ARGP (call
));
3409 /* Copy all CALL_EXPR flags, location and block, except
3410 CALL_EXPR_VA_ARG_PACK flag. */
3411 CALL_EXPR_STATIC_CHAIN (*expr_p
) = CALL_EXPR_STATIC_CHAIN (call
);
3412 CALL_EXPR_TAILCALL (*expr_p
) = CALL_EXPR_TAILCALL (call
);
3413 CALL_EXPR_RETURN_SLOT_OPT (*expr_p
)
3414 = CALL_EXPR_RETURN_SLOT_OPT (call
);
3415 CALL_FROM_THUNK_P (*expr_p
) = CALL_FROM_THUNK_P (call
);
3416 SET_EXPR_LOCATION (*expr_p
, EXPR_LOCATION (call
));
3418 /* Set CALL_EXPR_VA_ARG_PACK. */
3419 CALL_EXPR_VA_ARG_PACK (*expr_p
) = 1;
3423 /* If the call returns twice then after building the CFG the call
3424 argument computations will no longer dominate the call because
3425 we add an abnormal incoming edge to the call. So do not use SSA
3427 bool returns_twice
= call_expr_flags (*expr_p
) & ECF_RETURNS_TWICE
;
3429 /* Gimplify the function arguments. */
3432 for (i
= (PUSH_ARGS_REVERSED
? nargs
- 1 : 0);
3433 PUSH_ARGS_REVERSED
? i
>= 0 : i
< nargs
;
3434 PUSH_ARGS_REVERSED
? i
-- : i
++)
3436 enum gimplify_status t
;
3438 /* Avoid gimplifying the second argument to va_start, which needs to
3439 be the plain PARM_DECL. */
3440 if ((i
!= 1) || !builtin_va_start_p
)
3442 t
= gimplify_arg (&CALL_EXPR_ARG (*expr_p
, i
), pre_p
,
3443 EXPR_LOCATION (*expr_p
), ! returns_twice
);
3451 /* Gimplify the static chain. */
3452 if (CALL_EXPR_STATIC_CHAIN (*expr_p
))
3454 if (fndecl
&& !DECL_STATIC_CHAIN (fndecl
))
3455 CALL_EXPR_STATIC_CHAIN (*expr_p
) = NULL
;
3458 enum gimplify_status t
;
3459 t
= gimplify_arg (&CALL_EXPR_STATIC_CHAIN (*expr_p
), pre_p
,
3460 EXPR_LOCATION (*expr_p
), ! returns_twice
);
3466 /* Verify the function result. */
3467 if (want_value
&& fndecl
3468 && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fnptrtype
))))
3470 error_at (loc
, "using result of function returning %<void%>");
3474 /* Try this again in case gimplification exposed something. */
3475 if (ret
!= GS_ERROR
)
3477 tree new_tree
= fold_call_expr (input_location
, *expr_p
, !want_value
);
3479 if (new_tree
&& new_tree
!= *expr_p
)
3481 /* There was a transformation of this call which computes the
3482 same value, but in a more efficient way. Return and try
3490 *expr_p
= error_mark_node
;
3494 /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
3495 decl. This allows us to eliminate redundant or useless
3496 calls to "const" functions. */
3497 if (TREE_CODE (*expr_p
) == CALL_EXPR
)
3499 int flags
= call_expr_flags (*expr_p
);
3500 if (flags
& (ECF_CONST
| ECF_PURE
)
3501 /* An infinite loop is considered a side effect. */
3502 && !(flags
& (ECF_LOOPING_CONST_OR_PURE
)))
3503 TREE_SIDE_EFFECTS (*expr_p
) = 0;
3506 /* If the value is not needed by the caller, emit a new GIMPLE_CALL
3507 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified
3508 form and delegate the creation of a GIMPLE_CALL to
3509 gimplify_modify_expr. This is always possible because when
3510 WANT_VALUE is true, the caller wants the result of this call into
3511 a temporary, which means that we will emit an INIT_EXPR in
3512 internal_get_tmp_var which will then be handled by
3513 gimplify_modify_expr. */
3516 /* The CALL_EXPR in *EXPR_P is already in GIMPLE form, so all we
3517 have to do is replicate it as a GIMPLE_CALL tuple. */
3518 gimple_stmt_iterator gsi
;
3519 call
= gimple_build_call_from_tree (*expr_p
, fnptrtype
);
3520 notice_special_calls (call
);
3521 gimplify_seq_add_stmt (pre_p
, call
);
3522 gsi
= gsi_last (*pre_p
);
3523 maybe_fold_stmt (&gsi
);
3524 *expr_p
= NULL_TREE
;
3527 /* Remember the original function type. */
3528 CALL_EXPR_FN (*expr_p
) = build1 (NOP_EXPR
, fnptrtype
,
3529 CALL_EXPR_FN (*expr_p
));
3534 /* Handle shortcut semantics in the predicate operand of a COND_EXPR by
3535 rewriting it into multiple COND_EXPRs, and possibly GOTO_EXPRs.
3537 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
3538 condition is true or false, respectively. If null, we should generate
3539 our own to skip over the evaluation of this specific expression.
3541 LOCUS is the source location of the COND_EXPR.
3543 This function is the tree equivalent of do_jump.
3545 shortcut_cond_r should only be called by shortcut_cond_expr. */
3548 shortcut_cond_r (tree pred
, tree
*true_label_p
, tree
*false_label_p
,
3551 tree local_label
= NULL_TREE
;
3552 tree t
, expr
= NULL
;
3554 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
3555 retain the shortcut semantics. Just insert the gotos here;
3556 shortcut_cond_expr will append the real blocks later. */
3557 if (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
3559 location_t new_locus
;
3561 /* Turn if (a && b) into
3563 if (a); else goto no;
3564 if (b) goto yes; else goto no;
3567 if (false_label_p
== NULL
)
3568 false_label_p
= &local_label
;
3570 /* Keep the original source location on the first 'if'. */
3571 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), NULL
, false_label_p
, locus
);
3572 append_to_statement_list (t
, &expr
);
3574 /* Set the source location of the && on the second 'if'. */
3575 new_locus
= rexpr_location (pred
, locus
);
3576 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
, false_label_p
,
3578 append_to_statement_list (t
, &expr
);
3580 else if (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
3582 location_t new_locus
;
3584 /* Turn if (a || b) into
3587 if (b) goto yes; else goto no;
3590 if (true_label_p
== NULL
)
3591 true_label_p
= &local_label
;
3593 /* Keep the original source location on the first 'if'. */
3594 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), true_label_p
, NULL
, locus
);
3595 append_to_statement_list (t
, &expr
);
3597 /* Set the source location of the || on the second 'if'. */
3598 new_locus
= rexpr_location (pred
, locus
);
3599 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
, false_label_p
,
3601 append_to_statement_list (t
, &expr
);
3603 else if (TREE_CODE (pred
) == COND_EXPR
3604 && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred
, 1)))
3605 && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred
, 2))))
3607 location_t new_locus
;
3609 /* As long as we're messing with gotos, turn if (a ? b : c) into
3611 if (b) goto yes; else goto no;
3613 if (c) goto yes; else goto no;
3615 Don't do this if one of the arms has void type, which can happen
3616 in C++ when the arm is throw. */
3618 /* Keep the original source location on the first 'if'. Set the source
3619 location of the ? on the second 'if'. */
3620 new_locus
= rexpr_location (pred
, locus
);
3621 expr
= build3 (COND_EXPR
, void_type_node
, TREE_OPERAND (pred
, 0),
3622 shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
,
3623 false_label_p
, locus
),
3624 shortcut_cond_r (TREE_OPERAND (pred
, 2), true_label_p
,
3625 false_label_p
, new_locus
));
3629 expr
= build3 (COND_EXPR
, void_type_node
, pred
,
3630 build_and_jump (true_label_p
),
3631 build_and_jump (false_label_p
));
3632 SET_EXPR_LOCATION (expr
, locus
);
3637 t
= build1 (LABEL_EXPR
, void_type_node
, local_label
);
3638 append_to_statement_list (t
, &expr
);
3644 /* If EXPR is a GOTO_EXPR, return it. If it is a STATEMENT_LIST, skip
3645 any of its leading DEBUG_BEGIN_STMTS and recurse on the subsequent
3646 statement, if it is the last one. Otherwise, return NULL. */
3649 find_goto (tree expr
)
3654 if (TREE_CODE (expr
) == GOTO_EXPR
)
3657 if (TREE_CODE (expr
) != STATEMENT_LIST
)
3660 tree_stmt_iterator i
= tsi_start (expr
);
3662 while (!tsi_end_p (i
) && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
3665 if (!tsi_one_before_end_p (i
))
3668 return find_goto (tsi_stmt (i
));
3671 /* Same as find_goto, except that it returns NULL if the destination
3672 is not a LABEL_DECL. */
3675 find_goto_label (tree expr
)
3677 tree dest
= find_goto (expr
);
3678 if (dest
&& TREE_CODE (GOTO_DESTINATION (dest
)) == LABEL_DECL
)
3683 /* Given a conditional expression EXPR with short-circuit boolean
3684 predicates using TRUTH_ANDIF_EXPR or TRUTH_ORIF_EXPR, break the
3685 predicate apart into the equivalent sequence of conditionals. */
3688 shortcut_cond_expr (tree expr
)
3690 tree pred
= TREE_OPERAND (expr
, 0);
3691 tree then_
= TREE_OPERAND (expr
, 1);
3692 tree else_
= TREE_OPERAND (expr
, 2);
3693 tree true_label
, false_label
, end_label
, t
;
3695 tree
*false_label_p
;
3696 bool emit_end
, emit_false
, jump_over_else
;
3697 bool then_se
= then_
&& TREE_SIDE_EFFECTS (then_
);
3698 bool else_se
= else_
&& TREE_SIDE_EFFECTS (else_
);
3700 /* First do simple transformations. */
3703 /* If there is no 'else', turn
3706 if (a) if (b) then c. */
3707 while (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
3709 /* Keep the original source location on the first 'if'. */
3710 location_t locus
= EXPR_LOC_OR_LOC (expr
, input_location
);
3711 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
3712 /* Set the source location of the && on the second 'if'. */
3713 if (rexpr_has_location (pred
))
3714 SET_EXPR_LOCATION (expr
, rexpr_location (pred
));
3715 then_
= shortcut_cond_expr (expr
);
3716 then_se
= then_
&& TREE_SIDE_EFFECTS (then_
);
3717 pred
= TREE_OPERAND (pred
, 0);
3718 expr
= build3 (COND_EXPR
, void_type_node
, pred
, then_
, NULL_TREE
);
3719 SET_EXPR_LOCATION (expr
, locus
);
3725 /* If there is no 'then', turn
3728 if (a); else if (b); else d. */
3729 while (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
3731 /* Keep the original source location on the first 'if'. */
3732 location_t locus
= EXPR_LOC_OR_LOC (expr
, input_location
);
3733 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
3734 /* Set the source location of the || on the second 'if'. */
3735 if (rexpr_has_location (pred
))
3736 SET_EXPR_LOCATION (expr
, rexpr_location (pred
));
3737 else_
= shortcut_cond_expr (expr
);
3738 else_se
= else_
&& TREE_SIDE_EFFECTS (else_
);
3739 pred
= TREE_OPERAND (pred
, 0);
3740 expr
= build3 (COND_EXPR
, void_type_node
, pred
, NULL_TREE
, else_
);
3741 SET_EXPR_LOCATION (expr
, locus
);
3745 /* If we're done, great. */
3746 if (TREE_CODE (pred
) != TRUTH_ANDIF_EXPR
3747 && TREE_CODE (pred
) != TRUTH_ORIF_EXPR
)
3750 /* Otherwise we need to mess with gotos. Change
3753 if (a); else goto no;
3756 and recursively gimplify the condition. */
3758 true_label
= false_label
= end_label
= NULL_TREE
;
3760 /* If our arms just jump somewhere, hijack those labels so we don't
3761 generate jumps to jumps. */
3763 if (tree then_goto
= find_goto_label (then_
))
3765 true_label
= GOTO_DESTINATION (then_goto
);
3770 if (tree else_goto
= find_goto_label (else_
))
3772 false_label
= GOTO_DESTINATION (else_goto
);
3777 /* If we aren't hijacking a label for the 'then' branch, it falls through. */
3779 true_label_p
= &true_label
;
3781 true_label_p
= NULL
;
3783 /* The 'else' branch also needs a label if it contains interesting code. */
3784 if (false_label
|| else_se
)
3785 false_label_p
= &false_label
;
3787 false_label_p
= NULL
;
3789 /* If there was nothing else in our arms, just forward the label(s). */
3790 if (!then_se
&& !else_se
)
3791 return shortcut_cond_r (pred
, true_label_p
, false_label_p
,
3792 EXPR_LOC_OR_LOC (expr
, input_location
));
3794 /* If our last subexpression already has a terminal label, reuse it. */
3796 t
= expr_last (else_
);
3798 t
= expr_last (then_
);
3801 if (t
&& TREE_CODE (t
) == LABEL_EXPR
)
3802 end_label
= LABEL_EXPR_LABEL (t
);
3804 /* If we don't care about jumping to the 'else' branch, jump to the end
3805 if the condition is false. */
3807 false_label_p
= &end_label
;
3809 /* We only want to emit these labels if we aren't hijacking them. */
3810 emit_end
= (end_label
== NULL_TREE
);
3811 emit_false
= (false_label
== NULL_TREE
);
3813 /* We only emit the jump over the else clause if we have to--if the
3814 then clause may fall through. Otherwise we can wind up with a
3815 useless jump and a useless label at the end of gimplified code,
3816 which will cause us to think that this conditional as a whole
3817 falls through even if it doesn't. If we then inline a function
3818 which ends with such a condition, that can cause us to issue an
3819 inappropriate warning about control reaching the end of a
3820 non-void function. */
3821 jump_over_else
= block_may_fallthru (then_
);
3823 pred
= shortcut_cond_r (pred
, true_label_p
, false_label_p
,
3824 EXPR_LOC_OR_LOC (expr
, input_location
));
3827 append_to_statement_list (pred
, &expr
);
3829 append_to_statement_list (then_
, &expr
);
3834 tree last
= expr_last (expr
);
3835 t
= build_and_jump (&end_label
);
3836 if (rexpr_has_location (last
))
3837 SET_EXPR_LOCATION (t
, rexpr_location (last
));
3838 append_to_statement_list (t
, &expr
);
3842 t
= build1 (LABEL_EXPR
, void_type_node
, false_label
);
3843 append_to_statement_list (t
, &expr
);
3845 append_to_statement_list (else_
, &expr
);
3847 if (emit_end
&& end_label
)
3849 t
= build1 (LABEL_EXPR
, void_type_node
, end_label
);
3850 append_to_statement_list (t
, &expr
);
3856 /* EXPR is used in a boolean context; make sure it has BOOLEAN_TYPE. */
3859 gimple_boolify (tree expr
)
3861 tree type
= TREE_TYPE (expr
);
3862 location_t loc
= EXPR_LOCATION (expr
);
3864 if (TREE_CODE (expr
) == NE_EXPR
3865 && TREE_CODE (TREE_OPERAND (expr
, 0)) == CALL_EXPR
3866 && integer_zerop (TREE_OPERAND (expr
, 1)))
3868 tree call
= TREE_OPERAND (expr
, 0);
3869 tree fn
= get_callee_fndecl (call
);
3871 /* For __builtin_expect ((long) (x), y) recurse into x as well
3872 if x is truth_value_p. */
3874 && fndecl_built_in_p (fn
, BUILT_IN_EXPECT
)
3875 && call_expr_nargs (call
) == 2)
3877 tree arg
= CALL_EXPR_ARG (call
, 0);
3880 if (TREE_CODE (arg
) == NOP_EXPR
3881 && TREE_TYPE (arg
) == TREE_TYPE (call
))
3882 arg
= TREE_OPERAND (arg
, 0);
3883 if (truth_value_p (TREE_CODE (arg
)))
3885 arg
= gimple_boolify (arg
);
3886 CALL_EXPR_ARG (call
, 0)
3887 = fold_convert_loc (loc
, TREE_TYPE (call
), arg
);
3893 switch (TREE_CODE (expr
))
3895 case TRUTH_AND_EXPR
:
3897 case TRUTH_XOR_EXPR
:
3898 case TRUTH_ANDIF_EXPR
:
3899 case TRUTH_ORIF_EXPR
:
3900 /* Also boolify the arguments of truth exprs. */
3901 TREE_OPERAND (expr
, 1) = gimple_boolify (TREE_OPERAND (expr
, 1));
3904 case TRUTH_NOT_EXPR
:
3905 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
3907 /* These expressions always produce boolean results. */
3908 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3909 TREE_TYPE (expr
) = boolean_type_node
;
3913 switch ((enum annot_expr_kind
) TREE_INT_CST_LOW (TREE_OPERAND (expr
, 1)))
3915 case annot_expr_ivdep_kind
:
3916 case annot_expr_unroll_kind
:
3917 case annot_expr_no_vector_kind
:
3918 case annot_expr_vector_kind
:
3919 case annot_expr_parallel_kind
:
3920 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
3921 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3922 TREE_TYPE (expr
) = boolean_type_node
;
3929 if (COMPARISON_CLASS_P (expr
))
3931 /* There expressions always prduce boolean results. */
3932 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3933 TREE_TYPE (expr
) = boolean_type_node
;
3936 /* Other expressions that get here must have boolean values, but
3937 might need to be converted to the appropriate mode. */
3938 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
3940 return fold_convert_loc (loc
, boolean_type_node
, expr
);
3944 /* Given a conditional expression *EXPR_P without side effects, gimplify
3945 its operands. New statements are inserted to PRE_P. */
3947 static enum gimplify_status
3948 gimplify_pure_cond_expr (tree
*expr_p
, gimple_seq
*pre_p
)
3950 tree expr
= *expr_p
, cond
;
3951 enum gimplify_status ret
, tret
;
3952 enum tree_code code
;
3954 cond
= gimple_boolify (COND_EXPR_COND (expr
));
3956 /* We need to handle && and || specially, as their gimplification
3957 creates pure cond_expr, thus leading to an infinite cycle otherwise. */
3958 code
= TREE_CODE (cond
);
3959 if (code
== TRUTH_ANDIF_EXPR
)
3960 TREE_SET_CODE (cond
, TRUTH_AND_EXPR
);
3961 else if (code
== TRUTH_ORIF_EXPR
)
3962 TREE_SET_CODE (cond
, TRUTH_OR_EXPR
);
3963 ret
= gimplify_expr (&cond
, pre_p
, NULL
, is_gimple_condexpr
, fb_rvalue
);
3964 COND_EXPR_COND (*expr_p
) = cond
;
3966 tret
= gimplify_expr (&COND_EXPR_THEN (expr
), pre_p
, NULL
,
3967 is_gimple_val
, fb_rvalue
);
3968 ret
= MIN (ret
, tret
);
3969 tret
= gimplify_expr (&COND_EXPR_ELSE (expr
), pre_p
, NULL
,
3970 is_gimple_val
, fb_rvalue
);
3972 return MIN (ret
, tret
);
3975 /* Return true if evaluating EXPR could trap.
3976 EXPR is GENERIC, while tree_could_trap_p can be called
3980 generic_expr_could_trap_p (tree expr
)
3984 if (!expr
|| is_gimple_val (expr
))
3987 if (!EXPR_P (expr
) || tree_could_trap_p (expr
))
3990 n
= TREE_OPERAND_LENGTH (expr
);
3991 for (i
= 0; i
< n
; i
++)
3992 if (generic_expr_could_trap_p (TREE_OPERAND (expr
, i
)))
3998 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;'
4007 The second form is used when *EXPR_P is of type void.
4009 PRE_P points to the list where side effects that must happen before
4010 *EXPR_P should be stored. */
4012 static enum gimplify_status
4013 gimplify_cond_expr (tree
*expr_p
, gimple_seq
*pre_p
, fallback_t fallback
)
4015 tree expr
= *expr_p
;
4016 tree type
= TREE_TYPE (expr
);
4017 location_t loc
= EXPR_LOCATION (expr
);
4018 tree tmp
, arm1
, arm2
;
4019 enum gimplify_status ret
;
4020 tree label_true
, label_false
, label_cont
;
4021 bool have_then_clause_p
, have_else_clause_p
;
4023 enum tree_code pred_code
;
4024 gimple_seq seq
= NULL
;
4026 /* If this COND_EXPR has a value, copy the values into a temporary within
4028 if (!VOID_TYPE_P (type
))
4030 tree then_
= TREE_OPERAND (expr
, 1), else_
= TREE_OPERAND (expr
, 2);
4033 /* If either an rvalue is ok or we do not require an lvalue, create the
4034 temporary. But we cannot do that if the type is addressable. */
4035 if (((fallback
& fb_rvalue
) || !(fallback
& fb_lvalue
))
4036 && !TREE_ADDRESSABLE (type
))
4038 if (gimplify_ctxp
->allow_rhs_cond_expr
4039 /* If either branch has side effects or could trap, it can't be
4040 evaluated unconditionally. */
4041 && !TREE_SIDE_EFFECTS (then_
)
4042 && !generic_expr_could_trap_p (then_
)
4043 && !TREE_SIDE_EFFECTS (else_
)
4044 && !generic_expr_could_trap_p (else_
))
4045 return gimplify_pure_cond_expr (expr_p
, pre_p
);
4047 tmp
= create_tmp_var (type
, "iftmp");
4051 /* Otherwise, only create and copy references to the values. */
4054 type
= build_pointer_type (type
);
4056 if (!VOID_TYPE_P (TREE_TYPE (then_
)))
4057 then_
= build_fold_addr_expr_loc (loc
, then_
);
4059 if (!VOID_TYPE_P (TREE_TYPE (else_
)))
4060 else_
= build_fold_addr_expr_loc (loc
, else_
);
4063 = build3 (COND_EXPR
, type
, TREE_OPERAND (expr
, 0), then_
, else_
);
4065 tmp
= create_tmp_var (type
, "iftmp");
4066 result
= build_simple_mem_ref_loc (loc
, tmp
);
4069 /* Build the new then clause, `tmp = then_;'. But don't build the
4070 assignment if the value is void; in C++ it can be if it's a throw. */
4071 if (!VOID_TYPE_P (TREE_TYPE (then_
)))
4072 TREE_OPERAND (expr
, 1) = build2 (INIT_EXPR
, type
, tmp
, then_
);
4074 /* Similarly, build the new else clause, `tmp = else_;'. */
4075 if (!VOID_TYPE_P (TREE_TYPE (else_
)))
4076 TREE_OPERAND (expr
, 2) = build2 (INIT_EXPR
, type
, tmp
, else_
);
4078 TREE_TYPE (expr
) = void_type_node
;
4079 recalculate_side_effects (expr
);
4081 /* Move the COND_EXPR to the prequeue. */
4082 gimplify_stmt (&expr
, pre_p
);
4088 /* Remove any COMPOUND_EXPR so the following cases will be caught. */
4089 STRIP_TYPE_NOPS (TREE_OPERAND (expr
, 0));
4090 if (TREE_CODE (TREE_OPERAND (expr
, 0)) == COMPOUND_EXPR
)
4091 gimplify_compound_expr (&TREE_OPERAND (expr
, 0), pre_p
, true);
4093 /* Make sure the condition has BOOLEAN_TYPE. */
4094 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
4096 /* Break apart && and || conditions. */
4097 if (TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ANDIF_EXPR
4098 || TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ORIF_EXPR
)
4100 expr
= shortcut_cond_expr (expr
);
4102 if (expr
!= *expr_p
)
4106 /* We can't rely on gimplify_expr to re-gimplify the expanded
4107 form properly, as cleanups might cause the target labels to be
4108 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to
4109 set up a conditional context. */
4110 gimple_push_condition ();
4111 gimplify_stmt (expr_p
, &seq
);
4112 gimple_pop_condition (pre_p
);
4113 gimple_seq_add_seq (pre_p
, seq
);
4119 /* Now do the normal gimplification. */
4121 /* Gimplify condition. */
4122 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, NULL
, is_gimple_condexpr
,
4124 if (ret
== GS_ERROR
)
4126 gcc_assert (TREE_OPERAND (expr
, 0) != NULL_TREE
);
4128 gimple_push_condition ();
4130 have_then_clause_p
= have_else_clause_p
= false;
4131 label_true
= find_goto_label (TREE_OPERAND (expr
, 1));
4133 && DECL_CONTEXT (GOTO_DESTINATION (label_true
)) == current_function_decl
4134 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
4135 have different locations, otherwise we end up with incorrect
4136 location information on the branches. */
4138 || !EXPR_HAS_LOCATION (expr
)
4139 || !rexpr_has_location (label_true
)
4140 || EXPR_LOCATION (expr
) == rexpr_location (label_true
)))
4142 have_then_clause_p
= true;
4143 label_true
= GOTO_DESTINATION (label_true
);
4146 label_true
= create_artificial_label (UNKNOWN_LOCATION
);
4147 label_false
= find_goto_label (TREE_OPERAND (expr
, 2));
4149 && DECL_CONTEXT (GOTO_DESTINATION (label_false
)) == current_function_decl
4150 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
4151 have different locations, otherwise we end up with incorrect
4152 location information on the branches. */
4154 || !EXPR_HAS_LOCATION (expr
)
4155 || !rexpr_has_location (label_false
)
4156 || EXPR_LOCATION (expr
) == rexpr_location (label_false
)))
4158 have_else_clause_p
= true;
4159 label_false
= GOTO_DESTINATION (label_false
);
4162 label_false
= create_artificial_label (UNKNOWN_LOCATION
);
4164 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr
), &pred_code
, &arm1
,
4166 cond_stmt
= gimple_build_cond (pred_code
, arm1
, arm2
, label_true
,
4168 gimple_set_no_warning (cond_stmt
, TREE_NO_WARNING (COND_EXPR_COND (expr
)));
4169 gimplify_seq_add_stmt (&seq
, cond_stmt
);
4170 gimple_stmt_iterator gsi
= gsi_last (seq
);
4171 maybe_fold_stmt (&gsi
);
4173 label_cont
= NULL_TREE
;
4174 if (!have_then_clause_p
)
4176 /* For if (...) {} else { code; } put label_true after
4178 if (TREE_OPERAND (expr
, 1) == NULL_TREE
4179 && !have_else_clause_p
4180 && TREE_OPERAND (expr
, 2) != NULL_TREE
)
4181 label_cont
= label_true
;
4184 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_true
));
4185 have_then_clause_p
= gimplify_stmt (&TREE_OPERAND (expr
, 1), &seq
);
4186 /* For if (...) { code; } else {} or
4187 if (...) { code; } else goto label; or
4188 if (...) { code; return; } else { ... }
4189 label_cont isn't needed. */
4190 if (!have_else_clause_p
4191 && TREE_OPERAND (expr
, 2) != NULL_TREE
4192 && gimple_seq_may_fallthru (seq
))
4195 label_cont
= create_artificial_label (UNKNOWN_LOCATION
);
4197 g
= gimple_build_goto (label_cont
);
4199 /* GIMPLE_COND's are very low level; they have embedded
4200 gotos. This particular embedded goto should not be marked
4201 with the location of the original COND_EXPR, as it would
4202 correspond to the COND_EXPR's condition, not the ELSE or the
4203 THEN arms. To avoid marking it with the wrong location, flag
4204 it as "no location". */
4205 gimple_set_do_not_emit_location (g
);
4207 gimplify_seq_add_stmt (&seq
, g
);
4211 if (!have_else_clause_p
)
4213 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_false
));
4214 have_else_clause_p
= gimplify_stmt (&TREE_OPERAND (expr
, 2), &seq
);
4217 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_cont
));
4219 gimple_pop_condition (pre_p
);
4220 gimple_seq_add_seq (pre_p
, seq
);
4222 if (ret
== GS_ERROR
)
4224 else if (have_then_clause_p
|| have_else_clause_p
)
4228 /* Both arms are empty; replace the COND_EXPR with its predicate. */
4229 expr
= TREE_OPERAND (expr
, 0);
4230 gimplify_stmt (&expr
, pre_p
);
4237 /* Prepare the node pointed to by EXPR_P, an is_gimple_addressable expression,
4238 to be marked addressable.
4240 We cannot rely on such an expression being directly markable if a temporary
4241 has been created by the gimplification. In this case, we create another
4242 temporary and initialize it with a copy, which will become a store after we
4243 mark it addressable. This can happen if the front-end passed us something
4244 that it could not mark addressable yet, like a Fortran pass-by-reference
4245 parameter (int) floatvar. */
4248 prepare_gimple_addressable (tree
*expr_p
, gimple_seq
*seq_p
)
4250 while (handled_component_p (*expr_p
))
4251 expr_p
= &TREE_OPERAND (*expr_p
, 0);
4252 if (is_gimple_reg (*expr_p
))
4254 /* Do not allow an SSA name as the temporary. */
4255 tree var
= get_initialized_tmp_var (*expr_p
, seq_p
, NULL
, false);
4256 DECL_GIMPLE_REG_P (var
) = 0;
4261 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with
4262 a call to __builtin_memcpy. */
4264 static enum gimplify_status
4265 gimplify_modify_expr_to_memcpy (tree
*expr_p
, tree size
, bool want_value
,
4268 tree t
, to
, to_ptr
, from
, from_ptr
;
4270 location_t loc
= EXPR_LOCATION (*expr_p
);
4272 to
= TREE_OPERAND (*expr_p
, 0);
4273 from
= TREE_OPERAND (*expr_p
, 1);
4275 /* Mark the RHS addressable. Beware that it may not be possible to do so
4276 directly if a temporary has been created by the gimplification. */
4277 prepare_gimple_addressable (&from
, seq_p
);
4279 mark_addressable (from
);
4280 from_ptr
= build_fold_addr_expr_loc (loc
, from
);
4281 gimplify_arg (&from_ptr
, seq_p
, loc
);
4283 mark_addressable (to
);
4284 to_ptr
= build_fold_addr_expr_loc (loc
, to
);
4285 gimplify_arg (&to_ptr
, seq_p
, loc
);
4287 t
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
4289 gs
= gimple_build_call (t
, 3, to_ptr
, from_ptr
, size
);
4293 /* tmp = memcpy() */
4294 t
= create_tmp_var (TREE_TYPE (to_ptr
));
4295 gimple_call_set_lhs (gs
, t
);
4296 gimplify_seq_add_stmt (seq_p
, gs
);
4298 *expr_p
= build_simple_mem_ref (t
);
4302 gimplify_seq_add_stmt (seq_p
, gs
);
4307 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with
4308 a call to __builtin_memset. In this case we know that the RHS is
4309 a CONSTRUCTOR with an empty element list. */
4311 static enum gimplify_status
4312 gimplify_modify_expr_to_memset (tree
*expr_p
, tree size
, bool want_value
,
4315 tree t
, from
, to
, to_ptr
;
4317 location_t loc
= EXPR_LOCATION (*expr_p
);
4319 /* Assert our assumptions, to abort instead of producing wrong code
4320 silently if they are not met. Beware that the RHS CONSTRUCTOR might
4321 not be immediately exposed. */
4322 from
= TREE_OPERAND (*expr_p
, 1);
4323 if (TREE_CODE (from
) == WITH_SIZE_EXPR
)
4324 from
= TREE_OPERAND (from
, 0);
4326 gcc_assert (TREE_CODE (from
) == CONSTRUCTOR
4327 && vec_safe_is_empty (CONSTRUCTOR_ELTS (from
)));
4330 to
= TREE_OPERAND (*expr_p
, 0);
4332 to_ptr
= build_fold_addr_expr_loc (loc
, to
);
4333 gimplify_arg (&to_ptr
, seq_p
, loc
);
4334 t
= builtin_decl_implicit (BUILT_IN_MEMSET
);
4336 gs
= gimple_build_call (t
, 3, to_ptr
, integer_zero_node
, size
);
4340 /* tmp = memset() */
4341 t
= create_tmp_var (TREE_TYPE (to_ptr
));
4342 gimple_call_set_lhs (gs
, t
);
4343 gimplify_seq_add_stmt (seq_p
, gs
);
4345 *expr_p
= build1 (INDIRECT_REF
, TREE_TYPE (to
), t
);
4349 gimplify_seq_add_stmt (seq_p
, gs
);
4354 /* A subroutine of gimplify_init_ctor_preeval. Called via walk_tree,
4355 determine, cautiously, if a CONSTRUCTOR overlaps the lhs of an
4356 assignment. Return non-null if we detect a potential overlap. */
4358 struct gimplify_init_ctor_preeval_data
4360 /* The base decl of the lhs object. May be NULL, in which case we
4361 have to assume the lhs is indirect. */
4364 /* The alias set of the lhs object. */
4365 alias_set_type lhs_alias_set
;
4369 gimplify_init_ctor_preeval_1 (tree
*tp
, int *walk_subtrees
, void *xdata
)
4371 struct gimplify_init_ctor_preeval_data
*data
4372 = (struct gimplify_init_ctor_preeval_data
*) xdata
;
4375 /* If we find the base object, obviously we have overlap. */
4376 if (data
->lhs_base_decl
== t
)
4379 /* If the constructor component is indirect, determine if we have a
4380 potential overlap with the lhs. The only bits of information we
4381 have to go on at this point are addressability and alias sets. */
4382 if ((INDIRECT_REF_P (t
)
4383 || TREE_CODE (t
) == MEM_REF
)
4384 && (!data
->lhs_base_decl
|| TREE_ADDRESSABLE (data
->lhs_base_decl
))
4385 && alias_sets_conflict_p (data
->lhs_alias_set
, get_alias_set (t
)))
4388 /* If the constructor component is a call, determine if it can hide a
4389 potential overlap with the lhs through an INDIRECT_REF like above.
4390 ??? Ugh - this is completely broken. In fact this whole analysis
4391 doesn't look conservative. */
4392 if (TREE_CODE (t
) == CALL_EXPR
)
4394 tree type
, fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t
)));
4396 for (type
= TYPE_ARG_TYPES (fntype
); type
; type
= TREE_CHAIN (type
))
4397 if (POINTER_TYPE_P (TREE_VALUE (type
))
4398 && (!data
->lhs_base_decl
|| TREE_ADDRESSABLE (data
->lhs_base_decl
))
4399 && alias_sets_conflict_p (data
->lhs_alias_set
,
4401 (TREE_TYPE (TREE_VALUE (type
)))))
4405 if (IS_TYPE_OR_DECL_P (t
))
4410 /* A subroutine of gimplify_init_constructor. Pre-evaluate EXPR,
4411 force values that overlap with the lhs (as described by *DATA)
4412 into temporaries. */
4415 gimplify_init_ctor_preeval (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
4416 struct gimplify_init_ctor_preeval_data
*data
)
4418 enum gimplify_status one
;
4420 /* If the value is constant, then there's nothing to pre-evaluate. */
4421 if (TREE_CONSTANT (*expr_p
))
4423 /* Ensure it does not have side effects, it might contain a reference to
4424 the object we're initializing. */
4425 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p
));
4429 /* If the type has non-trivial constructors, we can't pre-evaluate. */
4430 if (TREE_ADDRESSABLE (TREE_TYPE (*expr_p
)))
4433 /* Recurse for nested constructors. */
4434 if (TREE_CODE (*expr_p
) == CONSTRUCTOR
)
4436 unsigned HOST_WIDE_INT ix
;
4437 constructor_elt
*ce
;
4438 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (*expr_p
);
4440 FOR_EACH_VEC_SAFE_ELT (v
, ix
, ce
)
4441 gimplify_init_ctor_preeval (&ce
->value
, pre_p
, post_p
, data
);
4446 /* If this is a variable sized type, we must remember the size. */
4447 maybe_with_size_expr (expr_p
);
4449 /* Gimplify the constructor element to something appropriate for the rhs
4450 of a MODIFY_EXPR. Given that we know the LHS is an aggregate, we know
4451 the gimplifier will consider this a store to memory. Doing this
4452 gimplification now means that we won't have to deal with complicated
4453 language-specific trees, nor trees like SAVE_EXPR that can induce
4454 exponential search behavior. */
4455 one
= gimplify_expr (expr_p
, pre_p
, post_p
, is_gimple_mem_rhs
, fb_rvalue
);
4456 if (one
== GS_ERROR
)
4462 /* If we gimplified to a bare decl, we can be sure that it doesn't overlap
4463 with the lhs, since "a = { .x=a }" doesn't make sense. This will
4464 always be true for all scalars, since is_gimple_mem_rhs insists on a
4465 temporary variable for them. */
4466 if (DECL_P (*expr_p
))
4469 /* If this is of variable size, we have no choice but to assume it doesn't
4470 overlap since we can't make a temporary for it. */
4471 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (*expr_p
))) != INTEGER_CST
)
4474 /* Otherwise, we must search for overlap ... */
4475 if (!walk_tree (expr_p
, gimplify_init_ctor_preeval_1
, data
, NULL
))
4478 /* ... and if found, force the value into a temporary. */
4479 *expr_p
= get_formal_tmp_var (*expr_p
, pre_p
);
4482 /* A subroutine of gimplify_init_ctor_eval. Create a loop for
4483 a RANGE_EXPR in a CONSTRUCTOR for an array.
4487 object[var] = value;
4494 We increment var _after_ the loop exit check because we might otherwise
4495 fail if upper == TYPE_MAX_VALUE (type for upper).
4497 Note that we never have to deal with SAVE_EXPRs here, because this has
4498 already been taken care of for us, in gimplify_init_ctor_preeval(). */
4500 static void gimplify_init_ctor_eval (tree
, vec
<constructor_elt
, va_gc
> *,
4501 gimple_seq
*, bool);
4504 gimplify_init_ctor_eval_range (tree object
, tree lower
, tree upper
,
4505 tree value
, tree array_elt_type
,
4506 gimple_seq
*pre_p
, bool cleared
)
4508 tree loop_entry_label
, loop_exit_label
, fall_thru_label
;
4509 tree var
, var_type
, cref
, tmp
;
4511 loop_entry_label
= create_artificial_label (UNKNOWN_LOCATION
);
4512 loop_exit_label
= create_artificial_label (UNKNOWN_LOCATION
);
4513 fall_thru_label
= create_artificial_label (UNKNOWN_LOCATION
);
4515 /* Create and initialize the index variable. */
4516 var_type
= TREE_TYPE (upper
);
4517 var
= create_tmp_var (var_type
);
4518 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (var
, lower
));
4520 /* Add the loop entry label. */
4521 gimplify_seq_add_stmt (pre_p
, gimple_build_label (loop_entry_label
));
4523 /* Build the reference. */
4524 cref
= build4 (ARRAY_REF
, array_elt_type
, unshare_expr (object
),
4525 var
, NULL_TREE
, NULL_TREE
);
4527 /* If we are a constructor, just call gimplify_init_ctor_eval to do
4528 the store. Otherwise just assign value to the reference. */
4530 if (TREE_CODE (value
) == CONSTRUCTOR
)
4531 /* NB we might have to call ourself recursively through
4532 gimplify_init_ctor_eval if the value is a constructor. */
4533 gimplify_init_ctor_eval (cref
, CONSTRUCTOR_ELTS (value
),
4536 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (cref
, value
));
4538 /* We exit the loop when the index var is equal to the upper bound. */
4539 gimplify_seq_add_stmt (pre_p
,
4540 gimple_build_cond (EQ_EXPR
, var
, upper
,
4541 loop_exit_label
, fall_thru_label
));
4543 gimplify_seq_add_stmt (pre_p
, gimple_build_label (fall_thru_label
));
4545 /* Otherwise, increment the index var... */
4546 tmp
= build2 (PLUS_EXPR
, var_type
, var
,
4547 fold_convert (var_type
, integer_one_node
));
4548 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (var
, tmp
));
4550 /* ...and jump back to the loop entry. */
4551 gimplify_seq_add_stmt (pre_p
, gimple_build_goto (loop_entry_label
));
4553 /* Add the loop exit label. */
4554 gimplify_seq_add_stmt (pre_p
, gimple_build_label (loop_exit_label
));
4557 /* Return true if FDECL is accessing a field that is zero sized. */
4560 zero_sized_field_decl (const_tree fdecl
)
4562 if (TREE_CODE (fdecl
) == FIELD_DECL
&& DECL_SIZE (fdecl
)
4563 && integer_zerop (DECL_SIZE (fdecl
)))
4568 /* Return true if TYPE is zero sized. */
4571 zero_sized_type (const_tree type
)
4573 if (AGGREGATE_TYPE_P (type
) && TYPE_SIZE (type
)
4574 && integer_zerop (TYPE_SIZE (type
)))
4579 /* A subroutine of gimplify_init_constructor. Generate individual
4580 MODIFY_EXPRs for a CONSTRUCTOR. OBJECT is the LHS against which the
4581 assignments should happen. ELTS is the CONSTRUCTOR_ELTS of the
4582 CONSTRUCTOR. CLEARED is true if the entire LHS object has been
4586 gimplify_init_ctor_eval (tree object
, vec
<constructor_elt
, va_gc
> *elts
,
4587 gimple_seq
*pre_p
, bool cleared
)
4589 tree array_elt_type
= NULL
;
4590 unsigned HOST_WIDE_INT ix
;
4591 tree purpose
, value
;
4593 if (TREE_CODE (TREE_TYPE (object
)) == ARRAY_TYPE
)
4594 array_elt_type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (object
)));
4596 FOR_EACH_CONSTRUCTOR_ELT (elts
, ix
, purpose
, value
)
4600 /* NULL values are created above for gimplification errors. */
4604 if (cleared
&& initializer_zerop (value
))
4607 /* ??? Here's to hoping the front end fills in all of the indices,
4608 so we don't have to figure out what's missing ourselves. */
4609 gcc_assert (purpose
);
4611 /* Skip zero-sized fields, unless value has side-effects. This can
4612 happen with calls to functions returning a zero-sized type, which
4613 we shouldn't discard. As a number of downstream passes don't
4614 expect sets of zero-sized fields, we rely on the gimplification of
4615 the MODIFY_EXPR we make below to drop the assignment statement. */
4616 if (! TREE_SIDE_EFFECTS (value
) && zero_sized_field_decl (purpose
))
4619 /* If we have a RANGE_EXPR, we have to build a loop to assign the
4621 if (TREE_CODE (purpose
) == RANGE_EXPR
)
4623 tree lower
= TREE_OPERAND (purpose
, 0);
4624 tree upper
= TREE_OPERAND (purpose
, 1);
4626 /* If the lower bound is equal to upper, just treat it as if
4627 upper was the index. */
4628 if (simple_cst_equal (lower
, upper
))
4632 gimplify_init_ctor_eval_range (object
, lower
, upper
, value
,
4633 array_elt_type
, pre_p
, cleared
);
4640 /* Do not use bitsizetype for ARRAY_REF indices. */
4641 if (TYPE_DOMAIN (TREE_TYPE (object
)))
4643 = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object
))),
4645 cref
= build4 (ARRAY_REF
, array_elt_type
, unshare_expr (object
),
4646 purpose
, NULL_TREE
, NULL_TREE
);
4650 gcc_assert (TREE_CODE (purpose
) == FIELD_DECL
);
4651 cref
= build3 (COMPONENT_REF
, TREE_TYPE (purpose
),
4652 unshare_expr (object
), purpose
, NULL_TREE
);
4655 if (TREE_CODE (value
) == CONSTRUCTOR
4656 && TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
)
4657 gimplify_init_ctor_eval (cref
, CONSTRUCTOR_ELTS (value
),
4661 tree init
= build2 (INIT_EXPR
, TREE_TYPE (cref
), cref
, value
);
4662 gimplify_and_add (init
, pre_p
);
4668 /* Return the appropriate RHS predicate for this LHS. */
4671 rhs_predicate_for (tree lhs
)
4673 if (is_gimple_reg (lhs
))
4674 return is_gimple_reg_rhs_or_call
;
4676 return is_gimple_mem_rhs_or_call
;
4679 /* Return the initial guess for an appropriate RHS predicate for this LHS,
4680 before the LHS has been gimplified. */
4682 static gimple_predicate
4683 initial_rhs_predicate_for (tree lhs
)
4685 if (is_gimple_reg_type (TREE_TYPE (lhs
)))
4686 return is_gimple_reg_rhs_or_call
;
4688 return is_gimple_mem_rhs_or_call
;
4691 /* Gimplify a C99 compound literal expression. This just means adding
4692 the DECL_EXPR before the current statement and using its anonymous
4695 static enum gimplify_status
4696 gimplify_compound_literal_expr (tree
*expr_p
, gimple_seq
*pre_p
,
4697 bool (*gimple_test_f
) (tree
),
4698 fallback_t fallback
)
4700 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p
);
4701 tree decl
= DECL_EXPR_DECL (decl_s
);
4702 tree init
= DECL_INITIAL (decl
);
4703 /* Mark the decl as addressable if the compound literal
4704 expression is addressable now, otherwise it is marked too late
4705 after we gimplify the initialization expression. */
4706 if (TREE_ADDRESSABLE (*expr_p
))
4707 TREE_ADDRESSABLE (decl
) = 1;
4708 /* Otherwise, if we don't need an lvalue and have a literal directly
4709 substitute it. Check if it matches the gimple predicate, as
4710 otherwise we'd generate a new temporary, and we can as well just
4711 use the decl we already have. */
4712 else if (!TREE_ADDRESSABLE (decl
)
4713 && !TREE_THIS_VOLATILE (decl
)
4715 && (fallback
& fb_lvalue
) == 0
4716 && gimple_test_f (init
))
4722 /* Preliminarily mark non-addressed complex variables as eligible
4723 for promotion to gimple registers. We'll transform their uses
4725 if ((TREE_CODE (TREE_TYPE (decl
)) == COMPLEX_TYPE
4726 || TREE_CODE (TREE_TYPE (decl
)) == VECTOR_TYPE
)
4727 && !TREE_THIS_VOLATILE (decl
)
4728 && !needs_to_live_in_memory (decl
))
4729 DECL_GIMPLE_REG_P (decl
) = 1;
4731 /* If the decl is not addressable, then it is being used in some
4732 expression or on the right hand side of a statement, and it can
4733 be put into a readonly data section. */
4734 if (!TREE_ADDRESSABLE (decl
) && (fallback
& fb_lvalue
) == 0)
4735 TREE_READONLY (decl
) = 1;
4737 /* This decl isn't mentioned in the enclosing block, so add it to the
4738 list of temps. FIXME it seems a bit of a kludge to say that
4739 anonymous artificial vars aren't pushed, but everything else is. */
4740 if (DECL_NAME (decl
) == NULL_TREE
&& !DECL_SEEN_IN_BIND_EXPR_P (decl
))
4741 gimple_add_tmp_var (decl
);
4743 gimplify_and_add (decl_s
, pre_p
);
4748 /* Optimize embedded COMPOUND_LITERAL_EXPRs within a CONSTRUCTOR,
4749 return a new CONSTRUCTOR if something changed. */
4752 optimize_compound_literals_in_ctor (tree orig_ctor
)
4754 tree ctor
= orig_ctor
;
4755 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (ctor
);
4756 unsigned int idx
, num
= vec_safe_length (elts
);
4758 for (idx
= 0; idx
< num
; idx
++)
4760 tree value
= (*elts
)[idx
].value
;
4761 tree newval
= value
;
4762 if (TREE_CODE (value
) == CONSTRUCTOR
)
4763 newval
= optimize_compound_literals_in_ctor (value
);
4764 else if (TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
)
4766 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (value
);
4767 tree decl
= DECL_EXPR_DECL (decl_s
);
4768 tree init
= DECL_INITIAL (decl
);
4770 if (!TREE_ADDRESSABLE (value
)
4771 && !TREE_ADDRESSABLE (decl
)
4773 && TREE_CODE (init
) == CONSTRUCTOR
)
4774 newval
= optimize_compound_literals_in_ctor (init
);
4776 if (newval
== value
)
4779 if (ctor
== orig_ctor
)
4781 ctor
= copy_node (orig_ctor
);
4782 CONSTRUCTOR_ELTS (ctor
) = vec_safe_copy (elts
);
4783 elts
= CONSTRUCTOR_ELTS (ctor
);
4785 (*elts
)[idx
].value
= newval
;
4790 /* A subroutine of gimplify_modify_expr. Break out elements of a
4791 CONSTRUCTOR used as an initializer into separate MODIFY_EXPRs.
4793 Note that we still need to clear any elements that don't have explicit
4794 initializers, so if not all elements are initialized we keep the
4795 original MODIFY_EXPR, we just remove all of the constructor elements.
4797 If NOTIFY_TEMP_CREATION is true, do not gimplify, just return
4798 GS_ERROR if we would have to create a temporary when gimplifying
4799 this constructor. Otherwise, return GS_OK.
4801 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */
4803 static enum gimplify_status
4804 gimplify_init_constructor (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
4805 bool want_value
, bool notify_temp_creation
)
4807 tree object
, ctor
, type
;
4808 enum gimplify_status ret
;
4809 vec
<constructor_elt
, va_gc
> *elts
;
4811 gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p
, 1)) == CONSTRUCTOR
);
4813 if (!notify_temp_creation
)
4815 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
4816 is_gimple_lvalue
, fb_lvalue
);
4817 if (ret
== GS_ERROR
)
4821 object
= TREE_OPERAND (*expr_p
, 0);
4822 ctor
= TREE_OPERAND (*expr_p
, 1)
4823 = optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p
, 1));
4824 type
= TREE_TYPE (ctor
);
4825 elts
= CONSTRUCTOR_ELTS (ctor
);
4828 switch (TREE_CODE (type
))
4832 case QUAL_UNION_TYPE
:
4835 struct gimplify_init_ctor_preeval_data preeval_data
;
4836 HOST_WIDE_INT num_ctor_elements
, num_nonzero_elements
;
4837 HOST_WIDE_INT num_unique_nonzero_elements
;
4838 bool cleared
, complete_p
, valid_const_initializer
;
4839 /* Use readonly data for initializers of this or smaller size
4840 regardless of the num_nonzero_elements / num_unique_nonzero_elements
4842 const HOST_WIDE_INT min_unique_size
= 64;
4843 /* If num_nonzero_elements / num_unique_nonzero_elements ratio
4844 is smaller than this, use readonly data. */
4845 const int unique_nonzero_ratio
= 8;
4847 /* Aggregate types must lower constructors to initialization of
4848 individual elements. The exception is that a CONSTRUCTOR node
4849 with no elements indicates zero-initialization of the whole. */
4850 if (vec_safe_is_empty (elts
))
4852 if (notify_temp_creation
)
4857 /* Fetch information about the constructor to direct later processing.
4858 We might want to make static versions of it in various cases, and
4859 can only do so if it known to be a valid constant initializer. */
4860 valid_const_initializer
4861 = categorize_ctor_elements (ctor
, &num_nonzero_elements
,
4862 &num_unique_nonzero_elements
,
4863 &num_ctor_elements
, &complete_p
);
4865 /* If a const aggregate variable is being initialized, then it
4866 should never be a lose to promote the variable to be static. */
4867 if (valid_const_initializer
4868 && num_nonzero_elements
> 1
4869 && TREE_READONLY (object
)
4871 && (flag_merge_constants
>= 2 || !TREE_ADDRESSABLE (object
))
4872 /* For ctors that have many repeated nonzero elements
4873 represented through RANGE_EXPRs, prefer initializing
4874 those through runtime loops over copies of large amounts
4875 of data from readonly data section. */
4876 && (num_unique_nonzero_elements
4877 > num_nonzero_elements
/ unique_nonzero_ratio
4878 || ((unsigned HOST_WIDE_INT
) int_size_in_bytes (type
)
4879 <= (unsigned HOST_WIDE_INT
) min_unique_size
)))
4881 if (notify_temp_creation
)
4883 DECL_INITIAL (object
) = ctor
;
4884 TREE_STATIC (object
) = 1;
4885 if (!DECL_NAME (object
))
4886 DECL_NAME (object
) = create_tmp_var_name ("C");
4887 walk_tree (&DECL_INITIAL (object
), force_labels_r
, NULL
, NULL
);
4889 /* ??? C++ doesn't automatically append a .<number> to the
4890 assembler name, and even when it does, it looks at FE private
4891 data structures to figure out what that number should be,
4892 which are not set for this variable. I suppose this is
4893 important for local statics for inline functions, which aren't
4894 "local" in the object file sense. So in order to get a unique
4895 TU-local symbol, we must invoke the lhd version now. */
4896 lhd_set_decl_assembler_name (object
);
4898 *expr_p
= NULL_TREE
;
4902 /* If there are "lots" of initialized elements, even discounting
4903 those that are not address constants (and thus *must* be
4904 computed at runtime), then partition the constructor into
4905 constant and non-constant parts. Block copy the constant
4906 parts in, then generate code for the non-constant parts. */
4907 /* TODO. There's code in cp/typeck.c to do this. */
4909 if (int_size_in_bytes (TREE_TYPE (ctor
)) < 0)
4910 /* store_constructor will ignore the clearing of variable-sized
4911 objects. Initializers for such objects must explicitly set
4912 every field that needs to be set. */
4914 else if (!complete_p
)
4915 /* If the constructor isn't complete, clear the whole object
4916 beforehand, unless CONSTRUCTOR_NO_CLEARING is set on it.
4918 ??? This ought not to be needed. For any element not present
4919 in the initializer, we should simply set them to zero. Except
4920 we'd need to *find* the elements that are not present, and that
4921 requires trickery to avoid quadratic compile-time behavior in
4922 large cases or excessive memory use in small cases. */
4923 cleared
= !CONSTRUCTOR_NO_CLEARING (ctor
);
4924 else if (num_ctor_elements
- num_nonzero_elements
4925 > CLEAR_RATIO (optimize_function_for_speed_p (cfun
))
4926 && num_nonzero_elements
< num_ctor_elements
/ 4)
4927 /* If there are "lots" of zeros, it's more efficient to clear
4928 the memory and then set the nonzero elements. */
4933 /* If there are "lots" of initialized elements, and all of them
4934 are valid address constants, then the entire initializer can
4935 be dropped to memory, and then memcpy'd out. Don't do this
4936 for sparse arrays, though, as it's more efficient to follow
4937 the standard CONSTRUCTOR behavior of memset followed by
4938 individual element initialization. Also don't do this for small
4939 all-zero initializers (which aren't big enough to merit
4940 clearing), and don't try to make bitwise copies of
4941 TREE_ADDRESSABLE types. */
4943 if (valid_const_initializer
4944 && !(cleared
|| num_nonzero_elements
== 0)
4945 && !TREE_ADDRESSABLE (type
))
4947 HOST_WIDE_INT size
= int_size_in_bytes (type
);
4950 /* ??? We can still get unbounded array types, at least
4951 from the C++ front end. This seems wrong, but attempt
4952 to work around it for now. */
4955 size
= int_size_in_bytes (TREE_TYPE (object
));
4957 TREE_TYPE (ctor
) = type
= TREE_TYPE (object
);
4960 /* Find the maximum alignment we can assume for the object. */
4961 /* ??? Make use of DECL_OFFSET_ALIGN. */
4962 if (DECL_P (object
))
4963 align
= DECL_ALIGN (object
);
4965 align
= TYPE_ALIGN (type
);
4967 /* Do a block move either if the size is so small as to make
4968 each individual move a sub-unit move on average, or if it
4969 is so large as to make individual moves inefficient. */
4971 && num_nonzero_elements
> 1
4972 /* For ctors that have many repeated nonzero elements
4973 represented through RANGE_EXPRs, prefer initializing
4974 those through runtime loops over copies of large amounts
4975 of data from readonly data section. */
4976 && (num_unique_nonzero_elements
4977 > num_nonzero_elements
/ unique_nonzero_ratio
4978 || size
<= min_unique_size
)
4979 && (size
< num_nonzero_elements
4980 || !can_move_by_pieces (size
, align
)))
4982 if (notify_temp_creation
)
4985 walk_tree (&ctor
, force_labels_r
, NULL
, NULL
);
4986 ctor
= tree_output_constant_def (ctor
);
4987 if (!useless_type_conversion_p (type
, TREE_TYPE (ctor
)))
4988 ctor
= build1 (VIEW_CONVERT_EXPR
, type
, ctor
);
4989 TREE_OPERAND (*expr_p
, 1) = ctor
;
4991 /* This is no longer an assignment of a CONSTRUCTOR, but
4992 we still may have processing to do on the LHS. So
4993 pretend we didn't do anything here to let that happen. */
4994 return GS_UNHANDLED
;
4998 /* If the target is volatile, we have non-zero elements and more than
4999 one field to assign, initialize the target from a temporary. */
5000 if (TREE_THIS_VOLATILE (object
)
5001 && !TREE_ADDRESSABLE (type
)
5002 && num_nonzero_elements
> 0
5003 && vec_safe_length (elts
) > 1)
5005 tree temp
= create_tmp_var (TYPE_MAIN_VARIANT (type
));
5006 TREE_OPERAND (*expr_p
, 0) = temp
;
5007 *expr_p
= build2 (COMPOUND_EXPR
, TREE_TYPE (*expr_p
),
5009 build2 (MODIFY_EXPR
, void_type_node
,
5014 if (notify_temp_creation
)
5017 /* If there are nonzero elements and if needed, pre-evaluate to capture
5018 elements overlapping with the lhs into temporaries. We must do this
5019 before clearing to fetch the values before they are zeroed-out. */
5020 if (num_nonzero_elements
> 0 && TREE_CODE (*expr_p
) != INIT_EXPR
)
5022 preeval_data
.lhs_base_decl
= get_base_address (object
);
5023 if (!DECL_P (preeval_data
.lhs_base_decl
))
5024 preeval_data
.lhs_base_decl
= NULL
;
5025 preeval_data
.lhs_alias_set
= get_alias_set (object
);
5027 gimplify_init_ctor_preeval (&TREE_OPERAND (*expr_p
, 1),
5028 pre_p
, post_p
, &preeval_data
);
5031 bool ctor_has_side_effects_p
5032 = TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p
, 1));
5036 /* Zap the CONSTRUCTOR element list, which simplifies this case.
5037 Note that we still have to gimplify, in order to handle the
5038 case of variable sized types. Avoid shared tree structures. */
5039 CONSTRUCTOR_ELTS (ctor
) = NULL
;
5040 TREE_SIDE_EFFECTS (ctor
) = 0;
5041 object
= unshare_expr (object
);
5042 gimplify_stmt (expr_p
, pre_p
);
5045 /* If we have not block cleared the object, or if there are nonzero
5046 elements in the constructor, or if the constructor has side effects,
5047 add assignments to the individual scalar fields of the object. */
5049 || num_nonzero_elements
> 0
5050 || ctor_has_side_effects_p
)
5051 gimplify_init_ctor_eval (object
, elts
, pre_p
, cleared
);
5053 *expr_p
= NULL_TREE
;
5061 if (notify_temp_creation
)
5064 /* Extract the real and imaginary parts out of the ctor. */
5065 gcc_assert (elts
->length () == 2);
5066 r
= (*elts
)[0].value
;
5067 i
= (*elts
)[1].value
;
5068 if (r
== NULL
|| i
== NULL
)
5070 tree zero
= build_zero_cst (TREE_TYPE (type
));
5077 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
5078 represent creation of a complex value. */
5079 if (TREE_CONSTANT (r
) && TREE_CONSTANT (i
))
5081 ctor
= build_complex (type
, r
, i
);
5082 TREE_OPERAND (*expr_p
, 1) = ctor
;
5086 ctor
= build2 (COMPLEX_EXPR
, type
, r
, i
);
5087 TREE_OPERAND (*expr_p
, 1) = ctor
;
5088 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1),
5091 rhs_predicate_for (TREE_OPERAND (*expr_p
, 0)),
5099 unsigned HOST_WIDE_INT ix
;
5100 constructor_elt
*ce
;
5102 if (notify_temp_creation
)
5105 /* Go ahead and simplify constant constructors to VECTOR_CST. */
5106 if (TREE_CONSTANT (ctor
))
5108 bool constant_p
= true;
5111 /* Even when ctor is constant, it might contain non-*_CST
5112 elements, such as addresses or trapping values like
5113 1.0/0.0 - 1.0/0.0. Such expressions don't belong
5114 in VECTOR_CST nodes. */
5115 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
5116 if (!CONSTANT_CLASS_P (value
))
5124 TREE_OPERAND (*expr_p
, 1) = build_vector_from_ctor (type
, elts
);
5128 TREE_CONSTANT (ctor
) = 0;
5131 /* Vector types use CONSTRUCTOR all the way through gimple
5132 compilation as a general initializer. */
5133 FOR_EACH_VEC_SAFE_ELT (elts
, ix
, ce
)
5135 enum gimplify_status tret
;
5136 tret
= gimplify_expr (&ce
->value
, pre_p
, post_p
, is_gimple_val
,
5138 if (tret
== GS_ERROR
)
5140 else if (TREE_STATIC (ctor
)
5141 && !initializer_constant_valid_p (ce
->value
,
5142 TREE_TYPE (ce
->value
)))
5143 TREE_STATIC (ctor
) = 0;
5145 if (!is_gimple_reg (TREE_OPERAND (*expr_p
, 0)))
5146 TREE_OPERAND (*expr_p
, 1) = get_formal_tmp_var (ctor
, pre_p
);
5151 /* So how did we get a CONSTRUCTOR for a scalar type? */
5155 if (ret
== GS_ERROR
)
5157 /* If we have gimplified both sides of the initializer but have
5158 not emitted an assignment, do so now. */
5161 tree lhs
= TREE_OPERAND (*expr_p
, 0);
5162 tree rhs
= TREE_OPERAND (*expr_p
, 1);
5163 if (want_value
&& object
== lhs
)
5164 lhs
= unshare_expr (lhs
);
5165 gassign
*init
= gimple_build_assign (lhs
, rhs
);
5166 gimplify_seq_add_stmt (pre_p
, init
);
5180 /* Given a pointer value OP0, return a simplified version of an
5181 indirection through OP0, or NULL_TREE if no simplification is
5182 possible. This may only be applied to a rhs of an expression.
5183 Note that the resulting type may be different from the type pointed
5184 to in the sense that it is still compatible from the langhooks
5188 gimple_fold_indirect_ref_rhs (tree t
)
5190 return gimple_fold_indirect_ref (t
);
5193 /* Subroutine of gimplify_modify_expr to do simplifications of
5194 MODIFY_EXPRs based on the code of the RHS. We loop for as long as
5195 something changes. */
5197 static enum gimplify_status
5198 gimplify_modify_expr_rhs (tree
*expr_p
, tree
*from_p
, tree
*to_p
,
5199 gimple_seq
*pre_p
, gimple_seq
*post_p
,
5202 enum gimplify_status ret
= GS_UNHANDLED
;
5208 switch (TREE_CODE (*from_p
))
5211 /* If we're assigning from a read-only variable initialized with
5212 a constructor, do the direct assignment from the constructor,
5213 but only if neither source nor target are volatile since this
5214 latter assignment might end up being done on a per-field basis. */
5215 if (DECL_INITIAL (*from_p
)
5216 && TREE_READONLY (*from_p
)
5217 && !TREE_THIS_VOLATILE (*from_p
)
5218 && !TREE_THIS_VOLATILE (*to_p
)
5219 && TREE_CODE (DECL_INITIAL (*from_p
)) == CONSTRUCTOR
)
5221 tree old_from
= *from_p
;
5222 enum gimplify_status subret
;
5224 /* Move the constructor into the RHS. */
5225 *from_p
= unshare_expr (DECL_INITIAL (*from_p
));
5227 /* Let's see if gimplify_init_constructor will need to put
5229 subret
= gimplify_init_constructor (expr_p
, NULL
, NULL
,
5231 if (subret
== GS_ERROR
)
5233 /* If so, revert the change. */
5245 /* If we have code like
5249 where the type of "x" is a (possibly cv-qualified variant
5250 of "A"), treat the entire expression as identical to "x".
5251 This kind of code arises in C++ when an object is bound
5252 to a const reference, and if "x" is a TARGET_EXPR we want
5253 to take advantage of the optimization below. */
5254 bool volatile_p
= TREE_THIS_VOLATILE (*from_p
);
5255 tree t
= gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p
, 0));
5258 if (TREE_THIS_VOLATILE (t
) != volatile_p
)
5261 t
= build_simple_mem_ref_loc (EXPR_LOCATION (*from_p
),
5262 build_fold_addr_expr (t
));
5263 if (REFERENCE_CLASS_P (t
))
5264 TREE_THIS_VOLATILE (t
) = volatile_p
;
5275 /* If we are initializing something from a TARGET_EXPR, strip the
5276 TARGET_EXPR and initialize it directly, if possible. This can't
5277 be done if the initializer is void, since that implies that the
5278 temporary is set in some non-trivial way.
5280 ??? What about code that pulls out the temp and uses it
5281 elsewhere? I think that such code never uses the TARGET_EXPR as
5282 an initializer. If I'm wrong, we'll die because the temp won't
5283 have any RTL. In that case, I guess we'll need to replace
5284 references somehow. */
5285 tree init
= TARGET_EXPR_INITIAL (*from_p
);
5288 && (TREE_CODE (*expr_p
) != MODIFY_EXPR
5289 || !TARGET_EXPR_NO_ELIDE (*from_p
))
5290 && !VOID_TYPE_P (TREE_TYPE (init
)))
5300 /* Remove any COMPOUND_EXPR in the RHS so the following cases will be
5302 gimplify_compound_expr (from_p
, pre_p
, true);
5308 /* If we already made some changes, let the front end have a
5309 crack at this before we break it down. */
5310 if (ret
!= GS_UNHANDLED
)
5312 /* If we're initializing from a CONSTRUCTOR, break this into
5313 individual MODIFY_EXPRs. */
5314 return gimplify_init_constructor (expr_p
, pre_p
, post_p
, want_value
,
5318 /* If we're assigning to a non-register type, push the assignment
5319 down into the branches. This is mandatory for ADDRESSABLE types,
5320 since we cannot generate temporaries for such, but it saves a
5321 copy in other cases as well. */
5322 if (!is_gimple_reg_type (TREE_TYPE (*from_p
)))
5324 /* This code should mirror the code in gimplify_cond_expr. */
5325 enum tree_code code
= TREE_CODE (*expr_p
);
5326 tree cond
= *from_p
;
5327 tree result
= *to_p
;
5329 ret
= gimplify_expr (&result
, pre_p
, post_p
,
5330 is_gimple_lvalue
, fb_lvalue
);
5331 if (ret
!= GS_ERROR
)
5334 /* If we are going to write RESULT more than once, clear
5335 TREE_READONLY flag, otherwise we might incorrectly promote
5336 the variable to static const and initialize it at compile
5337 time in one of the branches. */
5339 && TREE_TYPE (TREE_OPERAND (cond
, 1)) != void_type_node
5340 && TREE_TYPE (TREE_OPERAND (cond
, 2)) != void_type_node
)
5341 TREE_READONLY (result
) = 0;
5342 if (TREE_TYPE (TREE_OPERAND (cond
, 1)) != void_type_node
)
5343 TREE_OPERAND (cond
, 1)
5344 = build2 (code
, void_type_node
, result
,
5345 TREE_OPERAND (cond
, 1));
5346 if (TREE_TYPE (TREE_OPERAND (cond
, 2)) != void_type_node
)
5347 TREE_OPERAND (cond
, 2)
5348 = build2 (code
, void_type_node
, unshare_expr (result
),
5349 TREE_OPERAND (cond
, 2));
5351 TREE_TYPE (cond
) = void_type_node
;
5352 recalculate_side_effects (cond
);
5356 gimplify_and_add (cond
, pre_p
);
5357 *expr_p
= unshare_expr (result
);
5366 /* For calls that return in memory, give *to_p as the CALL_EXPR's
5367 return slot so that we don't generate a temporary. */
5368 if (!CALL_EXPR_RETURN_SLOT_OPT (*from_p
)
5369 && aggregate_value_p (*from_p
, *from_p
))
5373 if (!(rhs_predicate_for (*to_p
))(*from_p
))
5374 /* If we need a temporary, *to_p isn't accurate. */
5376 /* It's OK to use the return slot directly unless it's an NRV. */
5377 else if (TREE_CODE (*to_p
) == RESULT_DECL
5378 && DECL_NAME (*to_p
) == NULL_TREE
5379 && needs_to_live_in_memory (*to_p
))
5381 else if (is_gimple_reg_type (TREE_TYPE (*to_p
))
5382 || (DECL_P (*to_p
) && DECL_REGISTER (*to_p
)))
5383 /* Don't force regs into memory. */
5385 else if (TREE_CODE (*expr_p
) == INIT_EXPR
)
5386 /* It's OK to use the target directly if it's being
5389 else if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p
)))
5391 /* Always use the target and thus RSO for variable-sized types.
5392 GIMPLE cannot deal with a variable-sized assignment
5393 embedded in a call statement. */
5395 else if (TREE_CODE (*to_p
) != SSA_NAME
5396 && (!is_gimple_variable (*to_p
)
5397 || needs_to_live_in_memory (*to_p
)))
5398 /* Don't use the original target if it's already addressable;
5399 if its address escapes, and the called function uses the
5400 NRV optimization, a conforming program could see *to_p
5401 change before the called function returns; see c++/19317.
5402 When optimizing, the return_slot pass marks more functions
5403 as safe after we have escape info. */
5410 CALL_EXPR_RETURN_SLOT_OPT (*from_p
) = 1;
5411 mark_addressable (*to_p
);
5416 case WITH_SIZE_EXPR
:
5417 /* Likewise for calls that return an aggregate of non-constant size,
5418 since we would not be able to generate a temporary at all. */
5419 if (TREE_CODE (TREE_OPERAND (*from_p
, 0)) == CALL_EXPR
)
5421 *from_p
= TREE_OPERAND (*from_p
, 0);
5422 /* We don't change ret in this case because the
5423 WITH_SIZE_EXPR might have been added in
5424 gimplify_modify_expr, so returning GS_OK would lead to an
5430 /* If we're initializing from a container, push the initialization
5432 case CLEANUP_POINT_EXPR
:
5434 case STATEMENT_LIST
:
5436 tree wrap
= *from_p
;
5439 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_min_lval
,
5441 if (ret
!= GS_ERROR
)
5444 t
= voidify_wrapper_expr (wrap
, *expr_p
);
5445 gcc_assert (t
== *expr_p
);
5449 gimplify_and_add (wrap
, pre_p
);
5450 *expr_p
= unshare_expr (*to_p
);
5457 case COMPOUND_LITERAL_EXPR
:
5459 tree complit
= TREE_OPERAND (*expr_p
, 1);
5460 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (complit
);
5461 tree decl
= DECL_EXPR_DECL (decl_s
);
5462 tree init
= DECL_INITIAL (decl
);
5464 /* struct T x = (struct T) { 0, 1, 2 } can be optimized
5465 into struct T x = { 0, 1, 2 } if the address of the
5466 compound literal has never been taken. */
5467 if (!TREE_ADDRESSABLE (complit
)
5468 && !TREE_ADDRESSABLE (decl
)
5471 *expr_p
= copy_node (*expr_p
);
5472 TREE_OPERAND (*expr_p
, 1) = init
;
5487 /* Return true if T looks like a valid GIMPLE statement. */
5490 is_gimple_stmt (tree t
)
5492 const enum tree_code code
= TREE_CODE (t
);
5497 /* The only valid NOP_EXPR is the empty statement. */
5498 return IS_EMPTY_STMT (t
);
5502 /* These are only valid if they're void. */
5503 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
5509 case CASE_LABEL_EXPR
:
5510 case TRY_CATCH_EXPR
:
5511 case TRY_FINALLY_EXPR
:
5512 case EH_FILTER_EXPR
:
5515 case STATEMENT_LIST
:
5519 case OACC_HOST_DATA
:
5522 case OACC_ENTER_DATA
:
5523 case OACC_EXIT_DATA
:
5528 case OMP_DISTRIBUTE
:
5540 case OMP_TARGET_DATA
:
5541 case OMP_TARGET_UPDATE
:
5542 case OMP_TARGET_ENTER_DATA
:
5543 case OMP_TARGET_EXIT_DATA
:
5546 /* These are always void. */
5552 /* These are valid regardless of their type. */
5561 /* Promote partial stores to COMPLEX variables to total stores. *EXPR_P is
5562 a MODIFY_EXPR with a lhs of a REAL/IMAGPART_EXPR of a variable with
5563 DECL_GIMPLE_REG_P set.
5565 IMPORTANT NOTE: This promotion is performed by introducing a load of the
5566 other, unmodified part of the complex object just before the total store.
5567 As a consequence, if the object is still uninitialized, an undefined value
5568 will be loaded into a register, which may result in a spurious exception
5569 if the register is floating-point and the value happens to be a signaling
5570 NaN for example. Then the fully-fledged complex operations lowering pass
5571 followed by a DCE pass are necessary in order to fix things up. */
5573 static enum gimplify_status
5574 gimplify_modify_expr_complex_part (tree
*expr_p
, gimple_seq
*pre_p
,
5577 enum tree_code code
, ocode
;
5578 tree lhs
, rhs
, new_rhs
, other
, realpart
, imagpart
;
5580 lhs
= TREE_OPERAND (*expr_p
, 0);
5581 rhs
= TREE_OPERAND (*expr_p
, 1);
5582 code
= TREE_CODE (lhs
);
5583 lhs
= TREE_OPERAND (lhs
, 0);
5585 ocode
= code
== REALPART_EXPR
? IMAGPART_EXPR
: REALPART_EXPR
;
5586 other
= build1 (ocode
, TREE_TYPE (rhs
), lhs
);
5587 TREE_NO_WARNING (other
) = 1;
5588 other
= get_formal_tmp_var (other
, pre_p
);
5590 realpart
= code
== REALPART_EXPR
? rhs
: other
;
5591 imagpart
= code
== REALPART_EXPR
? other
: rhs
;
5593 if (TREE_CONSTANT (realpart
) && TREE_CONSTANT (imagpart
))
5594 new_rhs
= build_complex (TREE_TYPE (lhs
), realpart
, imagpart
);
5596 new_rhs
= build2 (COMPLEX_EXPR
, TREE_TYPE (lhs
), realpart
, imagpart
);
5598 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (lhs
, new_rhs
));
5599 *expr_p
= (want_value
) ? rhs
: NULL_TREE
;
5604 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P.
5610 PRE_P points to the list where side effects that must happen before
5611 *EXPR_P should be stored.
5613 POST_P points to the list where side effects that must happen after
5614 *EXPR_P should be stored.
5616 WANT_VALUE is nonzero iff we want to use the value of this expression
5617 in another expression. */
5619 static enum gimplify_status
5620 gimplify_modify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
5623 tree
*from_p
= &TREE_OPERAND (*expr_p
, 1);
5624 tree
*to_p
= &TREE_OPERAND (*expr_p
, 0);
5625 enum gimplify_status ret
= GS_UNHANDLED
;
5627 location_t loc
= EXPR_LOCATION (*expr_p
);
5628 gimple_stmt_iterator gsi
;
5630 gcc_assert (TREE_CODE (*expr_p
) == MODIFY_EXPR
5631 || TREE_CODE (*expr_p
) == INIT_EXPR
);
5633 /* Trying to simplify a clobber using normal logic doesn't work,
5634 so handle it here. */
5635 if (TREE_CLOBBER_P (*from_p
))
5637 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
5638 if (ret
== GS_ERROR
)
5640 gcc_assert (!want_value
);
5641 if (!VAR_P (*to_p
) && TREE_CODE (*to_p
) != MEM_REF
)
5643 tree addr
= get_initialized_tmp_var (build_fold_addr_expr (*to_p
),
5645 *to_p
= build_simple_mem_ref_loc (EXPR_LOCATION (*to_p
), addr
);
5647 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (*to_p
, *from_p
));
5652 /* Insert pointer conversions required by the middle-end that are not
5653 required by the frontend. This fixes middle-end type checking for
5654 for example gcc.dg/redecl-6.c. */
5655 if (POINTER_TYPE_P (TREE_TYPE (*to_p
)))
5657 STRIP_USELESS_TYPE_CONVERSION (*from_p
);
5658 if (!useless_type_conversion_p (TREE_TYPE (*to_p
), TREE_TYPE (*from_p
)))
5659 *from_p
= fold_convert_loc (loc
, TREE_TYPE (*to_p
), *from_p
);
5662 /* See if any simplifications can be done based on what the RHS is. */
5663 ret
= gimplify_modify_expr_rhs (expr_p
, from_p
, to_p
, pre_p
, post_p
,
5665 if (ret
!= GS_UNHANDLED
)
5668 /* For zero sized types only gimplify the left hand side and right hand
5669 side as statements and throw away the assignment. Do this after
5670 gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
5672 if (zero_sized_type (TREE_TYPE (*from_p
))
5674 /* Don't do this for calls that return addressable types, expand_call
5675 relies on those having a lhs. */
5676 && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p
))
5677 && TREE_CODE (*from_p
) == CALL_EXPR
))
5679 gimplify_stmt (from_p
, pre_p
);
5680 gimplify_stmt (to_p
, pre_p
);
5681 *expr_p
= NULL_TREE
;
5685 /* If the value being copied is of variable width, compute the length
5686 of the copy into a WITH_SIZE_EXPR. Note that we need to do this
5687 before gimplifying any of the operands so that we can resolve any
5688 PLACEHOLDER_EXPRs in the size. Also note that the RTL expander uses
5689 the size of the expression to be copied, not of the destination, so
5690 that is what we must do here. */
5691 maybe_with_size_expr (from_p
);
5693 /* As a special case, we have to temporarily allow for assignments
5694 with a CALL_EXPR on the RHS. Since in GIMPLE a function call is
5695 a toplevel statement, when gimplifying the GENERIC expression
5696 MODIFY_EXPR <a, CALL_EXPR <foo>>, we cannot create the tuple
5697 GIMPLE_ASSIGN <a, GIMPLE_CALL <foo>>.
5699 Instead, we need to create the tuple GIMPLE_CALL <a, foo>. To
5700 prevent gimplify_expr from trying to create a new temporary for
5701 foo's LHS, we tell it that it should only gimplify until it
5702 reaches the CALL_EXPR. On return from gimplify_expr, the newly
5703 created GIMPLE_CALL <foo> will be the last statement in *PRE_P
5704 and all we need to do here is set 'a' to be its LHS. */
5706 /* Gimplify the RHS first for C++17 and bug 71104. */
5707 gimple_predicate initial_pred
= initial_rhs_predicate_for (*to_p
);
5708 ret
= gimplify_expr (from_p
, pre_p
, post_p
, initial_pred
, fb_rvalue
);
5709 if (ret
== GS_ERROR
)
5712 /* Then gimplify the LHS. */
5713 /* If we gimplified the RHS to a CALL_EXPR and that call may return
5714 twice we have to make sure to gimplify into non-SSA as otherwise
5715 the abnormal edge added later will make those defs not dominate
5717 ??? Technically this applies only to the registers used in the
5718 resulting non-register *TO_P. */
5719 bool saved_into_ssa
= gimplify_ctxp
->into_ssa
;
5721 && TREE_CODE (*from_p
) == CALL_EXPR
5722 && call_expr_flags (*from_p
) & ECF_RETURNS_TWICE
)
5723 gimplify_ctxp
->into_ssa
= false;
5724 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
5725 gimplify_ctxp
->into_ssa
= saved_into_ssa
;
5726 if (ret
== GS_ERROR
)
5729 /* Now that the LHS is gimplified, re-gimplify the RHS if our initial
5730 guess for the predicate was wrong. */
5731 gimple_predicate final_pred
= rhs_predicate_for (*to_p
);
5732 if (final_pred
!= initial_pred
)
5734 ret
= gimplify_expr (from_p
, pre_p
, post_p
, final_pred
, fb_rvalue
);
5735 if (ret
== GS_ERROR
)
5739 /* In case of va_arg internal fn wrappped in a WITH_SIZE_EXPR, add the type
5740 size as argument to the call. */
5741 if (TREE_CODE (*from_p
) == WITH_SIZE_EXPR
)
5743 tree call
= TREE_OPERAND (*from_p
, 0);
5744 tree vlasize
= TREE_OPERAND (*from_p
, 1);
5746 if (TREE_CODE (call
) == CALL_EXPR
5747 && CALL_EXPR_IFN (call
) == IFN_VA_ARG
)
5749 int nargs
= call_expr_nargs (call
);
5750 tree type
= TREE_TYPE (call
);
5751 tree ap
= CALL_EXPR_ARG (call
, 0);
5752 tree tag
= CALL_EXPR_ARG (call
, 1);
5753 tree aptag
= CALL_EXPR_ARG (call
, 2);
5754 tree newcall
= build_call_expr_internal_loc (EXPR_LOCATION (call
),
5758 TREE_OPERAND (*from_p
, 0) = newcall
;
5762 /* Now see if the above changed *from_p to something we handle specially. */
5763 ret
= gimplify_modify_expr_rhs (expr_p
, from_p
, to_p
, pre_p
, post_p
,
5765 if (ret
!= GS_UNHANDLED
)
5768 /* If we've got a variable sized assignment between two lvalues (i.e. does
5769 not involve a call), then we can make things a bit more straightforward
5770 by converting the assignment to memcpy or memset. */
5771 if (TREE_CODE (*from_p
) == WITH_SIZE_EXPR
)
5773 tree from
= TREE_OPERAND (*from_p
, 0);
5774 tree size
= TREE_OPERAND (*from_p
, 1);
5776 if (TREE_CODE (from
) == CONSTRUCTOR
)
5777 return gimplify_modify_expr_to_memset (expr_p
, size
, want_value
, pre_p
);
5779 if (is_gimple_addressable (from
))
5782 return gimplify_modify_expr_to_memcpy (expr_p
, size
, want_value
,
5787 /* Transform partial stores to non-addressable complex variables into
5788 total stores. This allows us to use real instead of virtual operands
5789 for these variables, which improves optimization. */
5790 if ((TREE_CODE (*to_p
) == REALPART_EXPR
5791 || TREE_CODE (*to_p
) == IMAGPART_EXPR
)
5792 && is_gimple_reg (TREE_OPERAND (*to_p
, 0)))
5793 return gimplify_modify_expr_complex_part (expr_p
, pre_p
, want_value
);
5795 /* Try to alleviate the effects of the gimplification creating artificial
5796 temporaries (see for example is_gimple_reg_rhs) on the debug info, but
5797 make sure not to create DECL_DEBUG_EXPR links across functions. */
5798 if (!gimplify_ctxp
->into_ssa
5800 && DECL_IGNORED_P (*from_p
)
5802 && !DECL_IGNORED_P (*to_p
)
5803 && decl_function_context (*to_p
) == current_function_decl
5804 && decl_function_context (*from_p
) == current_function_decl
)
5806 if (!DECL_NAME (*from_p
) && DECL_NAME (*to_p
))
5808 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p
)));
5809 DECL_HAS_DEBUG_EXPR_P (*from_p
) = 1;
5810 SET_DECL_DEBUG_EXPR (*from_p
, *to_p
);
5813 if (want_value
&& TREE_THIS_VOLATILE (*to_p
))
5814 *from_p
= get_initialized_tmp_var (*from_p
, pre_p
, post_p
);
5816 if (TREE_CODE (*from_p
) == CALL_EXPR
)
5818 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL
5819 instead of a GIMPLE_ASSIGN. */
5821 if (CALL_EXPR_FN (*from_p
) == NULL_TREE
)
5823 /* Gimplify internal functions created in the FEs. */
5824 int nargs
= call_expr_nargs (*from_p
), i
;
5825 enum internal_fn ifn
= CALL_EXPR_IFN (*from_p
);
5826 auto_vec
<tree
> vargs (nargs
);
5828 for (i
= 0; i
< nargs
; i
++)
5830 gimplify_arg (&CALL_EXPR_ARG (*from_p
, i
), pre_p
,
5831 EXPR_LOCATION (*from_p
));
5832 vargs
.quick_push (CALL_EXPR_ARG (*from_p
, i
));
5834 call_stmt
= gimple_build_call_internal_vec (ifn
, vargs
);
5835 gimple_call_set_nothrow (call_stmt
, TREE_NOTHROW (*from_p
));
5836 gimple_set_location (call_stmt
, EXPR_LOCATION (*expr_p
));
5840 tree fnptrtype
= TREE_TYPE (CALL_EXPR_FN (*from_p
));
5841 CALL_EXPR_FN (*from_p
) = TREE_OPERAND (CALL_EXPR_FN (*from_p
), 0);
5842 STRIP_USELESS_TYPE_CONVERSION (CALL_EXPR_FN (*from_p
));
5843 tree fndecl
= get_callee_fndecl (*from_p
);
5845 && fndecl_built_in_p (fndecl
, BUILT_IN_EXPECT
)
5846 && call_expr_nargs (*from_p
) == 3)
5847 call_stmt
= gimple_build_call_internal (IFN_BUILTIN_EXPECT
, 3,
5848 CALL_EXPR_ARG (*from_p
, 0),
5849 CALL_EXPR_ARG (*from_p
, 1),
5850 CALL_EXPR_ARG (*from_p
, 2));
5853 call_stmt
= gimple_build_call_from_tree (*from_p
, fnptrtype
);
5856 notice_special_calls (call_stmt
);
5857 if (!gimple_call_noreturn_p (call_stmt
) || !should_remove_lhs_p (*to_p
))
5858 gimple_call_set_lhs (call_stmt
, *to_p
);
5859 else if (TREE_CODE (*to_p
) == SSA_NAME
)
5860 /* The above is somewhat premature, avoid ICEing later for a
5861 SSA name w/o a definition. We may have uses in the GIMPLE IL.
5862 ??? This doesn't make it a default-def. */
5863 SSA_NAME_DEF_STMT (*to_p
) = gimple_build_nop ();
5869 assign
= gimple_build_assign (*to_p
, *from_p
);
5870 gimple_set_location (assign
, EXPR_LOCATION (*expr_p
));
5871 if (COMPARISON_CLASS_P (*from_p
))
5872 gimple_set_no_warning (assign
, TREE_NO_WARNING (*from_p
));
5875 if (gimplify_ctxp
->into_ssa
&& is_gimple_reg (*to_p
))
5877 /* We should have got an SSA name from the start. */
5878 gcc_assert (TREE_CODE (*to_p
) == SSA_NAME
5879 || ! gimple_in_ssa_p (cfun
));
5882 gimplify_seq_add_stmt (pre_p
, assign
);
5883 gsi
= gsi_last (*pre_p
);
5884 maybe_fold_stmt (&gsi
);
5888 *expr_p
= TREE_THIS_VOLATILE (*to_p
) ? *from_p
: unshare_expr (*to_p
);
5897 /* Gimplify a comparison between two variable-sized objects. Do this
5898 with a call to BUILT_IN_MEMCMP. */
5900 static enum gimplify_status
5901 gimplify_variable_sized_compare (tree
*expr_p
)
5903 location_t loc
= EXPR_LOCATION (*expr_p
);
5904 tree op0
= TREE_OPERAND (*expr_p
, 0);
5905 tree op1
= TREE_OPERAND (*expr_p
, 1);
5906 tree t
, arg
, dest
, src
, expr
;
5908 arg
= TYPE_SIZE_UNIT (TREE_TYPE (op0
));
5909 arg
= unshare_expr (arg
);
5910 arg
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (arg
, op0
);
5911 src
= build_fold_addr_expr_loc (loc
, op1
);
5912 dest
= build_fold_addr_expr_loc (loc
, op0
);
5913 t
= builtin_decl_implicit (BUILT_IN_MEMCMP
);
5914 t
= build_call_expr_loc (loc
, t
, 3, dest
, src
, arg
);
5917 = build2 (TREE_CODE (*expr_p
), TREE_TYPE (*expr_p
), t
, integer_zero_node
);
5918 SET_EXPR_LOCATION (expr
, loc
);
5924 /* Gimplify a comparison between two aggregate objects of integral scalar
5925 mode as a comparison between the bitwise equivalent scalar values. */
5927 static enum gimplify_status
5928 gimplify_scalar_mode_aggregate_compare (tree
*expr_p
)
5930 location_t loc
= EXPR_LOCATION (*expr_p
);
5931 tree op0
= TREE_OPERAND (*expr_p
, 0);
5932 tree op1
= TREE_OPERAND (*expr_p
, 1);
5934 tree type
= TREE_TYPE (op0
);
5935 tree scalar_type
= lang_hooks
.types
.type_for_mode (TYPE_MODE (type
), 1);
5937 op0
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, scalar_type
, op0
);
5938 op1
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, scalar_type
, op1
);
5941 = fold_build2_loc (loc
, TREE_CODE (*expr_p
), TREE_TYPE (*expr_p
), op0
, op1
);
5946 /* Gimplify an expression sequence. This function gimplifies each
5947 expression and rewrites the original expression with the last
5948 expression of the sequence in GIMPLE form.
5950 PRE_P points to the list where the side effects for all the
5951 expressions in the sequence will be emitted.
5953 WANT_VALUE is true when the result of the last COMPOUND_EXPR is used. */
5955 static enum gimplify_status
5956 gimplify_compound_expr (tree
*expr_p
, gimple_seq
*pre_p
, bool want_value
)
5962 tree
*sub_p
= &TREE_OPERAND (t
, 0);
5964 if (TREE_CODE (*sub_p
) == COMPOUND_EXPR
)
5965 gimplify_compound_expr (sub_p
, pre_p
, false);
5967 gimplify_stmt (sub_p
, pre_p
);
5969 t
= TREE_OPERAND (t
, 1);
5971 while (TREE_CODE (t
) == COMPOUND_EXPR
);
5978 gimplify_stmt (expr_p
, pre_p
);
5983 /* Gimplify a SAVE_EXPR node. EXPR_P points to the expression to
5984 gimplify. After gimplification, EXPR_P will point to a new temporary
5985 that holds the original value of the SAVE_EXPR node.
5987 PRE_P points to the list where side effects that must happen before
5988 *EXPR_P should be stored. */
5990 static enum gimplify_status
5991 gimplify_save_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
5993 enum gimplify_status ret
= GS_ALL_DONE
;
5996 gcc_assert (TREE_CODE (*expr_p
) == SAVE_EXPR
);
5997 val
= TREE_OPERAND (*expr_p
, 0);
5999 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */
6000 if (!SAVE_EXPR_RESOLVED_P (*expr_p
))
6002 /* The operand may be a void-valued expression. It is
6003 being executed only for its side-effects. */
6004 if (TREE_TYPE (val
) == void_type_node
)
6006 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
6007 is_gimple_stmt
, fb_none
);
6011 /* The temporary may not be an SSA name as later abnormal and EH
6012 control flow may invalidate use/def domination. When in SSA
6013 form then assume there are no such issues and SAVE_EXPRs only
6014 appear via GENERIC foldings. */
6015 val
= get_initialized_tmp_var (val
, pre_p
, post_p
,
6016 gimple_in_ssa_p (cfun
));
6018 TREE_OPERAND (*expr_p
, 0) = val
;
6019 SAVE_EXPR_RESOLVED_P (*expr_p
) = 1;
6027 /* Rewrite the ADDR_EXPR node pointed to by EXPR_P
6034 PRE_P points to the list where side effects that must happen before
6035 *EXPR_P should be stored.
6037 POST_P points to the list where side effects that must happen after
6038 *EXPR_P should be stored. */
6040 static enum gimplify_status
6041 gimplify_addr_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
6043 tree expr
= *expr_p
;
6044 tree op0
= TREE_OPERAND (expr
, 0);
6045 enum gimplify_status ret
;
6046 location_t loc
= EXPR_LOCATION (*expr_p
);
6048 switch (TREE_CODE (op0
))
6052 /* Check if we are dealing with an expression of the form '&*ptr'.
6053 While the front end folds away '&*ptr' into 'ptr', these
6054 expressions may be generated internally by the compiler (e.g.,
6055 builtins like __builtin_va_end). */
6056 /* Caution: the silent array decomposition semantics we allow for
6057 ADDR_EXPR means we can't always discard the pair. */
6058 /* Gimplification of the ADDR_EXPR operand may drop
6059 cv-qualification conversions, so make sure we add them if
6062 tree op00
= TREE_OPERAND (op0
, 0);
6063 tree t_expr
= TREE_TYPE (expr
);
6064 tree t_op00
= TREE_TYPE (op00
);
6066 if (!useless_type_conversion_p (t_expr
, t_op00
))
6067 op00
= fold_convert_loc (loc
, TREE_TYPE (expr
), op00
);
6073 case VIEW_CONVERT_EXPR
:
6074 /* Take the address of our operand and then convert it to the type of
6077 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
6078 all clear. The impact of this transformation is even less clear. */
6080 /* If the operand is a useless conversion, look through it. Doing so
6081 guarantees that the ADDR_EXPR and its operand will remain of the
6083 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0
, 0)))
6084 op0
= TREE_OPERAND (op0
, 0);
6086 *expr_p
= fold_convert_loc (loc
, TREE_TYPE (expr
),
6087 build_fold_addr_expr_loc (loc
,
6088 TREE_OPERAND (op0
, 0)));
6093 if (integer_zerop (TREE_OPERAND (op0
, 1)))
6094 goto do_indirect_ref
;
6099 /* If we see a call to a declared builtin or see its address
6100 being taken (we can unify those cases here) then we can mark
6101 the builtin for implicit generation by GCC. */
6102 if (TREE_CODE (op0
) == FUNCTION_DECL
6103 && fndecl_built_in_p (op0
, BUILT_IN_NORMAL
)
6104 && builtin_decl_declared_p (DECL_FUNCTION_CODE (op0
)))
6105 set_builtin_decl_implicit_p (DECL_FUNCTION_CODE (op0
), true);
6107 /* We use fb_either here because the C frontend sometimes takes
6108 the address of a call that returns a struct; see
6109 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make
6110 the implied temporary explicit. */
6112 /* Make the operand addressable. */
6113 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, post_p
,
6114 is_gimple_addressable
, fb_either
);
6115 if (ret
== GS_ERROR
)
6118 /* Then mark it. Beware that it may not be possible to do so directly
6119 if a temporary has been created by the gimplification. */
6120 prepare_gimple_addressable (&TREE_OPERAND (expr
, 0), pre_p
);
6122 op0
= TREE_OPERAND (expr
, 0);
6124 /* For various reasons, the gimplification of the expression
6125 may have made a new INDIRECT_REF. */
6126 if (TREE_CODE (op0
) == INDIRECT_REF
)
6127 goto do_indirect_ref
;
6129 mark_addressable (TREE_OPERAND (expr
, 0));
6131 /* The FEs may end up building ADDR_EXPRs early on a decl with
6132 an incomplete type. Re-build ADDR_EXPRs in canonical form
6134 if (!types_compatible_p (TREE_TYPE (op0
), TREE_TYPE (TREE_TYPE (expr
))))
6135 *expr_p
= build_fold_addr_expr (op0
);
6137 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */
6138 recompute_tree_invariant_for_addr_expr (*expr_p
);
6140 /* If we re-built the ADDR_EXPR add a conversion to the original type
6142 if (!useless_type_conversion_p (TREE_TYPE (expr
), TREE_TYPE (*expr_p
)))
6143 *expr_p
= fold_convert (TREE_TYPE (expr
), *expr_p
);
6151 /* Gimplify the operands of an ASM_EXPR. Input operands should be a gimple
6152 value; output operands should be a gimple lvalue. */
6154 static enum gimplify_status
6155 gimplify_asm_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
6159 const char **oconstraints
;
6162 const char *constraint
;
6163 bool allows_mem
, allows_reg
, is_inout
;
6164 enum gimplify_status ret
, tret
;
6166 vec
<tree
, va_gc
> *inputs
;
6167 vec
<tree
, va_gc
> *outputs
;
6168 vec
<tree
, va_gc
> *clobbers
;
6169 vec
<tree
, va_gc
> *labels
;
6173 noutputs
= list_length (ASM_OUTPUTS (expr
));
6174 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
6182 link_next
= NULL_TREE
;
6183 for (i
= 0, link
= ASM_OUTPUTS (expr
); link
; ++i
, link
= link_next
)
6186 size_t constraint_len
;
6188 link_next
= TREE_CHAIN (link
);
6192 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
6193 constraint_len
= strlen (constraint
);
6194 if (constraint_len
== 0)
6197 ok
= parse_output_constraint (&constraint
, i
, 0, 0,
6198 &allows_mem
, &allows_reg
, &is_inout
);
6205 /* If we can't make copies, we can only accept memory. */
6206 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link
))))
6212 error ("impossible constraint in %<asm%>");
6213 error ("non-memory output %d must stay in memory", i
);
6218 if (!allows_reg
&& allows_mem
)
6219 mark_addressable (TREE_VALUE (link
));
6221 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6222 is_inout
? is_gimple_min_lval
: is_gimple_lvalue
,
6223 fb_lvalue
| fb_mayfail
);
6224 if (tret
== GS_ERROR
)
6226 error ("invalid lvalue in %<asm%> output %d", i
);
6230 /* If the constraint does not allow memory make sure we gimplify
6231 it to a register if it is not already but its base is. This
6232 happens for complex and vector components. */
6235 tree op
= TREE_VALUE (link
);
6236 if (! is_gimple_val (op
)
6237 && is_gimple_reg_type (TREE_TYPE (op
))
6238 && is_gimple_reg (get_base_address (op
)))
6240 tree tem
= create_tmp_reg (TREE_TYPE (op
));
6244 ass
= build2 (MODIFY_EXPR
, TREE_TYPE (tem
),
6245 tem
, unshare_expr (op
));
6246 gimplify_and_add (ass
, pre_p
);
6248 ass
= build2 (MODIFY_EXPR
, TREE_TYPE (tem
), op
, tem
);
6249 gimplify_and_add (ass
, post_p
);
6251 TREE_VALUE (link
) = tem
;
6256 vec_safe_push (outputs
, link
);
6257 TREE_CHAIN (link
) = NULL_TREE
;
6261 /* An input/output operand. To give the optimizers more
6262 flexibility, split it into separate input and output
6265 /* Buffer big enough to format a 32-bit UINT_MAX into. */
6268 /* Turn the in/out constraint into an output constraint. */
6269 char *p
= xstrdup (constraint
);
6271 TREE_VALUE (TREE_PURPOSE (link
)) = build_string (constraint_len
, p
);
6273 /* And add a matching input constraint. */
6276 sprintf (buf
, "%u", i
);
6278 /* If there are multiple alternatives in the constraint,
6279 handle each of them individually. Those that allow register
6280 will be replaced with operand number, the others will stay
6282 if (strchr (p
, ',') != NULL
)
6284 size_t len
= 0, buflen
= strlen (buf
);
6285 char *beg
, *end
, *str
, *dst
;
6289 end
= strchr (beg
, ',');
6291 end
= strchr (beg
, '\0');
6292 if ((size_t) (end
- beg
) < buflen
)
6295 len
+= end
- beg
+ 1;
6302 str
= (char *) alloca (len
);
6303 for (beg
= p
+ 1, dst
= str
;;)
6306 bool mem_p
, reg_p
, inout_p
;
6308 end
= strchr (beg
, ',');
6313 parse_output_constraint (&tem
, i
, 0, 0,
6314 &mem_p
, ®_p
, &inout_p
);
6319 memcpy (dst
, buf
, buflen
);
6328 memcpy (dst
, beg
, len
);
6337 input
= build_string (dst
- str
, str
);
6340 input
= build_string (strlen (buf
), buf
);
6343 input
= build_string (constraint_len
- 1, constraint
+ 1);
6347 input
= build_tree_list (build_tree_list (NULL_TREE
, input
),
6348 unshare_expr (TREE_VALUE (link
)));
6349 ASM_INPUTS (expr
) = chainon (ASM_INPUTS (expr
), input
);
6353 link_next
= NULL_TREE
;
6354 for (link
= ASM_INPUTS (expr
); link
; ++i
, link
= link_next
)
6356 link_next
= TREE_CHAIN (link
);
6357 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
6358 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
6359 oconstraints
, &allows_mem
, &allows_reg
);
6361 /* If we can't make copies, we can only accept memory. */
6362 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link
))))
6368 error ("impossible constraint in %<asm%>");
6369 error ("non-memory input %d must stay in memory", i
);
6374 /* If the operand is a memory input, it should be an lvalue. */
6375 if (!allows_reg
&& allows_mem
)
6377 tree inputv
= TREE_VALUE (link
);
6378 STRIP_NOPS (inputv
);
6379 if (TREE_CODE (inputv
) == PREDECREMENT_EXPR
6380 || TREE_CODE (inputv
) == PREINCREMENT_EXPR
6381 || TREE_CODE (inputv
) == POSTDECREMENT_EXPR
6382 || TREE_CODE (inputv
) == POSTINCREMENT_EXPR
6383 || TREE_CODE (inputv
) == MODIFY_EXPR
)
6384 TREE_VALUE (link
) = error_mark_node
;
6385 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6386 is_gimple_lvalue
, fb_lvalue
| fb_mayfail
);
6387 if (tret
!= GS_ERROR
)
6389 /* Unlike output operands, memory inputs are not guaranteed
6390 to be lvalues by the FE, and while the expressions are
6391 marked addressable there, if it is e.g. a statement
6392 expression, temporaries in it might not end up being
6393 addressable. They might be already used in the IL and thus
6394 it is too late to make them addressable now though. */
6395 tree x
= TREE_VALUE (link
);
6396 while (handled_component_p (x
))
6397 x
= TREE_OPERAND (x
, 0);
6398 if (TREE_CODE (x
) == MEM_REF
6399 && TREE_CODE (TREE_OPERAND (x
, 0)) == ADDR_EXPR
)
6400 x
= TREE_OPERAND (TREE_OPERAND (x
, 0), 0);
6402 || TREE_CODE (x
) == PARM_DECL
6403 || TREE_CODE (x
) == RESULT_DECL
)
6404 && !TREE_ADDRESSABLE (x
)
6405 && is_gimple_reg (x
))
6407 warning_at (EXPR_LOC_OR_LOC (TREE_VALUE (link
),
6409 "memory input %d is not directly addressable",
6411 prepare_gimple_addressable (&TREE_VALUE (link
), pre_p
);
6414 mark_addressable (TREE_VALUE (link
));
6415 if (tret
== GS_ERROR
)
6417 error_at (EXPR_LOC_OR_LOC (TREE_VALUE (link
), input_location
),
6418 "memory input %d is not directly addressable", i
);
6424 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6425 is_gimple_asm_val
, fb_rvalue
);
6426 if (tret
== GS_ERROR
)
6430 TREE_CHAIN (link
) = NULL_TREE
;
6431 vec_safe_push (inputs
, link
);
6434 link_next
= NULL_TREE
;
6435 for (link
= ASM_CLOBBERS (expr
); link
; ++i
, link
= link_next
)
6437 link_next
= TREE_CHAIN (link
);
6438 TREE_CHAIN (link
) = NULL_TREE
;
6439 vec_safe_push (clobbers
, link
);
6442 link_next
= NULL_TREE
;
6443 for (link
= ASM_LABELS (expr
); link
; ++i
, link
= link_next
)
6445 link_next
= TREE_CHAIN (link
);
6446 TREE_CHAIN (link
) = NULL_TREE
;
6447 vec_safe_push (labels
, link
);
6450 /* Do not add ASMs with errors to the gimple IL stream. */
6451 if (ret
!= GS_ERROR
)
6453 stmt
= gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr
)),
6454 inputs
, outputs
, clobbers
, labels
);
6456 gimple_asm_set_volatile (stmt
, ASM_VOLATILE_P (expr
) || noutputs
== 0);
6457 gimple_asm_set_input (stmt
, ASM_INPUT_P (expr
));
6458 gimple_asm_set_inline (stmt
, ASM_INLINE_P (expr
));
6460 gimplify_seq_add_stmt (pre_p
, stmt
);
6466 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding
6467 GIMPLE_WITH_CLEANUP_EXPRs to the prequeue as we encounter cleanups while
6468 gimplifying the body, and converting them to TRY_FINALLY_EXPRs when we
6469 return to this function.
6471 FIXME should we complexify the prequeue handling instead? Or use flags
6472 for all the cleanups and let the optimizer tighten them up? The current
6473 code seems pretty fragile; it will break on a cleanup within any
6474 non-conditional nesting. But any such nesting would be broken, anyway;
6475 we can't write a TRY_FINALLY_EXPR that starts inside a nesting construct
6476 and continues out of it. We can do that at the RTL level, though, so
6477 having an optimizer to tighten up try/finally regions would be a Good
6480 static enum gimplify_status
6481 gimplify_cleanup_point_expr (tree
*expr_p
, gimple_seq
*pre_p
)
6483 gimple_stmt_iterator iter
;
6484 gimple_seq body_sequence
= NULL
;
6486 tree temp
= voidify_wrapper_expr (*expr_p
, NULL
);
6488 /* We only care about the number of conditions between the innermost
6489 CLEANUP_POINT_EXPR and the cleanup. So save and reset the count and
6490 any cleanups collected outside the CLEANUP_POINT_EXPR. */
6491 int old_conds
= gimplify_ctxp
->conditions
;
6492 gimple_seq old_cleanups
= gimplify_ctxp
->conditional_cleanups
;
6493 bool old_in_cleanup_point_expr
= gimplify_ctxp
->in_cleanup_point_expr
;
6494 gimplify_ctxp
->conditions
= 0;
6495 gimplify_ctxp
->conditional_cleanups
= NULL
;
6496 gimplify_ctxp
->in_cleanup_point_expr
= true;
6498 gimplify_stmt (&TREE_OPERAND (*expr_p
, 0), &body_sequence
);
6500 gimplify_ctxp
->conditions
= old_conds
;
6501 gimplify_ctxp
->conditional_cleanups
= old_cleanups
;
6502 gimplify_ctxp
->in_cleanup_point_expr
= old_in_cleanup_point_expr
;
6504 for (iter
= gsi_start (body_sequence
); !gsi_end_p (iter
); )
6506 gimple
*wce
= gsi_stmt (iter
);
6508 if (gimple_code (wce
) == GIMPLE_WITH_CLEANUP_EXPR
)
6510 if (gsi_one_before_end_p (iter
))
6512 /* Note that gsi_insert_seq_before and gsi_remove do not
6513 scan operands, unlike some other sequence mutators. */
6514 if (!gimple_wce_cleanup_eh_only (wce
))
6515 gsi_insert_seq_before_without_update (&iter
,
6516 gimple_wce_cleanup (wce
),
6518 gsi_remove (&iter
, true);
6525 enum gimple_try_flags kind
;
6527 if (gimple_wce_cleanup_eh_only (wce
))
6528 kind
= GIMPLE_TRY_CATCH
;
6530 kind
= GIMPLE_TRY_FINALLY
;
6531 seq
= gsi_split_seq_after (iter
);
6533 gtry
= gimple_build_try (seq
, gimple_wce_cleanup (wce
), kind
);
6534 /* Do not use gsi_replace here, as it may scan operands.
6535 We want to do a simple structural modification only. */
6536 gsi_set_stmt (&iter
, gtry
);
6537 iter
= gsi_start (gtry
->eval
);
6544 gimplify_seq_add_seq (pre_p
, body_sequence
);
6557 /* Insert a cleanup marker for gimplify_cleanup_point_expr. CLEANUP
6558 is the cleanup action required. EH_ONLY is true if the cleanup should
6559 only be executed if an exception is thrown, not on normal exit.
6560 If FORCE_UNCOND is true perform the cleanup unconditionally; this is
6561 only valid for clobbers. */
6564 gimple_push_cleanup (tree var
, tree cleanup
, bool eh_only
, gimple_seq
*pre_p
,
6565 bool force_uncond
= false)
6568 gimple_seq cleanup_stmts
= NULL
;
6570 /* Errors can result in improperly nested cleanups. Which results in
6571 confusion when trying to resolve the GIMPLE_WITH_CLEANUP_EXPR. */
6575 if (gimple_conditional_context ())
6577 /* If we're in a conditional context, this is more complex. We only
6578 want to run the cleanup if we actually ran the initialization that
6579 necessitates it, but we want to run it after the end of the
6580 conditional context. So we wrap the try/finally around the
6581 condition and use a flag to determine whether or not to actually
6582 run the destructor. Thus
6586 becomes (approximately)
6590 if (test) { A::A(temp); flag = 1; val = f(temp); }
6593 if (flag) A::~A(temp);
6599 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6600 wce
= gimple_build_wce (cleanup_stmts
);
6601 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, wce
);
6605 tree flag
= create_tmp_var (boolean_type_node
, "cleanup");
6606 gassign
*ffalse
= gimple_build_assign (flag
, boolean_false_node
);
6607 gassign
*ftrue
= gimple_build_assign (flag
, boolean_true_node
);
6609 cleanup
= build3 (COND_EXPR
, void_type_node
, flag
, cleanup
, NULL
);
6610 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6611 wce
= gimple_build_wce (cleanup_stmts
);
6613 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, ffalse
);
6614 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, wce
);
6615 gimplify_seq_add_stmt (pre_p
, ftrue
);
6617 /* Because of this manipulation, and the EH edges that jump
6618 threading cannot redirect, the temporary (VAR) will appear
6619 to be used uninitialized. Don't warn. */
6620 TREE_NO_WARNING (var
) = 1;
6625 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6626 wce
= gimple_build_wce (cleanup_stmts
);
6627 gimple_wce_set_cleanup_eh_only (wce
, eh_only
);
6628 gimplify_seq_add_stmt (pre_p
, wce
);
6632 /* Gimplify a TARGET_EXPR which doesn't appear on the rhs of an INIT_EXPR. */
6634 static enum gimplify_status
6635 gimplify_target_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
6637 tree targ
= *expr_p
;
6638 tree temp
= TARGET_EXPR_SLOT (targ
);
6639 tree init
= TARGET_EXPR_INITIAL (targ
);
6640 enum gimplify_status ret
;
6642 bool unpoison_empty_seq
= false;
6643 gimple_stmt_iterator unpoison_it
;
6647 tree cleanup
= NULL_TREE
;
6649 /* TARGET_EXPR temps aren't part of the enclosing block, so add it
6650 to the temps list. Handle also variable length TARGET_EXPRs. */
6651 if (TREE_CODE (DECL_SIZE (temp
)) != INTEGER_CST
)
6653 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp
)))
6654 gimplify_type_sizes (TREE_TYPE (temp
), pre_p
);
6655 gimplify_vla_decl (temp
, pre_p
);
6659 /* Save location where we need to place unpoisoning. It's possible
6660 that a variable will be converted to needs_to_live_in_memory. */
6661 unpoison_it
= gsi_last (*pre_p
);
6662 unpoison_empty_seq
= gsi_end_p (unpoison_it
);
6664 gimple_add_tmp_var (temp
);
6667 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
6668 expression is supposed to initialize the slot. */
6669 if (VOID_TYPE_P (TREE_TYPE (init
)))
6670 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
6673 tree init_expr
= build2 (INIT_EXPR
, void_type_node
, temp
, init
);
6675 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
6677 ggc_free (init_expr
);
6679 if (ret
== GS_ERROR
)
6681 /* PR c++/28266 Make sure this is expanded only once. */
6682 TARGET_EXPR_INITIAL (targ
) = NULL_TREE
;
6686 gimplify_and_add (init
, pre_p
);
6688 /* If needed, push the cleanup for the temp. */
6689 if (TARGET_EXPR_CLEANUP (targ
))
6691 if (CLEANUP_EH_ONLY (targ
))
6692 gimple_push_cleanup (temp
, TARGET_EXPR_CLEANUP (targ
),
6693 CLEANUP_EH_ONLY (targ
), pre_p
);
6695 cleanup
= TARGET_EXPR_CLEANUP (targ
);
6698 /* Add a clobber for the temporary going out of scope, like
6699 gimplify_bind_expr. */
6700 if (gimplify_ctxp
->in_cleanup_point_expr
6701 && needs_to_live_in_memory (temp
))
6703 if (flag_stack_reuse
== SR_ALL
)
6705 tree clobber
= build_clobber (TREE_TYPE (temp
));
6706 clobber
= build2 (MODIFY_EXPR
, TREE_TYPE (temp
), temp
, clobber
);
6707 gimple_push_cleanup (temp
, clobber
, false, pre_p
, true);
6709 if (asan_poisoned_variables
6710 && DECL_ALIGN (temp
) <= MAX_SUPPORTED_STACK_ALIGNMENT
6711 && !TREE_STATIC (temp
)
6712 && dbg_cnt (asan_use_after_scope
)
6713 && !gimplify_omp_ctxp
)
6715 tree asan_cleanup
= build_asan_poison_call_expr (temp
);
6718 if (unpoison_empty_seq
)
6719 unpoison_it
= gsi_start (*pre_p
);
6721 asan_poison_variable (temp
, false, &unpoison_it
,
6722 unpoison_empty_seq
);
6723 gimple_push_cleanup (temp
, asan_cleanup
, false, pre_p
);
6728 gimple_push_cleanup (temp
, cleanup
, false, pre_p
);
6730 /* Only expand this once. */
6731 TREE_OPERAND (targ
, 3) = init
;
6732 TARGET_EXPR_INITIAL (targ
) = NULL_TREE
;
6735 /* We should have expanded this before. */
6736 gcc_assert (DECL_SEEN_IN_BIND_EXPR_P (temp
));
6742 /* Gimplification of expression trees. */
6744 /* Gimplify an expression which appears at statement context. The
6745 corresponding GIMPLE statements are added to *SEQ_P. If *SEQ_P is
6746 NULL, a new sequence is allocated.
6748 Return true if we actually added a statement to the queue. */
6751 gimplify_stmt (tree
*stmt_p
, gimple_seq
*seq_p
)
6753 gimple_seq_node last
;
6755 last
= gimple_seq_last (*seq_p
);
6756 gimplify_expr (stmt_p
, seq_p
, NULL
, is_gimple_stmt
, fb_none
);
6757 return last
!= gimple_seq_last (*seq_p
);
6760 /* Add FIRSTPRIVATE entries for DECL in the OpenMP the surrounding parallels
6761 to CTX. If entries already exist, force them to be some flavor of private.
6762 If there is no enclosing parallel, do nothing. */
6765 omp_firstprivatize_variable (struct gimplify_omp_ctx
*ctx
, tree decl
)
6769 if (decl
== NULL
|| !DECL_P (decl
) || ctx
->region_type
== ORT_NONE
)
6774 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
6777 if (n
->value
& GOVD_SHARED
)
6778 n
->value
= GOVD_FIRSTPRIVATE
| (n
->value
& GOVD_SEEN
);
6779 else if (n
->value
& GOVD_MAP
)
6780 n
->value
|= GOVD_MAP_TO_ONLY
;
6784 else if ((ctx
->region_type
& ORT_TARGET
) != 0)
6786 if (ctx
->defaultmap
[GDMK_SCALAR
] & GOVD_FIRSTPRIVATE
)
6787 omp_add_variable (ctx
, decl
, GOVD_FIRSTPRIVATE
);
6789 omp_add_variable (ctx
, decl
, GOVD_MAP
| GOVD_MAP_TO_ONLY
);
6791 else if (ctx
->region_type
!= ORT_WORKSHARE
6792 && ctx
->region_type
!= ORT_TASKGROUP
6793 && ctx
->region_type
!= ORT_SIMD
6794 && ctx
->region_type
!= ORT_ACC
6795 && !(ctx
->region_type
& ORT_TARGET_DATA
))
6796 omp_add_variable (ctx
, decl
, GOVD_FIRSTPRIVATE
);
6798 ctx
= ctx
->outer_context
;
6803 /* Similarly for each of the type sizes of TYPE. */
6806 omp_firstprivatize_type_sizes (struct gimplify_omp_ctx
*ctx
, tree type
)
6808 if (type
== NULL
|| type
== error_mark_node
)
6810 type
= TYPE_MAIN_VARIANT (type
);
6812 if (ctx
->privatized_types
->add (type
))
6815 switch (TREE_CODE (type
))
6821 case FIXED_POINT_TYPE
:
6822 omp_firstprivatize_variable (ctx
, TYPE_MIN_VALUE (type
));
6823 omp_firstprivatize_variable (ctx
, TYPE_MAX_VALUE (type
));
6827 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (type
));
6828 omp_firstprivatize_type_sizes (ctx
, TYPE_DOMAIN (type
));
6833 case QUAL_UNION_TYPE
:
6836 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
6837 if (TREE_CODE (field
) == FIELD_DECL
)
6839 omp_firstprivatize_variable (ctx
, DECL_FIELD_OFFSET (field
));
6840 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (field
));
6846 case REFERENCE_TYPE
:
6847 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (type
));
6854 omp_firstprivatize_variable (ctx
, TYPE_SIZE (type
));
6855 omp_firstprivatize_variable (ctx
, TYPE_SIZE_UNIT (type
));
6856 lang_hooks
.types
.omp_firstprivatize_type_sizes (ctx
, type
);
6859 /* Add an entry for DECL in the OMP context CTX with FLAGS. */
6862 omp_add_variable (struct gimplify_omp_ctx
*ctx
, tree decl
, unsigned int flags
)
6865 unsigned int nflags
;
6868 if (error_operand_p (decl
) || ctx
->region_type
== ORT_NONE
)
6871 /* Never elide decls whose type has TREE_ADDRESSABLE set. This means
6872 there are constructors involved somewhere. Exception is a shared clause,
6873 there is nothing privatized in that case. */
6874 if ((flags
& GOVD_SHARED
) == 0
6875 && (TREE_ADDRESSABLE (TREE_TYPE (decl
))
6876 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
))))
6879 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
6880 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
6882 /* We shouldn't be re-adding the decl with the same data
6884 gcc_assert ((n
->value
& GOVD_DATA_SHARE_CLASS
& flags
) == 0);
6885 nflags
= n
->value
| flags
;
6886 /* The only combination of data sharing classes we should see is
6887 FIRSTPRIVATE and LASTPRIVATE. However, OpenACC permits
6888 reduction variables to be used in data sharing clauses. */
6889 gcc_assert ((ctx
->region_type
& ORT_ACC
) != 0
6890 || ((nflags
& GOVD_DATA_SHARE_CLASS
)
6891 == (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
))
6892 || (flags
& GOVD_DATA_SHARE_CLASS
) == 0);
6897 /* When adding a variable-sized variable, we have to handle all sorts
6898 of additional bits of data: the pointer replacement variable, and
6899 the parameters of the type. */
6900 if (DECL_SIZE (decl
) && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
6902 /* Add the pointer replacement variable as PRIVATE if the variable
6903 replacement is private, else FIRSTPRIVATE since we'll need the
6904 address of the original variable either for SHARED, or for the
6905 copy into or out of the context. */
6906 if (!(flags
& GOVD_LOCAL
) && ctx
->region_type
!= ORT_TASKGROUP
)
6908 if (flags
& GOVD_MAP
)
6909 nflags
= GOVD_MAP
| GOVD_MAP_TO_ONLY
| GOVD_EXPLICIT
;
6910 else if (flags
& GOVD_PRIVATE
)
6911 nflags
= GOVD_PRIVATE
;
6912 else if ((ctx
->region_type
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0
6913 && (flags
& GOVD_FIRSTPRIVATE
))
6914 nflags
= GOVD_PRIVATE
| GOVD_EXPLICIT
;
6916 nflags
= GOVD_FIRSTPRIVATE
;
6917 nflags
|= flags
& GOVD_SEEN
;
6918 t
= DECL_VALUE_EXPR (decl
);
6919 gcc_assert (TREE_CODE (t
) == INDIRECT_REF
);
6920 t
= TREE_OPERAND (t
, 0);
6921 gcc_assert (DECL_P (t
));
6922 omp_add_variable (ctx
, t
, nflags
);
6925 /* Add all of the variable and type parameters (which should have
6926 been gimplified to a formal temporary) as FIRSTPRIVATE. */
6927 omp_firstprivatize_variable (ctx
, DECL_SIZE_UNIT (decl
));
6928 omp_firstprivatize_variable (ctx
, DECL_SIZE (decl
));
6929 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (decl
));
6931 /* The variable-sized variable itself is never SHARED, only some form
6932 of PRIVATE. The sharing would take place via the pointer variable
6933 which we remapped above. */
6934 if (flags
& GOVD_SHARED
)
6935 flags
= GOVD_SHARED
| GOVD_DEBUG_PRIVATE
6936 | (flags
& (GOVD_SEEN
| GOVD_EXPLICIT
));
6938 /* We're going to make use of the TYPE_SIZE_UNIT at least in the
6939 alloca statement we generate for the variable, so make sure it
6940 is available. This isn't automatically needed for the SHARED
6941 case, since we won't be allocating local storage then.
6942 For local variables TYPE_SIZE_UNIT might not be gimplified yet,
6943 in this case omp_notice_variable will be called later
6944 on when it is gimplified. */
6945 else if (! (flags
& (GOVD_LOCAL
| GOVD_MAP
))
6946 && DECL_P (TYPE_SIZE_UNIT (TREE_TYPE (decl
))))
6947 omp_notice_variable (ctx
, TYPE_SIZE_UNIT (TREE_TYPE (decl
)), true);
6949 else if ((flags
& (GOVD_MAP
| GOVD_LOCAL
)) == 0
6950 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
6952 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (decl
));
6954 /* Similar to the direct variable sized case above, we'll need the
6955 size of references being privatized. */
6956 if ((flags
& GOVD_SHARED
) == 0)
6958 t
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)));
6960 omp_notice_variable (ctx
, t
, true);
6967 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl
, flags
);
6969 /* For reductions clauses in OpenACC loop directives, by default create a
6970 copy clause on the enclosing parallel construct for carrying back the
6972 if (ctx
->region_type
== ORT_ACC
&& (flags
& GOVD_REDUCTION
))
6974 struct gimplify_omp_ctx
*outer_ctx
= ctx
->outer_context
;
6977 n
= splay_tree_lookup (outer_ctx
->variables
, (splay_tree_key
)decl
);
6980 /* Ignore local variables and explicitly declared clauses. */
6981 if (n
->value
& (GOVD_LOCAL
| GOVD_EXPLICIT
))
6983 else if (outer_ctx
->region_type
== ORT_ACC_KERNELS
)
6985 /* According to the OpenACC spec, such a reduction variable
6986 should already have a copy map on a kernels construct,
6987 verify that here. */
6988 gcc_assert (!(n
->value
& GOVD_FIRSTPRIVATE
)
6989 && (n
->value
& GOVD_MAP
));
6991 else if (outer_ctx
->region_type
== ORT_ACC_PARALLEL
)
6993 /* Remove firstprivate and make it a copy map. */
6994 n
->value
&= ~GOVD_FIRSTPRIVATE
;
6995 n
->value
|= GOVD_MAP
;
6998 else if (outer_ctx
->region_type
== ORT_ACC_PARALLEL
)
7000 splay_tree_insert (outer_ctx
->variables
, (splay_tree_key
)decl
,
7001 GOVD_MAP
| GOVD_SEEN
);
7004 outer_ctx
= outer_ctx
->outer_context
;
7009 /* Notice a threadprivate variable DECL used in OMP context CTX.
7010 This just prints out diagnostics about threadprivate variable uses
7011 in untied tasks. If DECL2 is non-NULL, prevent this warning
7012 on that variable. */
7015 omp_notice_threadprivate_variable (struct gimplify_omp_ctx
*ctx
, tree decl
,
7019 struct gimplify_omp_ctx
*octx
;
7021 for (octx
= ctx
; octx
; octx
= octx
->outer_context
)
7022 if ((octx
->region_type
& ORT_TARGET
) != 0)
7024 n
= splay_tree_lookup (octx
->variables
, (splay_tree_key
)decl
);
7027 error ("threadprivate variable %qE used in target region",
7029 error_at (octx
->location
, "enclosing target region");
7030 splay_tree_insert (octx
->variables
, (splay_tree_key
)decl
, 0);
7033 splay_tree_insert (octx
->variables
, (splay_tree_key
)decl2
, 0);
7036 if (ctx
->region_type
!= ORT_UNTIED_TASK
)
7038 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7041 error ("threadprivate variable %qE used in untied task",
7043 error_at (ctx
->location
, "enclosing task");
7044 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl
, 0);
7047 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl2
, 0);
7051 /* Return true if global var DECL is device resident. */
7054 device_resident_p (tree decl
)
7056 tree attr
= lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (decl
));
7061 for (tree t
= TREE_VALUE (attr
); t
; t
= TREE_PURPOSE (t
))
7063 tree c
= TREE_VALUE (t
);
7064 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DEVICE_RESIDENT
)
7071 /* Return true if DECL has an ACC DECLARE attribute. */
7074 is_oacc_declared (tree decl
)
7076 tree t
= TREE_CODE (decl
) == MEM_REF
? TREE_OPERAND (decl
, 0) : decl
;
7077 tree declared
= lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (t
));
7078 return declared
!= NULL_TREE
;
7081 /* Determine outer default flags for DECL mentioned in an OMP region
7082 but not declared in an enclosing clause.
7084 ??? Some compiler-generated variables (like SAVE_EXPRs) could be
7085 remapped firstprivate instead of shared. To some extent this is
7086 addressed in omp_firstprivatize_type_sizes, but not
7090 omp_default_clause (struct gimplify_omp_ctx
*ctx
, tree decl
,
7091 bool in_code
, unsigned flags
)
7093 enum omp_clause_default_kind default_kind
= ctx
->default_kind
;
7094 enum omp_clause_default_kind kind
;
7096 kind
= lang_hooks
.decls
.omp_predetermined_sharing (decl
);
7097 if (kind
!= OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7098 default_kind
= kind
;
7100 switch (default_kind
)
7102 case OMP_CLAUSE_DEFAULT_NONE
:
7106 if (ctx
->region_type
& ORT_PARALLEL
)
7108 else if ((ctx
->region_type
& ORT_TASKLOOP
) == ORT_TASKLOOP
)
7110 else if (ctx
->region_type
& ORT_TASK
)
7112 else if (ctx
->region_type
& ORT_TEAMS
)
7117 error ("%qE not specified in enclosing %qs",
7118 DECL_NAME (lang_hooks
.decls
.omp_report_decl (decl
)), rtype
);
7119 error_at (ctx
->location
, "enclosing %qs", rtype
);
7122 case OMP_CLAUSE_DEFAULT_SHARED
:
7123 flags
|= GOVD_SHARED
;
7125 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7126 flags
|= GOVD_PRIVATE
;
7128 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE
:
7129 flags
|= GOVD_FIRSTPRIVATE
;
7131 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7132 /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */
7133 gcc_assert ((ctx
->region_type
& ORT_TASK
) != 0);
7134 if (struct gimplify_omp_ctx
*octx
= ctx
->outer_context
)
7136 omp_notice_variable (octx
, decl
, in_code
);
7137 for (; octx
; octx
= octx
->outer_context
)
7141 n2
= splay_tree_lookup (octx
->variables
, (splay_tree_key
) decl
);
7142 if ((octx
->region_type
& (ORT_TARGET_DATA
| ORT_TARGET
)) != 0
7143 && (n2
== NULL
|| (n2
->value
& GOVD_DATA_SHARE_CLASS
) == 0))
7145 if (n2
&& (n2
->value
& GOVD_DATA_SHARE_CLASS
) != GOVD_SHARED
)
7147 flags
|= GOVD_FIRSTPRIVATE
;
7150 if ((octx
->region_type
& (ORT_PARALLEL
| ORT_TEAMS
)) != 0)
7152 flags
|= GOVD_SHARED
;
7158 if (TREE_CODE (decl
) == PARM_DECL
7159 || (!is_global_var (decl
)
7160 && DECL_CONTEXT (decl
) == current_function_decl
))
7161 flags
|= GOVD_FIRSTPRIVATE
;
7163 flags
|= GOVD_SHARED
;
7175 /* Determine outer default flags for DECL mentioned in an OACC region
7176 but not declared in an enclosing clause. */
7179 oacc_default_clause (struct gimplify_omp_ctx
*ctx
, tree decl
, unsigned flags
)
7182 bool on_device
= false;
7183 bool declared
= is_oacc_declared (decl
);
7184 tree type
= TREE_TYPE (decl
);
7186 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7187 type
= TREE_TYPE (type
);
7189 if ((ctx
->region_type
& (ORT_ACC_PARALLEL
| ORT_ACC_KERNELS
)) != 0
7190 && is_global_var (decl
)
7191 && device_resident_p (decl
))
7194 flags
|= GOVD_MAP_TO_ONLY
;
7197 switch (ctx
->region_type
)
7199 case ORT_ACC_KERNELS
:
7202 if (AGGREGATE_TYPE_P (type
))
7204 /* Aggregates default to 'present_or_copy', or 'present'. */
7205 if (ctx
->default_kind
!= OMP_CLAUSE_DEFAULT_PRESENT
)
7208 flags
|= GOVD_MAP
| GOVD_MAP_FORCE_PRESENT
;
7211 /* Scalars default to 'copy'. */
7212 flags
|= GOVD_MAP
| GOVD_MAP_FORCE
;
7216 case ORT_ACC_PARALLEL
:
7219 if (on_device
|| declared
)
7221 else if (AGGREGATE_TYPE_P (type
))
7223 /* Aggregates default to 'present_or_copy', or 'present'. */
7224 if (ctx
->default_kind
!= OMP_CLAUSE_DEFAULT_PRESENT
)
7227 flags
|= GOVD_MAP
| GOVD_MAP_FORCE_PRESENT
;
7230 /* Scalars default to 'firstprivate'. */
7231 flags
|= GOVD_FIRSTPRIVATE
;
7239 if (DECL_ARTIFICIAL (decl
))
7240 ; /* We can get compiler-generated decls, and should not complain
7242 else if (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_NONE
)
7244 error ("%qE not specified in enclosing OpenACC %qs construct",
7245 DECL_NAME (lang_hooks
.decls
.omp_report_decl (decl
)), rkind
);
7246 inform (ctx
->location
, "enclosing OpenACC %qs construct", rkind
);
7248 else if (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_PRESENT
)
7249 ; /* Handled above. */
7251 gcc_checking_assert (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_SHARED
);
7256 /* Record the fact that DECL was used within the OMP context CTX.
7257 IN_CODE is true when real code uses DECL, and false when we should
7258 merely emit default(none) errors. Return true if DECL is going to
7259 be remapped and thus DECL shouldn't be gimplified into its
7260 DECL_VALUE_EXPR (if any). */
7263 omp_notice_variable (struct gimplify_omp_ctx
*ctx
, tree decl
, bool in_code
)
7266 unsigned flags
= in_code
? GOVD_SEEN
: 0;
7267 bool ret
= false, shared
;
7269 if (error_operand_p (decl
))
7272 if (ctx
->region_type
== ORT_NONE
)
7273 return lang_hooks
.decls
.omp_disregard_value_expr (decl
, false);
7275 if (is_global_var (decl
))
7277 /* Threadprivate variables are predetermined. */
7278 if (DECL_THREAD_LOCAL_P (decl
))
7279 return omp_notice_threadprivate_variable (ctx
, decl
, NULL_TREE
);
7281 if (DECL_HAS_VALUE_EXPR_P (decl
))
7283 tree value
= get_base_address (DECL_VALUE_EXPR (decl
));
7285 if (value
&& DECL_P (value
) && DECL_THREAD_LOCAL_P (value
))
7286 return omp_notice_threadprivate_variable (ctx
, decl
, value
);
7289 if (gimplify_omp_ctxp
->outer_context
== NULL
7291 && oacc_get_fn_attrib (current_function_decl
))
7293 location_t loc
= DECL_SOURCE_LOCATION (decl
);
7295 if (lookup_attribute ("omp declare target link",
7296 DECL_ATTRIBUTES (decl
)))
7299 "%qE with %<link%> clause used in %<routine%> function",
7303 else if (!lookup_attribute ("omp declare target",
7304 DECL_ATTRIBUTES (decl
)))
7307 "%qE requires a %<declare%> directive for use "
7308 "in a %<routine%> function", DECL_NAME (decl
));
7314 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7315 if ((ctx
->region_type
& ORT_TARGET
) != 0)
7317 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, true);
7320 unsigned nflags
= flags
;
7321 if ((ctx
->region_type
& ORT_ACC
) == 0)
7323 bool is_declare_target
= false;
7324 if (is_global_var (decl
)
7325 && varpool_node::get_create (decl
)->offloadable
)
7327 struct gimplify_omp_ctx
*octx
;
7328 for (octx
= ctx
->outer_context
;
7329 octx
; octx
= octx
->outer_context
)
7331 n
= splay_tree_lookup (octx
->variables
,
7332 (splay_tree_key
)decl
);
7334 && (n
->value
& GOVD_DATA_SHARE_CLASS
) != GOVD_SHARED
7335 && (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
7338 is_declare_target
= octx
== NULL
;
7340 if (!is_declare_target
)
7343 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
7344 || (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
7345 && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl
)))
7347 gdmk
= GDMK_POINTER
;
7348 else if (lang_hooks
.decls
.omp_scalar_p (decl
))
7351 gdmk
= GDMK_AGGREGATE
;
7352 if (ctx
->defaultmap
[gdmk
] == 0)
7354 tree d
= lang_hooks
.decls
.omp_report_decl (decl
);
7355 error ("%qE not specified in enclosing %<target%>",
7357 error_at (ctx
->location
, "enclosing %<target%>");
7359 else if (ctx
->defaultmap
[gdmk
]
7360 & (GOVD_MAP_0LEN_ARRAY
| GOVD_FIRSTPRIVATE
))
7361 nflags
|= ctx
->defaultmap
[gdmk
];
7364 gcc_assert (ctx
->defaultmap
[gdmk
] & GOVD_MAP
);
7365 nflags
|= ctx
->defaultmap
[gdmk
] & ~GOVD_MAP
;
7370 struct gimplify_omp_ctx
*octx
= ctx
->outer_context
;
7371 if ((ctx
->region_type
& ORT_ACC
) && octx
)
7373 /* Look in outer OpenACC contexts, to see if there's a
7374 data attribute for this variable. */
7375 omp_notice_variable (octx
, decl
, in_code
);
7377 for (; octx
; octx
= octx
->outer_context
)
7379 if (!(octx
->region_type
& (ORT_TARGET_DATA
| ORT_TARGET
)))
7382 = splay_tree_lookup (octx
->variables
,
7383 (splay_tree_key
) decl
);
7386 if (octx
->region_type
== ORT_ACC_HOST_DATA
)
7387 error ("variable %qE declared in enclosing "
7388 "%<host_data%> region", DECL_NAME (decl
));
7390 if (octx
->region_type
== ORT_ACC_DATA
7391 && (n2
->value
& GOVD_MAP_0LEN_ARRAY
))
7392 nflags
|= GOVD_MAP_0LEN_ARRAY
;
7398 if ((nflags
& ~(GOVD_MAP_TO_ONLY
| GOVD_MAP_FROM_ONLY
7399 | GOVD_MAP_ALLOC_ONLY
)) == flags
)
7401 tree type
= TREE_TYPE (decl
);
7403 if (gimplify_omp_ctxp
->target_firstprivatize_array_bases
7404 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7405 type
= TREE_TYPE (type
);
7406 if (!lang_hooks
.types
.omp_mappable_type (type
))
7408 error ("%qD referenced in target region does not have "
7409 "a mappable type", decl
);
7410 nflags
|= GOVD_MAP
| GOVD_EXPLICIT
;
7414 if ((ctx
->region_type
& ORT_ACC
) != 0)
7415 nflags
= oacc_default_clause (ctx
, decl
, flags
);
7421 omp_add_variable (ctx
, decl
, nflags
);
7425 /* If nothing changed, there's nothing left to do. */
7426 if ((n
->value
& flags
) == flags
)
7436 if (ctx
->region_type
== ORT_WORKSHARE
7437 || ctx
->region_type
== ORT_TASKGROUP
7438 || ctx
->region_type
== ORT_SIMD
7439 || ctx
->region_type
== ORT_ACC
7440 || (ctx
->region_type
& ORT_TARGET_DATA
) != 0)
7443 flags
= omp_default_clause (ctx
, decl
, in_code
, flags
);
7445 if ((flags
& GOVD_PRIVATE
)
7446 && lang_hooks
.decls
.omp_private_outer_ref (decl
))
7447 flags
|= GOVD_PRIVATE_OUTER_REF
;
7449 omp_add_variable (ctx
, decl
, flags
);
7451 shared
= (flags
& GOVD_SHARED
) != 0;
7452 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, shared
);
7456 if ((n
->value
& (GOVD_SEEN
| GOVD_LOCAL
)) == 0
7457 && (flags
& (GOVD_SEEN
| GOVD_LOCAL
)) == GOVD_SEEN
7458 && DECL_SIZE (decl
))
7460 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
7463 tree t
= DECL_VALUE_EXPR (decl
);
7464 gcc_assert (TREE_CODE (t
) == INDIRECT_REF
);
7465 t
= TREE_OPERAND (t
, 0);
7466 gcc_assert (DECL_P (t
));
7467 n2
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
7468 n2
->value
|= GOVD_SEEN
;
7470 else if (lang_hooks
.decls
.omp_privatize_by_reference (decl
)
7471 && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)))
7472 && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
))))
7476 tree t
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)));
7477 gcc_assert (DECL_P (t
));
7478 n2
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
7480 omp_notice_variable (ctx
, t
, true);
7484 shared
= ((flags
| n
->value
) & GOVD_SHARED
) != 0;
7485 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, shared
);
7487 /* If nothing changed, there's nothing left to do. */
7488 if ((n
->value
& flags
) == flags
)
7494 /* If the variable is private in the current context, then we don't
7495 need to propagate anything to an outer context. */
7496 if ((flags
& GOVD_PRIVATE
) && !(flags
& GOVD_PRIVATE_OUTER_REF
))
7498 if ((flags
& (GOVD_LINEAR
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7499 == (GOVD_LINEAR
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7501 if ((flags
& (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
7502 | GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7503 == (GOVD_LASTPRIVATE
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7505 if (ctx
->outer_context
7506 && omp_notice_variable (ctx
->outer_context
, decl
, in_code
))
7511 /* Verify that DECL is private within CTX. If there's specific information
7512 to the contrary in the innermost scope, generate an error. */
7515 omp_is_private (struct gimplify_omp_ctx
*ctx
, tree decl
, int simd
)
7519 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7522 if (n
->value
& GOVD_SHARED
)
7524 if (ctx
== gimplify_omp_ctxp
)
7527 error ("iteration variable %qE is predetermined linear",
7530 error ("iteration variable %qE should be private",
7532 n
->value
= GOVD_PRIVATE
;
7538 else if ((n
->value
& GOVD_EXPLICIT
) != 0
7539 && (ctx
== gimplify_omp_ctxp
7540 || (ctx
->region_type
== ORT_COMBINED_PARALLEL
7541 && gimplify_omp_ctxp
->outer_context
== ctx
)))
7543 if ((n
->value
& GOVD_FIRSTPRIVATE
) != 0)
7544 error ("iteration variable %qE should not be firstprivate",
7546 else if ((n
->value
& GOVD_REDUCTION
) != 0)
7547 error ("iteration variable %qE should not be reduction",
7549 else if (simd
!= 1 && (n
->value
& GOVD_LINEAR
) != 0)
7550 error ("iteration variable %qE should not be linear",
7553 return (ctx
== gimplify_omp_ctxp
7554 || (ctx
->region_type
== ORT_COMBINED_PARALLEL
7555 && gimplify_omp_ctxp
->outer_context
== ctx
));
7558 if (ctx
->region_type
!= ORT_WORKSHARE
7559 && ctx
->region_type
!= ORT_TASKGROUP
7560 && ctx
->region_type
!= ORT_SIMD
7561 && ctx
->region_type
!= ORT_ACC
)
7563 else if (ctx
->outer_context
)
7564 return omp_is_private (ctx
->outer_context
, decl
, simd
);
7568 /* Return true if DECL is private within a parallel region
7569 that binds to the current construct's context or in parallel
7570 region's REDUCTION clause. */
7573 omp_check_private (struct gimplify_omp_ctx
*ctx
, tree decl
, bool copyprivate
)
7579 ctx
= ctx
->outer_context
;
7582 if (is_global_var (decl
))
7585 /* References might be private, but might be shared too,
7586 when checking for copyprivate, assume they might be
7587 private, otherwise assume they might be shared. */
7591 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7594 /* Treat C++ privatized non-static data members outside
7595 of the privatization the same. */
7596 if (omp_member_access_dummy_var (decl
))
7602 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
7604 if ((ctx
->region_type
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0
7605 && (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0))
7610 if ((n
->value
& GOVD_LOCAL
) != 0
7611 && omp_member_access_dummy_var (decl
))
7613 return (n
->value
& GOVD_SHARED
) == 0;
7616 while (ctx
->region_type
== ORT_WORKSHARE
7617 || ctx
->region_type
== ORT_TASKGROUP
7618 || ctx
->region_type
== ORT_SIMD
7619 || ctx
->region_type
== ORT_ACC
);
7623 /* Callback for walk_tree to find a DECL_EXPR for the given DECL. */
7626 find_decl_expr (tree
*tp
, int *walk_subtrees
, void *data
)
7630 /* If this node has been visited, unmark it and keep looking. */
7631 if (TREE_CODE (t
) == DECL_EXPR
&& DECL_EXPR_DECL (t
) == (tree
) data
)
7634 if (IS_TYPE_OR_DECL_P (t
))
7639 /* If *LIST_P contains any OpenMP depend clauses with iterators,
7640 lower all the depend clauses by populating corresponding depend
7641 array. Returns 0 if there are no such depend clauses, or
7642 2 if all depend clauses should be removed, 1 otherwise. */
7645 gimplify_omp_depend (tree
*list_p
, gimple_seq
*pre_p
)
7649 size_t n
[4] = { 0, 0, 0, 0 };
7651 tree counts
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
7652 tree last_iter
= NULL_TREE
, last_count
= NULL_TREE
;
7654 location_t first_loc
= UNKNOWN_LOCATION
;
7656 for (c
= *list_p
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7657 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
7659 switch (OMP_CLAUSE_DEPEND_KIND (c
))
7661 case OMP_CLAUSE_DEPEND_IN
:
7664 case OMP_CLAUSE_DEPEND_OUT
:
7665 case OMP_CLAUSE_DEPEND_INOUT
:
7668 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET
:
7671 case OMP_CLAUSE_DEPEND_DEPOBJ
:
7674 case OMP_CLAUSE_DEPEND_SOURCE
:
7675 case OMP_CLAUSE_DEPEND_SINK
:
7680 tree t
= OMP_CLAUSE_DECL (c
);
7681 if (first_loc
== UNKNOWN_LOCATION
)
7682 first_loc
= OMP_CLAUSE_LOCATION (c
);
7683 if (TREE_CODE (t
) == TREE_LIST
7685 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7687 if (TREE_PURPOSE (t
) != last_iter
)
7689 tree tcnt
= size_one_node
;
7690 for (tree it
= TREE_PURPOSE (t
); it
; it
= TREE_CHAIN (it
))
7692 if (gimplify_expr (&TREE_VEC_ELT (it
, 1), pre_p
, NULL
,
7693 is_gimple_val
, fb_rvalue
) == GS_ERROR
7694 || gimplify_expr (&TREE_VEC_ELT (it
, 2), pre_p
, NULL
,
7695 is_gimple_val
, fb_rvalue
) == GS_ERROR
7696 || gimplify_expr (&TREE_VEC_ELT (it
, 3), pre_p
, NULL
,
7697 is_gimple_val
, fb_rvalue
) == GS_ERROR
7698 || (gimplify_expr (&TREE_VEC_ELT (it
, 4), pre_p
, NULL
,
7699 is_gimple_val
, fb_rvalue
)
7702 tree var
= TREE_VEC_ELT (it
, 0);
7703 tree begin
= TREE_VEC_ELT (it
, 1);
7704 tree end
= TREE_VEC_ELT (it
, 2);
7705 tree step
= TREE_VEC_ELT (it
, 3);
7706 tree orig_step
= TREE_VEC_ELT (it
, 4);
7707 tree type
= TREE_TYPE (var
);
7708 tree stype
= TREE_TYPE (step
);
7709 location_t loc
= DECL_SOURCE_LOCATION (var
);
7711 /* Compute count for this iterator as
7713 ? (begin < end ? (end - begin + (step - 1)) / step : 0)
7714 : (begin > end ? (end - begin + (step + 1)) / step : 0)
7715 and compute product of those for the entire depend
7717 if (POINTER_TYPE_P (type
))
7718 endmbegin
= fold_build2_loc (loc
, POINTER_DIFF_EXPR
,
7721 endmbegin
= fold_build2_loc (loc
, MINUS_EXPR
, type
,
7723 tree stepm1
= fold_build2_loc (loc
, MINUS_EXPR
, stype
,
7725 build_int_cst (stype
, 1));
7726 tree stepp1
= fold_build2_loc (loc
, PLUS_EXPR
, stype
, step
,
7727 build_int_cst (stype
, 1));
7728 tree pos
= fold_build2_loc (loc
, PLUS_EXPR
, stype
,
7729 unshare_expr (endmbegin
),
7731 pos
= fold_build2_loc (loc
, TRUNC_DIV_EXPR
, stype
,
7733 tree neg
= fold_build2_loc (loc
, PLUS_EXPR
, stype
,
7735 if (TYPE_UNSIGNED (stype
))
7737 neg
= fold_build1_loc (loc
, NEGATE_EXPR
, stype
, neg
);
7738 step
= fold_build1_loc (loc
, NEGATE_EXPR
, stype
, step
);
7740 neg
= fold_build2_loc (loc
, TRUNC_DIV_EXPR
, stype
,
7743 tree cond
= fold_build2_loc (loc
, LT_EXPR
,
7746 pos
= fold_build3_loc (loc
, COND_EXPR
, stype
, cond
, pos
,
7747 build_int_cst (stype
, 0));
7748 cond
= fold_build2_loc (loc
, LT_EXPR
, boolean_type_node
,
7750 neg
= fold_build3_loc (loc
, COND_EXPR
, stype
, cond
, neg
,
7751 build_int_cst (stype
, 0));
7752 tree osteptype
= TREE_TYPE (orig_step
);
7753 cond
= fold_build2_loc (loc
, GT_EXPR
, boolean_type_node
,
7755 build_int_cst (osteptype
, 0));
7756 tree cnt
= fold_build3_loc (loc
, COND_EXPR
, stype
,
7758 cnt
= fold_convert_loc (loc
, sizetype
, cnt
);
7759 if (gimplify_expr (&cnt
, pre_p
, NULL
, is_gimple_val
,
7760 fb_rvalue
) == GS_ERROR
)
7762 tcnt
= size_binop_loc (loc
, MULT_EXPR
, tcnt
, cnt
);
7764 if (gimplify_expr (&tcnt
, pre_p
, NULL
, is_gimple_val
,
7765 fb_rvalue
) == GS_ERROR
)
7767 last_iter
= TREE_PURPOSE (t
);
7770 if (counts
[i
] == NULL_TREE
)
7771 counts
[i
] = last_count
;
7773 counts
[i
] = size_binop_loc (OMP_CLAUSE_LOCATION (c
),
7774 PLUS_EXPR
, counts
[i
], last_count
);
7779 for (i
= 0; i
< 4; i
++)
7785 tree total
= size_zero_node
;
7786 for (i
= 0; i
< 4; i
++)
7788 unused
[i
] = counts
[i
] == NULL_TREE
&& n
[i
] == 0;
7789 if (counts
[i
] == NULL_TREE
)
7790 counts
[i
] = size_zero_node
;
7792 counts
[i
] = size_binop (PLUS_EXPR
, counts
[i
], size_int (n
[i
]));
7793 if (gimplify_expr (&counts
[i
], pre_p
, NULL
, is_gimple_val
,
7794 fb_rvalue
) == GS_ERROR
)
7796 total
= size_binop (PLUS_EXPR
, total
, counts
[i
]);
7799 if (gimplify_expr (&total
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
7802 bool is_old
= unused
[1] && unused
[3];
7803 tree totalpx
= size_binop (PLUS_EXPR
, unshare_expr (total
),
7804 size_int (is_old
? 1 : 4));
7805 tree type
= build_array_type (ptr_type_node
, build_index_type (totalpx
));
7806 tree array
= create_tmp_var_raw (type
);
7807 TREE_ADDRESSABLE (array
) = 1;
7808 if (TREE_CODE (totalpx
) != INTEGER_CST
)
7810 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (array
)))
7811 gimplify_type_sizes (TREE_TYPE (array
), pre_p
);
7812 if (gimplify_omp_ctxp
)
7814 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
7816 && (ctx
->region_type
== ORT_WORKSHARE
7817 || ctx
->region_type
== ORT_TASKGROUP
7818 || ctx
->region_type
== ORT_SIMD
7819 || ctx
->region_type
== ORT_ACC
))
7820 ctx
= ctx
->outer_context
;
7822 omp_add_variable (ctx
, array
, GOVD_LOCAL
| GOVD_SEEN
);
7824 gimplify_vla_decl (array
, pre_p
);
7827 gimple_add_tmp_var (array
);
7828 tree r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (0), NULL_TREE
,
7833 tem
= build2 (MODIFY_EXPR
, void_type_node
, r
,
7834 build_int_cst (ptr_type_node
, 0));
7835 gimplify_and_add (tem
, pre_p
);
7836 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (1), NULL_TREE
,
7839 tem
= build2 (MODIFY_EXPR
, void_type_node
, r
,
7840 fold_convert (ptr_type_node
, total
));
7841 gimplify_and_add (tem
, pre_p
);
7842 for (i
= 1; i
< (is_old
? 2 : 4); i
++)
7844 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (i
+ !is_old
),
7845 NULL_TREE
, NULL_TREE
);
7846 tem
= build2 (MODIFY_EXPR
, void_type_node
, r
, counts
[i
- 1]);
7847 gimplify_and_add (tem
, pre_p
);
7854 for (i
= 0; i
< 4; i
++)
7856 if (i
&& (i
>= j
|| unused
[i
- 1]))
7858 cnts
[i
] = cnts
[i
- 1];
7861 cnts
[i
] = create_tmp_var (sizetype
);
7863 g
= gimple_build_assign (cnts
[i
], size_int (is_old
? 2 : 5));
7868 t
= size_binop (PLUS_EXPR
, counts
[0], size_int (2));
7870 t
= size_binop (PLUS_EXPR
, cnts
[i
- 1], counts
[i
- 1]);
7871 if (gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
7874 g
= gimple_build_assign (cnts
[i
], t
);
7876 gimple_seq_add_stmt (pre_p
, g
);
7879 last_iter
= NULL_TREE
;
7880 tree last_bind
= NULL_TREE
;
7881 tree
*last_body
= NULL
;
7882 for (c
= *list_p
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7883 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
7885 switch (OMP_CLAUSE_DEPEND_KIND (c
))
7887 case OMP_CLAUSE_DEPEND_IN
:
7890 case OMP_CLAUSE_DEPEND_OUT
:
7891 case OMP_CLAUSE_DEPEND_INOUT
:
7894 case OMP_CLAUSE_DEPEND_MUTEXINOUTSET
:
7897 case OMP_CLAUSE_DEPEND_DEPOBJ
:
7900 case OMP_CLAUSE_DEPEND_SOURCE
:
7901 case OMP_CLAUSE_DEPEND_SINK
:
7906 tree t
= OMP_CLAUSE_DECL (c
);
7907 if (TREE_CODE (t
) == TREE_LIST
7909 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7911 if (TREE_PURPOSE (t
) != last_iter
)
7914 gimplify_and_add (last_bind
, pre_p
);
7915 tree block
= TREE_VEC_ELT (TREE_PURPOSE (t
), 5);
7916 last_bind
= build3 (BIND_EXPR
, void_type_node
,
7917 BLOCK_VARS (block
), NULL
, block
);
7918 TREE_SIDE_EFFECTS (last_bind
) = 1;
7919 SET_EXPR_LOCATION (last_bind
, OMP_CLAUSE_LOCATION (c
));
7920 tree
*p
= &BIND_EXPR_BODY (last_bind
);
7921 for (tree it
= TREE_PURPOSE (t
); it
; it
= TREE_CHAIN (it
))
7923 tree var
= TREE_VEC_ELT (it
, 0);
7924 tree begin
= TREE_VEC_ELT (it
, 1);
7925 tree end
= TREE_VEC_ELT (it
, 2);
7926 tree step
= TREE_VEC_ELT (it
, 3);
7927 tree orig_step
= TREE_VEC_ELT (it
, 4);
7928 tree type
= TREE_TYPE (var
);
7929 location_t loc
= DECL_SOURCE_LOCATION (var
);
7937 if (orig_step > 0) {
7938 if (var < end) goto beg_label;
7940 if (var > end) goto beg_label;
7942 for each iterator, with inner iterators added to
7944 tree beg_label
= create_artificial_label (loc
);
7945 tree cond_label
= NULL_TREE
;
7946 tem
= build2_loc (loc
, MODIFY_EXPR
, void_type_node
,
7948 append_to_statement_list_force (tem
, p
);
7949 tem
= build_and_jump (&cond_label
);
7950 append_to_statement_list_force (tem
, p
);
7951 tem
= build1 (LABEL_EXPR
, void_type_node
, beg_label
);
7952 append_to_statement_list (tem
, p
);
7953 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
7954 NULL_TREE
, NULL_TREE
);
7955 TREE_SIDE_EFFECTS (bind
) = 1;
7956 SET_EXPR_LOCATION (bind
, loc
);
7957 append_to_statement_list_force (bind
, p
);
7958 if (POINTER_TYPE_P (type
))
7959 tem
= build2_loc (loc
, POINTER_PLUS_EXPR
, type
,
7960 var
, fold_convert_loc (loc
, sizetype
,
7963 tem
= build2_loc (loc
, PLUS_EXPR
, type
, var
, step
);
7964 tem
= build2_loc (loc
, MODIFY_EXPR
, void_type_node
,
7966 append_to_statement_list_force (tem
, p
);
7967 tem
= build1 (LABEL_EXPR
, void_type_node
, cond_label
);
7968 append_to_statement_list (tem
, p
);
7969 tree cond
= fold_build2_loc (loc
, LT_EXPR
,
7973 = fold_build3_loc (loc
, COND_EXPR
, void_type_node
,
7974 cond
, build_and_jump (&beg_label
),
7976 cond
= fold_build2_loc (loc
, GT_EXPR
, boolean_type_node
,
7979 = fold_build3_loc (loc
, COND_EXPR
, void_type_node
,
7980 cond
, build_and_jump (&beg_label
),
7982 tree osteptype
= TREE_TYPE (orig_step
);
7983 cond
= fold_build2_loc (loc
, GT_EXPR
, boolean_type_node
,
7985 build_int_cst (osteptype
, 0));
7986 tem
= fold_build3_loc (loc
, COND_EXPR
, void_type_node
,
7988 append_to_statement_list_force (tem
, p
);
7989 p
= &BIND_EXPR_BODY (bind
);
7993 last_iter
= TREE_PURPOSE (t
);
7994 if (TREE_CODE (TREE_VALUE (t
)) == COMPOUND_EXPR
)
7996 append_to_statement_list (TREE_OPERAND (TREE_VALUE (t
),
7998 TREE_VALUE (t
) = TREE_OPERAND (TREE_VALUE (t
), 1);
8000 if (error_operand_p (TREE_VALUE (t
)))
8002 TREE_VALUE (t
) = build_fold_addr_expr (TREE_VALUE (t
));
8003 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, cnts
[i
],
8004 NULL_TREE
, NULL_TREE
);
8005 tem
= build2_loc (OMP_CLAUSE_LOCATION (c
), MODIFY_EXPR
,
8006 void_type_node
, r
, TREE_VALUE (t
));
8007 append_to_statement_list_force (tem
, last_body
);
8008 tem
= build2_loc (OMP_CLAUSE_LOCATION (c
), MODIFY_EXPR
,
8009 void_type_node
, cnts
[i
],
8010 size_binop (PLUS_EXPR
, cnts
[i
], size_int (1)));
8011 append_to_statement_list_force (tem
, last_body
);
8012 TREE_VALUE (t
) = null_pointer_node
;
8018 gimplify_and_add (last_bind
, pre_p
);
8019 last_bind
= NULL_TREE
;
8021 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPOUND_EXPR
)
8023 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0), pre_p
,
8024 NULL
, is_gimple_val
, fb_rvalue
);
8025 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (OMP_CLAUSE_DECL (c
), 1);
8027 if (error_operand_p (OMP_CLAUSE_DECL (c
)))
8029 OMP_CLAUSE_DECL (c
) = build_fold_addr_expr (OMP_CLAUSE_DECL (c
));
8030 if (gimplify_expr (&OMP_CLAUSE_DECL (c
), pre_p
, NULL
,
8031 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8033 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, cnts
[i
],
8034 NULL_TREE
, NULL_TREE
);
8035 tem
= build2 (MODIFY_EXPR
, void_type_node
, r
, OMP_CLAUSE_DECL (c
));
8036 gimplify_and_add (tem
, pre_p
);
8037 g
= gimple_build_assign (cnts
[i
], size_binop (PLUS_EXPR
, cnts
[i
],
8039 gimple_seq_add_stmt (pre_p
, g
);
8043 gimplify_and_add (last_bind
, pre_p
);
8044 tree cond
= boolean_false_node
;
8048 cond
= build2_loc (first_loc
, NE_EXPR
, boolean_type_node
, cnts
[0],
8049 size_binop_loc (first_loc
, PLUS_EXPR
, counts
[0],
8052 cond
= build2_loc (first_loc
, TRUTH_OR_EXPR
, boolean_type_node
, cond
,
8053 build2_loc (first_loc
, NE_EXPR
, boolean_type_node
,
8055 size_binop_loc (first_loc
, PLUS_EXPR
,
8061 tree prev
= size_int (5);
8062 for (i
= 0; i
< 4; i
++)
8066 prev
= size_binop_loc (first_loc
, PLUS_EXPR
, counts
[i
], prev
);
8067 cond
= build2_loc (first_loc
, TRUTH_OR_EXPR
, boolean_type_node
, cond
,
8068 build2_loc (first_loc
, NE_EXPR
, boolean_type_node
,
8069 cnts
[i
], unshare_expr (prev
)));
8072 tem
= build3_loc (first_loc
, COND_EXPR
, void_type_node
, cond
,
8073 build_call_expr_loc (first_loc
,
8074 builtin_decl_explicit (BUILT_IN_TRAP
),
8076 gimplify_and_add (tem
, pre_p
);
8077 c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE_DEPEND
);
8078 OMP_CLAUSE_DEPEND_KIND (c
) = OMP_CLAUSE_DEPEND_LAST
;
8079 OMP_CLAUSE_DECL (c
) = build_fold_addr_expr (array
);
8080 OMP_CLAUSE_CHAIN (c
) = *list_p
;
8085 /* Scan the OMP clauses in *LIST_P, installing mappings into a new
8086 and previous omp contexts. */
8089 gimplify_scan_omp_clauses (tree
*list_p
, gimple_seq
*pre_p
,
8090 enum omp_region_type region_type
,
8091 enum tree_code code
)
8093 struct gimplify_omp_ctx
*ctx
, *outer_ctx
;
8095 hash_map
<tree
, tree
> *struct_map_to_clause
= NULL
;
8096 tree
*prev_list_p
= NULL
, *orig_list_p
= list_p
;
8097 int handled_depend_iterators
= -1;
8100 ctx
= new_omp_context (region_type
);
8101 outer_ctx
= ctx
->outer_context
;
8102 if (code
== OMP_TARGET
)
8104 if (!lang_GNU_Fortran ())
8105 ctx
->defaultmap
[GDMK_POINTER
] = GOVD_MAP
| GOVD_MAP_0LEN_ARRAY
;
8106 ctx
->defaultmap
[GDMK_SCALAR
] = GOVD_FIRSTPRIVATE
;
8108 if (!lang_GNU_Fortran ())
8112 case OMP_TARGET_DATA
:
8113 case OMP_TARGET_ENTER_DATA
:
8114 case OMP_TARGET_EXIT_DATA
:
8116 case OACC_HOST_DATA
:
8119 ctx
->target_firstprivatize_array_bases
= true;
8124 while ((c
= *list_p
) != NULL
)
8126 bool remove
= false;
8127 bool notice_outer
= true;
8128 const char *check_non_private
= NULL
;
8132 switch (OMP_CLAUSE_CODE (c
))
8134 case OMP_CLAUSE_PRIVATE
:
8135 flags
= GOVD_PRIVATE
| GOVD_EXPLICIT
;
8136 if (lang_hooks
.decls
.omp_private_outer_ref (OMP_CLAUSE_DECL (c
)))
8138 flags
|= GOVD_PRIVATE_OUTER_REF
;
8139 OMP_CLAUSE_PRIVATE_OUTER_REF (c
) = 1;
8142 notice_outer
= false;
8144 case OMP_CLAUSE_SHARED
:
8145 flags
= GOVD_SHARED
| GOVD_EXPLICIT
;
8147 case OMP_CLAUSE_FIRSTPRIVATE
:
8148 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
8149 check_non_private
= "firstprivate";
8151 case OMP_CLAUSE_LASTPRIVATE
:
8152 if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
))
8155 case OMP_DISTRIBUTE
:
8156 error_at (OMP_CLAUSE_LOCATION (c
),
8157 "conditional %<lastprivate%> clause on "
8158 "%qs construct", "distribute");
8159 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) = 0;
8162 error_at (OMP_CLAUSE_LOCATION (c
),
8163 "conditional %<lastprivate%> clause on "
8164 "%qs construct", "taskloop");
8165 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) = 0;
8170 flags
= GOVD_LASTPRIVATE
| GOVD_SEEN
| GOVD_EXPLICIT
;
8171 check_non_private
= "lastprivate";
8172 decl
= OMP_CLAUSE_DECL (c
);
8173 if (error_operand_p (decl
))
8175 if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
)
8176 && !lang_hooks
.decls
.omp_scalar_p (decl
))
8178 error_at (OMP_CLAUSE_LOCATION (c
),
8179 "non-scalar variable %qD in conditional "
8180 "%<lastprivate%> clause", decl
);
8181 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) = 0;
8183 if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
))
8184 flags
|= GOVD_LASTPRIVATE_CONDITIONAL
;
8186 && (outer_ctx
->region_type
== ORT_COMBINED_PARALLEL
8187 || ((outer_ctx
->region_type
& ORT_COMBINED_TEAMS
)
8188 == ORT_COMBINED_TEAMS
))
8189 && splay_tree_lookup (outer_ctx
->variables
,
8190 (splay_tree_key
) decl
) == NULL
)
8192 omp_add_variable (outer_ctx
, decl
, GOVD_SHARED
| GOVD_SEEN
);
8193 if (outer_ctx
->outer_context
)
8194 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
8197 && (outer_ctx
->region_type
& ORT_TASK
) != 0
8198 && outer_ctx
->combined_loop
8199 && splay_tree_lookup (outer_ctx
->variables
,
8200 (splay_tree_key
) decl
) == NULL
)
8202 omp_add_variable (outer_ctx
, decl
, GOVD_LASTPRIVATE
| GOVD_SEEN
);
8203 if (outer_ctx
->outer_context
)
8204 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
8207 && (outer_ctx
->region_type
== ORT_WORKSHARE
8208 || outer_ctx
->region_type
== ORT_ACC
)
8209 && outer_ctx
->combined_loop
8210 && splay_tree_lookup (outer_ctx
->variables
,
8211 (splay_tree_key
) decl
) == NULL
8212 && !omp_check_private (outer_ctx
, decl
, false))
8214 omp_add_variable (outer_ctx
, decl
, GOVD_LASTPRIVATE
| GOVD_SEEN
);
8215 if (outer_ctx
->outer_context
8216 && (outer_ctx
->outer_context
->region_type
8217 == ORT_COMBINED_PARALLEL
)
8218 && splay_tree_lookup (outer_ctx
->outer_context
->variables
,
8219 (splay_tree_key
) decl
) == NULL
)
8221 struct gimplify_omp_ctx
*octx
= outer_ctx
->outer_context
;
8222 omp_add_variable (octx
, decl
, GOVD_SHARED
| GOVD_SEEN
);
8223 if (octx
->outer_context
)
8225 octx
= octx
->outer_context
;
8226 if (octx
->region_type
== ORT_WORKSHARE
8227 && octx
->combined_loop
8228 && splay_tree_lookup (octx
->variables
,
8229 (splay_tree_key
) decl
) == NULL
8230 && !omp_check_private (octx
, decl
, false))
8232 omp_add_variable (octx
, decl
,
8233 GOVD_LASTPRIVATE
| GOVD_SEEN
);
8234 octx
= octx
->outer_context
;
8236 && ((octx
->region_type
& ORT_COMBINED_TEAMS
)
8237 == ORT_COMBINED_TEAMS
)
8238 && (splay_tree_lookup (octx
->variables
,
8239 (splay_tree_key
) decl
)
8242 omp_add_variable (octx
, decl
,
8243 GOVD_SHARED
| GOVD_SEEN
);
8244 octx
= octx
->outer_context
;
8248 omp_notice_variable (octx
, decl
, true);
8251 else if (outer_ctx
->outer_context
)
8252 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
8255 case OMP_CLAUSE_REDUCTION
:
8256 if (OMP_CLAUSE_REDUCTION_TASK (c
))
8258 if (region_type
== ORT_WORKSHARE
)
8261 nowait
= omp_find_clause (*list_p
,
8262 OMP_CLAUSE_NOWAIT
) != NULL_TREE
;
8264 && (outer_ctx
== NULL
8265 || outer_ctx
->region_type
!= ORT_COMBINED_PARALLEL
))
8267 error_at (OMP_CLAUSE_LOCATION (c
),
8268 "%<task%> reduction modifier on a construct "
8269 "with a %<nowait%> clause");
8270 OMP_CLAUSE_REDUCTION_TASK (c
) = 0;
8273 else if ((region_type
& ORT_PARALLEL
) != ORT_PARALLEL
)
8275 error_at (OMP_CLAUSE_LOCATION (c
),
8276 "invalid %<task%> reduction modifier on construct "
8277 "other than %<parallel%>, %<for%> or %<sections%>");
8278 OMP_CLAUSE_REDUCTION_TASK (c
) = 0;
8281 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8285 error_at (OMP_CLAUSE_LOCATION (c
),
8286 "%<inscan%> %<reduction%> clause on "
8287 "%qs construct", "sections");
8288 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8291 error_at (OMP_CLAUSE_LOCATION (c
),
8292 "%<inscan%> %<reduction%> clause on "
8293 "%qs construct", "parallel");
8294 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8297 error_at (OMP_CLAUSE_LOCATION (c
),
8298 "%<inscan%> %<reduction%> clause on "
8299 "%qs construct", "teams");
8300 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8303 error_at (OMP_CLAUSE_LOCATION (c
),
8304 "%<inscan%> %<reduction%> clause on "
8305 "%qs construct", "taskloop");
8306 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8312 case OMP_CLAUSE_IN_REDUCTION
:
8313 case OMP_CLAUSE_TASK_REDUCTION
:
8314 flags
= GOVD_REDUCTION
| GOVD_SEEN
| GOVD_EXPLICIT
;
8315 /* OpenACC permits reductions on private variables. */
8316 if (!(region_type
& ORT_ACC
)
8317 /* taskgroup is actually not a worksharing region. */
8318 && code
!= OMP_TASKGROUP
)
8319 check_non_private
= omp_clause_code_name
[OMP_CLAUSE_CODE (c
)];
8320 decl
= OMP_CLAUSE_DECL (c
);
8321 if (TREE_CODE (decl
) == MEM_REF
)
8323 tree type
= TREE_TYPE (decl
);
8324 if (gimplify_expr (&TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), pre_p
,
8325 NULL
, is_gimple_val
, fb_rvalue
, false)
8331 tree v
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
8334 omp_firstprivatize_variable (ctx
, v
);
8335 omp_notice_variable (ctx
, v
, true);
8337 decl
= TREE_OPERAND (decl
, 0);
8338 if (TREE_CODE (decl
) == POINTER_PLUS_EXPR
)
8340 if (gimplify_expr (&TREE_OPERAND (decl
, 1), pre_p
,
8341 NULL
, is_gimple_val
, fb_rvalue
, false)
8347 v
= TREE_OPERAND (decl
, 1);
8350 omp_firstprivatize_variable (ctx
, v
);
8351 omp_notice_variable (ctx
, v
, true);
8353 decl
= TREE_OPERAND (decl
, 0);
8355 if (TREE_CODE (decl
) == ADDR_EXPR
8356 || TREE_CODE (decl
) == INDIRECT_REF
)
8357 decl
= TREE_OPERAND (decl
, 0);
8360 case OMP_CLAUSE_LINEAR
:
8361 if (gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c
), pre_p
, NULL
,
8362 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8369 if (code
== OMP_SIMD
8370 && !OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
8372 struct gimplify_omp_ctx
*octx
= outer_ctx
;
8374 && octx
->region_type
== ORT_WORKSHARE
8375 && octx
->combined_loop
8376 && !octx
->distribute
)
8378 if (octx
->outer_context
8379 && (octx
->outer_context
->region_type
8380 == ORT_COMBINED_PARALLEL
))
8381 octx
= octx
->outer_context
->outer_context
;
8383 octx
= octx
->outer_context
;
8386 && octx
->region_type
== ORT_WORKSHARE
8387 && octx
->combined_loop
8388 && octx
->distribute
)
8390 error_at (OMP_CLAUSE_LOCATION (c
),
8391 "%<linear%> clause for variable other than "
8392 "loop iterator specified on construct "
8393 "combined with %<distribute%>");
8398 /* For combined #pragma omp parallel for simd, need to put
8399 lastprivate and perhaps firstprivate too on the
8400 parallel. Similarly for #pragma omp for simd. */
8401 struct gimplify_omp_ctx
*octx
= outer_ctx
;
8405 if (OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
8406 && OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
8408 decl
= OMP_CLAUSE_DECL (c
);
8409 if (error_operand_p (decl
))
8415 if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
8416 flags
|= GOVD_FIRSTPRIVATE
;
8417 if (!OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
8418 flags
|= GOVD_LASTPRIVATE
;
8420 && octx
->region_type
== ORT_WORKSHARE
8421 && octx
->combined_loop
)
8423 if (octx
->outer_context
8424 && (octx
->outer_context
->region_type
8425 == ORT_COMBINED_PARALLEL
))
8426 octx
= octx
->outer_context
;
8427 else if (omp_check_private (octx
, decl
, false))
8431 && (octx
->region_type
& ORT_TASK
) != 0
8432 && octx
->combined_loop
)
8435 && octx
->region_type
== ORT_COMBINED_PARALLEL
8436 && ctx
->region_type
== ORT_WORKSHARE
8437 && octx
== outer_ctx
)
8438 flags
= GOVD_SEEN
| GOVD_SHARED
;
8440 && ((octx
->region_type
& ORT_COMBINED_TEAMS
)
8441 == ORT_COMBINED_TEAMS
))
8442 flags
= GOVD_SEEN
| GOVD_SHARED
;
8444 && octx
->region_type
== ORT_COMBINED_TARGET
)
8446 flags
&= ~GOVD_LASTPRIVATE
;
8447 if (flags
== GOVD_SEEN
)
8453 = splay_tree_lookup (octx
->variables
,
8454 (splay_tree_key
) decl
);
8455 if (on
&& (on
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
8460 omp_add_variable (octx
, decl
, flags
);
8461 if (octx
->outer_context
== NULL
)
8463 octx
= octx
->outer_context
;
8468 && (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
8469 || !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)))
8470 omp_notice_variable (octx
, decl
, true);
8472 flags
= GOVD_LINEAR
| GOVD_EXPLICIT
;
8473 if (OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
8474 && OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
8476 notice_outer
= false;
8477 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
8481 case OMP_CLAUSE_MAP
:
8482 decl
= OMP_CLAUSE_DECL (c
);
8483 if (error_operand_p (decl
))
8490 if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
8493 case OMP_TARGET_DATA
:
8494 case OMP_TARGET_ENTER_DATA
:
8495 case OMP_TARGET_EXIT_DATA
:
8496 case OACC_ENTER_DATA
:
8497 case OACC_EXIT_DATA
:
8498 case OACC_HOST_DATA
:
8499 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
8500 || (OMP_CLAUSE_MAP_KIND (c
)
8501 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
8502 /* For target {,enter ,exit }data only the array slice is
8503 mapped, but not the pointer to it. */
8511 if (DECL_P (decl
) && outer_ctx
&& (region_type
& ORT_ACC
))
8513 struct gimplify_omp_ctx
*octx
;
8514 for (octx
= outer_ctx
; octx
; octx
= octx
->outer_context
)
8516 if (octx
->region_type
!= ORT_ACC_HOST_DATA
)
8519 = splay_tree_lookup (octx
->variables
,
8520 (splay_tree_key
) decl
);
8522 error_at (OMP_CLAUSE_LOCATION (c
), "variable %qE "
8523 "declared in enclosing %<host_data%> region",
8527 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8528 OMP_CLAUSE_SIZE (c
) = DECL_P (decl
) ? DECL_SIZE_UNIT (decl
)
8529 : TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8530 if (gimplify_expr (&OMP_CLAUSE_SIZE (c
), pre_p
,
8531 NULL
, is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8536 else if ((OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
8537 || (OMP_CLAUSE_MAP_KIND (c
)
8538 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
8539 && TREE_CODE (OMP_CLAUSE_SIZE (c
)) != INTEGER_CST
)
8542 = get_initialized_tmp_var (OMP_CLAUSE_SIZE (c
), pre_p
, NULL
,
8544 omp_add_variable (ctx
, OMP_CLAUSE_SIZE (c
),
8545 GOVD_FIRSTPRIVATE
| GOVD_SEEN
);
8550 if (TREE_CODE (d
) == ARRAY_REF
)
8552 while (TREE_CODE (d
) == ARRAY_REF
)
8553 d
= TREE_OPERAND (d
, 0);
8554 if (TREE_CODE (d
) == COMPONENT_REF
8555 && TREE_CODE (TREE_TYPE (d
)) == ARRAY_TYPE
)
8558 pd
= &OMP_CLAUSE_DECL (c
);
8560 && TREE_CODE (decl
) == INDIRECT_REF
8561 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
8562 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
8565 pd
= &TREE_OPERAND (decl
, 0);
8566 decl
= TREE_OPERAND (decl
, 0);
8568 if (TREE_CODE (decl
) == COMPONENT_REF
)
8570 while (TREE_CODE (decl
) == COMPONENT_REF
)
8571 decl
= TREE_OPERAND (decl
, 0);
8572 if (TREE_CODE (decl
) == INDIRECT_REF
8573 && DECL_P (TREE_OPERAND (decl
, 0))
8574 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
8576 decl
= TREE_OPERAND (decl
, 0);
8578 if (gimplify_expr (pd
, pre_p
, NULL
, is_gimple_lvalue
, fb_lvalue
)
8586 if (error_operand_p (decl
))
8592 tree stype
= TREE_TYPE (decl
);
8593 if (TREE_CODE (stype
) == REFERENCE_TYPE
)
8594 stype
= TREE_TYPE (stype
);
8595 if (TYPE_SIZE_UNIT (stype
) == NULL
8596 || TREE_CODE (TYPE_SIZE_UNIT (stype
)) != INTEGER_CST
)
8598 error_at (OMP_CLAUSE_LOCATION (c
),
8599 "mapping field %qE of variable length "
8600 "structure", OMP_CLAUSE_DECL (c
));
8605 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
)
8607 /* Error recovery. */
8608 if (prev_list_p
== NULL
)
8613 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
8615 tree ch
= OMP_CLAUSE_CHAIN (*prev_list_p
);
8616 if (ch
== NULL_TREE
|| OMP_CLAUSE_CHAIN (ch
) != c
)
8625 poly_int64 bitsize
, bitpos
;
8627 int unsignedp
, reversep
, volatilep
= 0;
8628 tree base
= OMP_CLAUSE_DECL (c
);
8629 while (TREE_CODE (base
) == ARRAY_REF
)
8630 base
= TREE_OPERAND (base
, 0);
8631 if (TREE_CODE (base
) == INDIRECT_REF
)
8632 base
= TREE_OPERAND (base
, 0);
8633 base
= get_inner_reference (base
, &bitsize
, &bitpos
, &offset
,
8634 &mode
, &unsignedp
, &reversep
,
8636 tree orig_base
= base
;
8637 if ((TREE_CODE (base
) == INDIRECT_REF
8638 || (TREE_CODE (base
) == MEM_REF
8639 && integer_zerop (TREE_OPERAND (base
, 1))))
8640 && DECL_P (TREE_OPERAND (base
, 0))
8641 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base
, 0)))
8643 base
= TREE_OPERAND (base
, 0);
8644 gcc_assert (base
== decl
8645 && (offset
== NULL_TREE
8646 || poly_int_tree_p (offset
)));
8649 = splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
8650 bool ptr
= (OMP_CLAUSE_MAP_KIND (c
)
8651 == GOMP_MAP_ALWAYS_POINTER
);
8652 if (n
== NULL
|| (n
->value
& GOVD_MAP
) == 0)
8654 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8656 OMP_CLAUSE_SET_MAP_KIND (l
, GOMP_MAP_STRUCT
);
8657 if (orig_base
!= base
)
8658 OMP_CLAUSE_DECL (l
) = unshare_expr (orig_base
);
8660 OMP_CLAUSE_DECL (l
) = decl
;
8661 OMP_CLAUSE_SIZE (l
) = size_int (1);
8662 if (struct_map_to_clause
== NULL
)
8663 struct_map_to_clause
= new hash_map
<tree
, tree
>;
8664 struct_map_to_clause
->put (decl
, l
);
8667 enum gomp_map_kind mkind
8668 = code
== OMP_TARGET_EXIT_DATA
8669 ? GOMP_MAP_RELEASE
: GOMP_MAP_ALLOC
;
8670 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8672 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
8673 OMP_CLAUSE_DECL (c2
)
8674 = unshare_expr (OMP_CLAUSE_DECL (c
));
8675 OMP_CLAUSE_CHAIN (c2
) = *prev_list_p
;
8676 OMP_CLAUSE_SIZE (c2
)
8677 = TYPE_SIZE_UNIT (ptr_type_node
);
8678 OMP_CLAUSE_CHAIN (l
) = c2
;
8679 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
8681 tree c4
= OMP_CLAUSE_CHAIN (*prev_list_p
);
8683 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8685 OMP_CLAUSE_SET_MAP_KIND (c3
, mkind
);
8686 OMP_CLAUSE_DECL (c3
)
8687 = unshare_expr (OMP_CLAUSE_DECL (c4
));
8688 OMP_CLAUSE_SIZE (c3
)
8689 = TYPE_SIZE_UNIT (ptr_type_node
);
8690 OMP_CLAUSE_CHAIN (c3
) = *prev_list_p
;
8691 OMP_CLAUSE_CHAIN (c2
) = c3
;
8698 OMP_CLAUSE_CHAIN (l
) = c
;
8700 list_p
= &OMP_CLAUSE_CHAIN (l
);
8702 if (orig_base
!= base
&& code
== OMP_TARGET
)
8704 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8706 enum gomp_map_kind mkind
8707 = GOMP_MAP_FIRSTPRIVATE_REFERENCE
;
8708 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
8709 OMP_CLAUSE_DECL (c2
) = decl
;
8710 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
8711 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (l
);
8712 OMP_CLAUSE_CHAIN (l
) = c2
;
8714 flags
= GOVD_MAP
| GOVD_EXPLICIT
;
8715 if (GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) || ptr
)
8721 tree
*osc
= struct_map_to_clause
->get (decl
);
8722 tree
*sc
= NULL
, *scp
= NULL
;
8723 if (GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) || ptr
)
8724 n
->value
|= GOVD_SEEN
;
8725 poly_offset_int o1
, o2
;
8727 o1
= wi::to_poly_offset (offset
);
8730 if (maybe_ne (bitpos
, 0))
8731 o1
+= bits_to_bytes_round_down (bitpos
);
8732 sc
= &OMP_CLAUSE_CHAIN (*osc
);
8734 && (OMP_CLAUSE_MAP_KIND (*sc
)
8735 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
8736 sc
= &OMP_CLAUSE_CHAIN (*sc
);
8737 for (; *sc
!= c
; sc
= &OMP_CLAUSE_CHAIN (*sc
))
8738 if (ptr
&& sc
== prev_list_p
)
8740 else if (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8742 && (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8744 && (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8750 poly_int64 bitsize2
, bitpos2
;
8751 base
= OMP_CLAUSE_DECL (*sc
);
8752 if (TREE_CODE (base
) == ARRAY_REF
)
8754 while (TREE_CODE (base
) == ARRAY_REF
)
8755 base
= TREE_OPERAND (base
, 0);
8756 if (TREE_CODE (base
) != COMPONENT_REF
8757 || (TREE_CODE (TREE_TYPE (base
))
8761 else if (TREE_CODE (base
) == INDIRECT_REF
8762 && (TREE_CODE (TREE_OPERAND (base
, 0))
8764 && (TREE_CODE (TREE_TYPE
8765 (TREE_OPERAND (base
, 0)))
8767 base
= TREE_OPERAND (base
, 0);
8768 base
= get_inner_reference (base
, &bitsize2
,
8771 &reversep
, &volatilep
);
8772 if ((TREE_CODE (base
) == INDIRECT_REF
8773 || (TREE_CODE (base
) == MEM_REF
8774 && integer_zerop (TREE_OPERAND (base
,
8776 && DECL_P (TREE_OPERAND (base
, 0))
8777 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base
,
8780 base
= TREE_OPERAND (base
, 0);
8785 gcc_assert (offset
== NULL_TREE
8786 || poly_int_tree_p (offset
));
8787 tree d1
= OMP_CLAUSE_DECL (*sc
);
8788 tree d2
= OMP_CLAUSE_DECL (c
);
8789 while (TREE_CODE (d1
) == ARRAY_REF
)
8790 d1
= TREE_OPERAND (d1
, 0);
8791 while (TREE_CODE (d2
) == ARRAY_REF
)
8792 d2
= TREE_OPERAND (d2
, 0);
8793 if (TREE_CODE (d1
) == INDIRECT_REF
)
8794 d1
= TREE_OPERAND (d1
, 0);
8795 if (TREE_CODE (d2
) == INDIRECT_REF
)
8796 d2
= TREE_OPERAND (d2
, 0);
8797 while (TREE_CODE (d1
) == COMPONENT_REF
)
8798 if (TREE_CODE (d2
) == COMPONENT_REF
8799 && TREE_OPERAND (d1
, 1)
8800 == TREE_OPERAND (d2
, 1))
8802 d1
= TREE_OPERAND (d1
, 0);
8803 d2
= TREE_OPERAND (d2
, 0);
8809 error_at (OMP_CLAUSE_LOCATION (c
),
8810 "%qE appears more than once in map "
8811 "clauses", OMP_CLAUSE_DECL (c
));
8816 o2
= wi::to_poly_offset (offset2
);
8819 o2
+= bits_to_bytes_round_down (bitpos2
);
8820 if (maybe_lt (o1
, o2
)
8821 || (known_eq (o1
, o2
)
8822 && maybe_lt (bitpos
, bitpos2
)))
8832 OMP_CLAUSE_SIZE (*osc
)
8833 = size_binop (PLUS_EXPR
, OMP_CLAUSE_SIZE (*osc
),
8837 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8839 tree cl
= NULL_TREE
;
8840 enum gomp_map_kind mkind
8841 = code
== OMP_TARGET_EXIT_DATA
8842 ? GOMP_MAP_RELEASE
: GOMP_MAP_ALLOC
;
8843 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
8844 OMP_CLAUSE_DECL (c2
)
8845 = unshare_expr (OMP_CLAUSE_DECL (c
));
8846 OMP_CLAUSE_CHAIN (c2
) = scp
? *scp
: *prev_list_p
;
8847 OMP_CLAUSE_SIZE (c2
)
8848 = TYPE_SIZE_UNIT (ptr_type_node
);
8849 cl
= scp
? *prev_list_p
: c2
;
8850 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
8852 tree c4
= OMP_CLAUSE_CHAIN (*prev_list_p
);
8854 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8856 OMP_CLAUSE_SET_MAP_KIND (c3
, mkind
);
8857 OMP_CLAUSE_DECL (c3
)
8858 = unshare_expr (OMP_CLAUSE_DECL (c4
));
8859 OMP_CLAUSE_SIZE (c3
)
8860 = TYPE_SIZE_UNIT (ptr_type_node
);
8861 OMP_CLAUSE_CHAIN (c3
) = *prev_list_p
;
8863 OMP_CLAUSE_CHAIN (c2
) = c3
;
8869 if (sc
== prev_list_p
)
8876 *prev_list_p
= OMP_CLAUSE_CHAIN (c
);
8877 list_p
= prev_list_p
;
8879 OMP_CLAUSE_CHAIN (c
) = *sc
;
8886 *list_p
= OMP_CLAUSE_CHAIN (c
);
8887 OMP_CLAUSE_CHAIN (c
) = *sc
;
8894 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ALWAYS_POINTER
8895 && OMP_CLAUSE_CHAIN (c
)
8896 && OMP_CLAUSE_CODE (OMP_CLAUSE_CHAIN (c
)) == OMP_CLAUSE_MAP
8897 && (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c
))
8898 == GOMP_MAP_ALWAYS_POINTER
))
8899 prev_list_p
= list_p
;
8902 flags
= GOVD_MAP
| GOVD_EXPLICIT
;
8903 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_TO
8904 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_TOFROM
)
8905 flags
|= GOVD_MAP_ALWAYS_TO
;
8908 case OMP_CLAUSE_DEPEND
:
8909 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
8911 tree deps
= OMP_CLAUSE_DECL (c
);
8912 while (deps
&& TREE_CODE (deps
) == TREE_LIST
)
8914 if (TREE_CODE (TREE_PURPOSE (deps
)) == TRUNC_DIV_EXPR
8915 && DECL_P (TREE_OPERAND (TREE_PURPOSE (deps
), 1)))
8916 gimplify_expr (&TREE_OPERAND (TREE_PURPOSE (deps
), 1),
8917 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8918 deps
= TREE_CHAIN (deps
);
8922 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
)
8924 if (handled_depend_iterators
== -1)
8925 handled_depend_iterators
= gimplify_omp_depend (list_p
, pre_p
);
8926 if (handled_depend_iterators
)
8928 if (handled_depend_iterators
== 2)
8932 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPOUND_EXPR
)
8934 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0), pre_p
,
8935 NULL
, is_gimple_val
, fb_rvalue
);
8936 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (OMP_CLAUSE_DECL (c
), 1);
8938 if (error_operand_p (OMP_CLAUSE_DECL (c
)))
8943 OMP_CLAUSE_DECL (c
) = build_fold_addr_expr (OMP_CLAUSE_DECL (c
));
8944 if (gimplify_expr (&OMP_CLAUSE_DECL (c
), pre_p
, NULL
,
8945 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8953 case OMP_CLAUSE_FROM
:
8954 case OMP_CLAUSE__CACHE_
:
8955 decl
= OMP_CLAUSE_DECL (c
);
8956 if (error_operand_p (decl
))
8961 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8962 OMP_CLAUSE_SIZE (c
) = DECL_P (decl
) ? DECL_SIZE_UNIT (decl
)
8963 : TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8964 if (gimplify_expr (&OMP_CLAUSE_SIZE (c
), pre_p
,
8965 NULL
, is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8972 if (gimplify_expr (&OMP_CLAUSE_DECL (c
), pre_p
,
8973 NULL
, is_gimple_lvalue
, fb_lvalue
)
8983 case OMP_CLAUSE_USE_DEVICE_PTR
:
8984 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
8986 case OMP_CLAUSE_IS_DEVICE_PTR
:
8987 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
8991 decl
= OMP_CLAUSE_DECL (c
);
8993 if (error_operand_p (decl
))
8998 if (DECL_NAME (decl
) == NULL_TREE
&& (flags
& GOVD_SHARED
) == 0)
9000 tree t
= omp_member_access_dummy_var (decl
);
9003 tree v
= DECL_VALUE_EXPR (decl
);
9004 DECL_NAME (decl
) = DECL_NAME (TREE_OPERAND (v
, 1));
9006 omp_notice_variable (outer_ctx
, t
, true);
9009 if (code
== OACC_DATA
9010 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
9011 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
9012 flags
|= GOVD_MAP_0LEN_ARRAY
;
9013 omp_add_variable (ctx
, decl
, flags
);
9014 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
9015 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
9016 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
9017 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
9019 omp_add_variable (ctx
, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
),
9020 GOVD_LOCAL
| GOVD_SEEN
);
9021 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
9022 && walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
9024 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
),
9026 omp_add_variable (ctx
,
9027 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
),
9028 GOVD_LOCAL
| GOVD_SEEN
);
9029 gimplify_omp_ctxp
= ctx
;
9030 push_gimplify_context ();
9032 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
) = NULL
;
9033 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
9035 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c
),
9036 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
));
9037 pop_gimplify_context
9038 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
)));
9039 push_gimplify_context ();
9040 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c
),
9041 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
));
9042 pop_gimplify_context
9043 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
)));
9044 OMP_CLAUSE_REDUCTION_INIT (c
) = NULL_TREE
;
9045 OMP_CLAUSE_REDUCTION_MERGE (c
) = NULL_TREE
;
9047 gimplify_omp_ctxp
= outer_ctx
;
9049 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9050 && OMP_CLAUSE_LASTPRIVATE_STMT (c
))
9052 gimplify_omp_ctxp
= ctx
;
9053 push_gimplify_context ();
9054 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c
)) != BIND_EXPR
)
9056 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
,
9058 TREE_SIDE_EFFECTS (bind
) = 1;
9059 BIND_EXPR_BODY (bind
) = OMP_CLAUSE_LASTPRIVATE_STMT (c
);
9060 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = bind
;
9062 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c
),
9063 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
));
9064 pop_gimplify_context
9065 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
)));
9066 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = NULL_TREE
;
9068 gimplify_omp_ctxp
= outer_ctx
;
9070 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
9071 && OMP_CLAUSE_LINEAR_STMT (c
))
9073 gimplify_omp_ctxp
= ctx
;
9074 push_gimplify_context ();
9075 if (TREE_CODE (OMP_CLAUSE_LINEAR_STMT (c
)) != BIND_EXPR
)
9077 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
,
9079 TREE_SIDE_EFFECTS (bind
) = 1;
9080 BIND_EXPR_BODY (bind
) = OMP_CLAUSE_LINEAR_STMT (c
);
9081 OMP_CLAUSE_LINEAR_STMT (c
) = bind
;
9083 gimplify_and_add (OMP_CLAUSE_LINEAR_STMT (c
),
9084 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
));
9085 pop_gimplify_context
9086 (gimple_seq_first_stmt (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
)));
9087 OMP_CLAUSE_LINEAR_STMT (c
) = NULL_TREE
;
9089 gimplify_omp_ctxp
= outer_ctx
;
9095 case OMP_CLAUSE_COPYIN
:
9096 case OMP_CLAUSE_COPYPRIVATE
:
9097 decl
= OMP_CLAUSE_DECL (c
);
9098 if (error_operand_p (decl
))
9103 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_COPYPRIVATE
9105 && !omp_check_private (ctx
, decl
, true))
9108 if (is_global_var (decl
))
9110 if (DECL_THREAD_LOCAL_P (decl
))
9112 else if (DECL_HAS_VALUE_EXPR_P (decl
))
9114 tree value
= get_base_address (DECL_VALUE_EXPR (decl
));
9118 && DECL_THREAD_LOCAL_P (value
))
9123 error_at (OMP_CLAUSE_LOCATION (c
),
9124 "copyprivate variable %qE is not threadprivate"
9125 " or private in outer context", DECL_NAME (decl
));
9128 if ((region_type
& ORT_TASKLOOP
) == ORT_TASKLOOP
9130 && outer_ctx
->region_type
== ORT_COMBINED_PARALLEL
9131 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
9132 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
9133 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
))
9136 = splay_tree_lookup (outer_ctx
->variables
,
9137 (splay_tree_key
)decl
);
9138 if (on
== NULL
|| (on
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
9140 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
9141 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
9142 && (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
9143 || (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
9144 && (TREE_CODE (TREE_TYPE (TREE_TYPE (decl
)))
9146 omp_firstprivatize_variable (outer_ctx
, decl
);
9148 omp_add_variable (outer_ctx
, decl
,
9149 GOVD_SEEN
| GOVD_SHARED
);
9150 omp_notice_variable (outer_ctx
, decl
, true);
9154 omp_notice_variable (outer_ctx
, decl
, true);
9155 if (check_non_private
9156 && region_type
== ORT_WORKSHARE
9157 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
9158 || decl
== OMP_CLAUSE_DECL (c
)
9159 || (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
9160 && (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0))
9162 || (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0))
9163 == POINTER_PLUS_EXPR
9164 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND
9165 (OMP_CLAUSE_DECL (c
), 0), 0))
9167 && omp_check_private (ctx
, decl
, false))
9169 error ("%s variable %qE is private in outer context",
9170 check_non_private
, DECL_NAME (decl
));
9176 if (OMP_CLAUSE_IF_MODIFIER (c
) != ERROR_MARK
9177 && OMP_CLAUSE_IF_MODIFIER (c
) != code
)
9180 for (int i
= 0; i
< 2; i
++)
9181 switch (i
? OMP_CLAUSE_IF_MODIFIER (c
) : code
)
9183 case VOID_CST
: p
[i
] = "cancel"; break;
9184 case OMP_PARALLEL
: p
[i
] = "parallel"; break;
9185 case OMP_SIMD
: p
[i
] = "simd"; break;
9186 case OMP_TASK
: p
[i
] = "task"; break;
9187 case OMP_TASKLOOP
: p
[i
] = "taskloop"; break;
9188 case OMP_TARGET_DATA
: p
[i
] = "target data"; break;
9189 case OMP_TARGET
: p
[i
] = "target"; break;
9190 case OMP_TARGET_UPDATE
: p
[i
] = "target update"; break;
9191 case OMP_TARGET_ENTER_DATA
:
9192 p
[i
] = "target enter data"; break;
9193 case OMP_TARGET_EXIT_DATA
: p
[i
] = "target exit data"; break;
9194 default: gcc_unreachable ();
9196 error_at (OMP_CLAUSE_LOCATION (c
),
9197 "expected %qs %<if%> clause modifier rather than %qs",
9203 case OMP_CLAUSE_FINAL
:
9204 OMP_CLAUSE_OPERAND (c
, 0)
9205 = gimple_boolify (OMP_CLAUSE_OPERAND (c
, 0));
9208 case OMP_CLAUSE_SCHEDULE
:
9209 case OMP_CLAUSE_NUM_THREADS
:
9210 case OMP_CLAUSE_NUM_TEAMS
:
9211 case OMP_CLAUSE_THREAD_LIMIT
:
9212 case OMP_CLAUSE_DIST_SCHEDULE
:
9213 case OMP_CLAUSE_DEVICE
:
9214 case OMP_CLAUSE_PRIORITY
:
9215 case OMP_CLAUSE_GRAINSIZE
:
9216 case OMP_CLAUSE_NUM_TASKS
:
9217 case OMP_CLAUSE_HINT
:
9218 case OMP_CLAUSE_ASYNC
:
9219 case OMP_CLAUSE_WAIT
:
9220 case OMP_CLAUSE_NUM_GANGS
:
9221 case OMP_CLAUSE_NUM_WORKERS
:
9222 case OMP_CLAUSE_VECTOR_LENGTH
:
9223 case OMP_CLAUSE_WORKER
:
9224 case OMP_CLAUSE_VECTOR
:
9225 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 0), pre_p
, NULL
,
9226 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
9230 case OMP_CLAUSE_GANG
:
9231 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 0), pre_p
, NULL
,
9232 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
9234 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 1), pre_p
, NULL
,
9235 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
9239 case OMP_CLAUSE_NOWAIT
:
9243 case OMP_CLAUSE_ORDERED
:
9244 case OMP_CLAUSE_UNTIED
:
9245 case OMP_CLAUSE_COLLAPSE
:
9246 case OMP_CLAUSE_TILE
:
9247 case OMP_CLAUSE_AUTO
:
9248 case OMP_CLAUSE_SEQ
:
9249 case OMP_CLAUSE_INDEPENDENT
:
9250 case OMP_CLAUSE_MERGEABLE
:
9251 case OMP_CLAUSE_PROC_BIND
:
9252 case OMP_CLAUSE_SAFELEN
:
9253 case OMP_CLAUSE_SIMDLEN
:
9254 case OMP_CLAUSE_NOGROUP
:
9255 case OMP_CLAUSE_THREADS
:
9256 case OMP_CLAUSE_SIMD
:
9257 case OMP_CLAUSE_IF_PRESENT
:
9258 case OMP_CLAUSE_FINALIZE
:
9261 case OMP_CLAUSE_DEFAULTMAP
:
9262 enum gimplify_defaultmap_kind gdmkmin
, gdmkmax
;
9263 switch (OMP_CLAUSE_DEFAULTMAP_CATEGORY (c
))
9265 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED
:
9266 gdmkmin
= GDMK_SCALAR
;
9267 gdmkmax
= GDMK_POINTER
;
9269 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR
:
9270 gdmkmin
= gdmkmax
= GDMK_SCALAR
;
9272 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE
:
9273 gdmkmin
= gdmkmax
= GDMK_AGGREGATE
;
9275 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE
:
9276 gdmkmin
= gdmkmax
= GDMK_ALLOCATABLE
;
9278 case OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER
:
9279 gdmkmin
= gdmkmax
= GDMK_POINTER
;
9284 for (int gdmk
= gdmkmin
; gdmk
<= gdmkmax
; gdmk
++)
9285 switch (OMP_CLAUSE_DEFAULTMAP_BEHAVIOR (c
))
9287 case OMP_CLAUSE_DEFAULTMAP_ALLOC
:
9288 ctx
->defaultmap
[gdmk
] = GOVD_MAP
| GOVD_MAP_ALLOC_ONLY
;
9290 case OMP_CLAUSE_DEFAULTMAP_TO
:
9291 ctx
->defaultmap
[gdmk
] = GOVD_MAP
| GOVD_MAP_TO_ONLY
;
9293 case OMP_CLAUSE_DEFAULTMAP_FROM
:
9294 ctx
->defaultmap
[gdmk
] = GOVD_MAP
| GOVD_MAP_FROM_ONLY
;
9296 case OMP_CLAUSE_DEFAULTMAP_TOFROM
:
9297 ctx
->defaultmap
[gdmk
] = GOVD_MAP
;
9299 case OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE
:
9300 ctx
->defaultmap
[gdmk
] = GOVD_FIRSTPRIVATE
;
9302 case OMP_CLAUSE_DEFAULTMAP_NONE
:
9303 ctx
->defaultmap
[gdmk
] = 0;
9305 case OMP_CLAUSE_DEFAULTMAP_DEFAULT
:
9309 ctx
->defaultmap
[gdmk
] = GOVD_FIRSTPRIVATE
;
9311 case GDMK_AGGREGATE
:
9312 case GDMK_ALLOCATABLE
:
9313 ctx
->defaultmap
[gdmk
] = GOVD_MAP
;
9316 ctx
->defaultmap
[gdmk
] = GOVD_MAP
| GOVD_MAP_0LEN_ARRAY
;
9327 case OMP_CLAUSE_ALIGNED
:
9328 decl
= OMP_CLAUSE_DECL (c
);
9329 if (error_operand_p (decl
))
9334 if (gimplify_expr (&OMP_CLAUSE_ALIGNED_ALIGNMENT (c
), pre_p
, NULL
,
9335 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
9340 if (!is_global_var (decl
)
9341 && TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
9342 omp_add_variable (ctx
, decl
, GOVD_ALIGNED
);
9345 case OMP_CLAUSE_NONTEMPORAL
:
9346 decl
= OMP_CLAUSE_DECL (c
);
9347 if (error_operand_p (decl
))
9352 omp_add_variable (ctx
, decl
, GOVD_NONTEMPORAL
);
9355 case OMP_CLAUSE_DEFAULT
:
9356 ctx
->default_kind
= OMP_CLAUSE_DEFAULT_KIND (c
);
9359 case OMP_CLAUSE_INCLUSIVE
:
9360 case OMP_CLAUSE_EXCLUSIVE
:
9361 decl
= OMP_CLAUSE_DECL (c
);
9363 splay_tree_node n
= splay_tree_lookup (outer_ctx
->variables
,
9364 (splay_tree_key
) decl
);
9365 if (n
== NULL
|| (n
->value
& GOVD_REDUCTION
) == 0)
9367 error_at (OMP_CLAUSE_LOCATION (c
),
9368 "%qD specified in %qs clause but not in %<inscan%> "
9369 "%<reduction%> clause on the containing construct",
9370 decl
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
9375 n
->value
|= GOVD_REDUCTION_INSCAN
;
9376 if (outer_ctx
->region_type
== ORT_SIMD
9377 && outer_ctx
->outer_context
9378 && outer_ctx
->outer_context
->region_type
== ORT_WORKSHARE
)
9380 n
= splay_tree_lookup (outer_ctx
->outer_context
->variables
,
9381 (splay_tree_key
) decl
);
9382 if (n
&& (n
->value
& GOVD_REDUCTION
) != 0)
9383 n
->value
|= GOVD_REDUCTION_INSCAN
;
9393 if (code
== OACC_DATA
9394 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
9395 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
9396 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
9399 *list_p
= OMP_CLAUSE_CHAIN (c
);
9401 list_p
= &OMP_CLAUSE_CHAIN (c
);
9404 ctx
->clauses
= *orig_list_p
;
9405 gimplify_omp_ctxp
= ctx
;
9406 if (struct_map_to_clause
)
9407 delete struct_map_to_clause
;
9410 /* Return true if DECL is a candidate for shared to firstprivate
9411 optimization. We only consider non-addressable scalars, not
9412 too big, and not references. */
9415 omp_shared_to_firstprivate_optimizable_decl_p (tree decl
)
9417 if (TREE_ADDRESSABLE (decl
))
9419 tree type
= TREE_TYPE (decl
);
9420 if (!is_gimple_reg_type (type
)
9421 || TREE_CODE (type
) == REFERENCE_TYPE
9422 || TREE_ADDRESSABLE (type
))
9424 /* Don't optimize too large decls, as each thread/task will have
9426 HOST_WIDE_INT len
= int_size_in_bytes (type
);
9427 if (len
== -1 || len
> 4 * POINTER_SIZE
/ BITS_PER_UNIT
)
9429 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
9434 /* Helper function of omp_find_stores_op and gimplify_adjust_omp_clauses*.
9435 For omp_shared_to_firstprivate_optimizable_decl_p decl mark it as
9436 GOVD_WRITTEN in outer contexts. */
9439 omp_mark_stores (struct gimplify_omp_ctx
*ctx
, tree decl
)
9441 for (; ctx
; ctx
= ctx
->outer_context
)
9443 splay_tree_node n
= splay_tree_lookup (ctx
->variables
,
9444 (splay_tree_key
) decl
);
9447 else if (n
->value
& GOVD_SHARED
)
9449 n
->value
|= GOVD_WRITTEN
;
9452 else if (n
->value
& GOVD_DATA_SHARE_CLASS
)
9457 /* Helper callback for walk_gimple_seq to discover possible stores
9458 to omp_shared_to_firstprivate_optimizable_decl_p decls and set
9459 GOVD_WRITTEN if they are GOVD_SHARED in some outer context
9463 omp_find_stores_op (tree
*tp
, int *walk_subtrees
, void *data
)
9465 struct walk_stmt_info
*wi
= (struct walk_stmt_info
*) data
;
9474 if (handled_component_p (op
))
9475 op
= TREE_OPERAND (op
, 0);
9476 else if ((TREE_CODE (op
) == MEM_REF
|| TREE_CODE (op
) == TARGET_MEM_REF
)
9477 && TREE_CODE (TREE_OPERAND (op
, 0)) == ADDR_EXPR
)
9478 op
= TREE_OPERAND (TREE_OPERAND (op
, 0), 0);
9483 if (!DECL_P (op
) || !omp_shared_to_firstprivate_optimizable_decl_p (op
))
9486 omp_mark_stores (gimplify_omp_ctxp
, op
);
9490 /* Helper callback for walk_gimple_seq to discover possible stores
9491 to omp_shared_to_firstprivate_optimizable_decl_p decls and set
9492 GOVD_WRITTEN if they are GOVD_SHARED in some outer context
9496 omp_find_stores_stmt (gimple_stmt_iterator
*gsi_p
,
9497 bool *handled_ops_p
,
9498 struct walk_stmt_info
*wi
)
9500 gimple
*stmt
= gsi_stmt (*gsi_p
);
9501 switch (gimple_code (stmt
))
9503 /* Don't recurse on OpenMP constructs for which
9504 gimplify_adjust_omp_clauses already handled the bodies,
9505 except handle gimple_omp_for_pre_body. */
9506 case GIMPLE_OMP_FOR
:
9507 *handled_ops_p
= true;
9508 if (gimple_omp_for_pre_body (stmt
))
9509 walk_gimple_seq (gimple_omp_for_pre_body (stmt
),
9510 omp_find_stores_stmt
, omp_find_stores_op
, wi
);
9512 case GIMPLE_OMP_PARALLEL
:
9513 case GIMPLE_OMP_TASK
:
9514 case GIMPLE_OMP_SECTIONS
:
9515 case GIMPLE_OMP_SINGLE
:
9516 case GIMPLE_OMP_TARGET
:
9517 case GIMPLE_OMP_TEAMS
:
9518 case GIMPLE_OMP_CRITICAL
:
9519 *handled_ops_p
= true;
9527 struct gimplify_adjust_omp_clauses_data
9533 /* For all variables that were not actually used within the context,
9534 remove PRIVATE, SHARED, and FIRSTPRIVATE clauses. */
9537 gimplify_adjust_omp_clauses_1 (splay_tree_node n
, void *data
)
9539 tree
*list_p
= ((struct gimplify_adjust_omp_clauses_data
*) data
)->list_p
;
9541 = ((struct gimplify_adjust_omp_clauses_data
*) data
)->pre_p
;
9542 tree decl
= (tree
) n
->key
;
9543 unsigned flags
= n
->value
;
9544 enum omp_clause_code code
;
9548 if (gimplify_omp_ctxp
->region_type
== ORT_COMBINED_PARALLEL
9549 && (flags
& GOVD_LASTPRIVATE_CONDITIONAL
) != 0)
9550 flags
= GOVD_SHARED
| GOVD_SEEN
| GOVD_WRITTEN
;
9551 if (flags
& (GOVD_EXPLICIT
| GOVD_LOCAL
))
9553 if ((flags
& GOVD_SEEN
) == 0)
9555 if (flags
& GOVD_DEBUG_PRIVATE
)
9557 gcc_assert ((flags
& GOVD_DATA_SHARE_CLASS
) == GOVD_SHARED
);
9558 private_debug
= true;
9560 else if (flags
& GOVD_MAP
)
9561 private_debug
= false;
9564 = lang_hooks
.decls
.omp_private_debug_clause (decl
,
9565 !!(flags
& GOVD_SHARED
));
9567 code
= OMP_CLAUSE_PRIVATE
;
9568 else if (flags
& GOVD_MAP
)
9570 code
= OMP_CLAUSE_MAP
;
9571 if ((gimplify_omp_ctxp
->region_type
& ORT_ACC
) == 0
9572 && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl
))))
9574 error ("%<_Atomic%> %qD in implicit %<map%> clause", decl
);
9578 else if (flags
& GOVD_SHARED
)
9580 if (is_global_var (decl
))
9582 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
->outer_context
;
9586 = splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9587 if (on
&& (on
->value
& (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
9588 | GOVD_PRIVATE
| GOVD_REDUCTION
9589 | GOVD_LINEAR
| GOVD_MAP
)) != 0)
9591 ctx
= ctx
->outer_context
;
9596 code
= OMP_CLAUSE_SHARED
;
9598 else if (flags
& GOVD_PRIVATE
)
9599 code
= OMP_CLAUSE_PRIVATE
;
9600 else if (flags
& GOVD_FIRSTPRIVATE
)
9602 code
= OMP_CLAUSE_FIRSTPRIVATE
;
9603 if ((gimplify_omp_ctxp
->region_type
& ORT_TARGET
)
9604 && (gimplify_omp_ctxp
->region_type
& ORT_ACC
) == 0
9605 && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl
))))
9607 error ("%<_Atomic%> %qD in implicit %<firstprivate%> clause on "
9608 "%<target%> construct", decl
);
9612 else if (flags
& GOVD_LASTPRIVATE
)
9613 code
= OMP_CLAUSE_LASTPRIVATE
;
9614 else if (flags
& (GOVD_ALIGNED
| GOVD_NONTEMPORAL
))
9616 else if (flags
& GOVD_CONDTEMP
)
9618 code
= OMP_CLAUSE__CONDTEMP_
;
9619 gimple_add_tmp_var (decl
);
9624 if (((flags
& GOVD_LASTPRIVATE
)
9625 || (code
== OMP_CLAUSE_SHARED
&& (flags
& GOVD_WRITTEN
)))
9626 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9627 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9629 tree chain
= *list_p
;
9630 clause
= build_omp_clause (input_location
, code
);
9631 OMP_CLAUSE_DECL (clause
) = decl
;
9632 OMP_CLAUSE_CHAIN (clause
) = chain
;
9634 OMP_CLAUSE_PRIVATE_DEBUG (clause
) = 1;
9635 else if (code
== OMP_CLAUSE_PRIVATE
&& (flags
& GOVD_PRIVATE_OUTER_REF
))
9636 OMP_CLAUSE_PRIVATE_OUTER_REF (clause
) = 1;
9637 else if (code
== OMP_CLAUSE_SHARED
9638 && (flags
& GOVD_WRITTEN
) == 0
9639 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9640 OMP_CLAUSE_SHARED_READONLY (clause
) = 1;
9641 else if (code
== OMP_CLAUSE_FIRSTPRIVATE
&& (flags
& GOVD_EXPLICIT
) == 0)
9642 OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause
) = 1;
9643 else if (code
== OMP_CLAUSE_MAP
&& (flags
& GOVD_MAP_0LEN_ARRAY
) != 0)
9645 tree nc
= build_omp_clause (input_location
, OMP_CLAUSE_MAP
);
9646 OMP_CLAUSE_DECL (nc
) = decl
;
9647 if (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
9648 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) == POINTER_TYPE
)
9649 OMP_CLAUSE_DECL (clause
)
9650 = build_simple_mem_ref_loc (input_location
, decl
);
9651 OMP_CLAUSE_DECL (clause
)
9652 = build2 (MEM_REF
, char_type_node
, OMP_CLAUSE_DECL (clause
),
9653 build_int_cst (build_pointer_type (char_type_node
), 0));
9654 OMP_CLAUSE_SIZE (clause
) = size_zero_node
;
9655 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
9656 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_ALLOC
);
9657 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (clause
) = 1;
9658 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
9659 OMP_CLAUSE_CHAIN (nc
) = chain
;
9660 OMP_CLAUSE_CHAIN (clause
) = nc
;
9661 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
9662 gimplify_omp_ctxp
= ctx
->outer_context
;
9663 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (clause
), 0),
9664 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9665 gimplify_omp_ctxp
= ctx
;
9667 else if (code
== OMP_CLAUSE_MAP
)
9670 /* Not all combinations of these GOVD_MAP flags are actually valid. */
9671 switch (flags
& (GOVD_MAP_TO_ONLY
9673 | GOVD_MAP_FORCE_PRESENT
9674 | GOVD_MAP_ALLOC_ONLY
9675 | GOVD_MAP_FROM_ONLY
))
9678 kind
= GOMP_MAP_TOFROM
;
9680 case GOVD_MAP_FORCE
:
9681 kind
= GOMP_MAP_TOFROM
| GOMP_MAP_FLAG_FORCE
;
9683 case GOVD_MAP_TO_ONLY
:
9686 case GOVD_MAP_FROM_ONLY
:
9687 kind
= GOMP_MAP_FROM
;
9689 case GOVD_MAP_ALLOC_ONLY
:
9690 kind
= GOMP_MAP_ALLOC
;
9692 case GOVD_MAP_TO_ONLY
| GOVD_MAP_FORCE
:
9693 kind
= GOMP_MAP_TO
| GOMP_MAP_FLAG_FORCE
;
9695 case GOVD_MAP_FORCE_PRESENT
:
9696 kind
= GOMP_MAP_FORCE_PRESENT
;
9701 OMP_CLAUSE_SET_MAP_KIND (clause
, kind
);
9702 if (DECL_SIZE (decl
)
9703 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
9705 tree decl2
= DECL_VALUE_EXPR (decl
);
9706 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
9707 decl2
= TREE_OPERAND (decl2
, 0);
9708 gcc_assert (DECL_P (decl2
));
9709 tree mem
= build_simple_mem_ref (decl2
);
9710 OMP_CLAUSE_DECL (clause
) = mem
;
9711 OMP_CLAUSE_SIZE (clause
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
9712 if (gimplify_omp_ctxp
->outer_context
)
9714 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
->outer_context
;
9715 omp_notice_variable (ctx
, decl2
, true);
9716 omp_notice_variable (ctx
, OMP_CLAUSE_SIZE (clause
), true);
9718 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
),
9720 OMP_CLAUSE_DECL (nc
) = decl
;
9721 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
9722 if (gimplify_omp_ctxp
->target_firstprivatize_array_bases
)
9723 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
9725 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_POINTER
);
9726 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (clause
);
9727 OMP_CLAUSE_CHAIN (clause
) = nc
;
9729 else if (gimplify_omp_ctxp
->target_firstprivatize_array_bases
9730 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
9732 OMP_CLAUSE_DECL (clause
) = build_simple_mem_ref (decl
);
9733 OMP_CLAUSE_SIZE (clause
)
9734 = unshare_expr (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
))));
9735 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
9736 gimplify_omp_ctxp
= ctx
->outer_context
;
9737 gimplify_expr (&OMP_CLAUSE_SIZE (clause
),
9738 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9739 gimplify_omp_ctxp
= ctx
;
9740 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
),
9742 OMP_CLAUSE_DECL (nc
) = decl
;
9743 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
9744 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
9745 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (clause
);
9746 OMP_CLAUSE_CHAIN (clause
) = nc
;
9749 OMP_CLAUSE_SIZE (clause
) = DECL_SIZE_UNIT (decl
);
9751 if (code
== OMP_CLAUSE_FIRSTPRIVATE
&& (flags
& GOVD_LASTPRIVATE
) != 0)
9753 tree nc
= build_omp_clause (input_location
, OMP_CLAUSE_LASTPRIVATE
);
9754 OMP_CLAUSE_DECL (nc
) = decl
;
9755 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (nc
) = 1;
9756 OMP_CLAUSE_CHAIN (nc
) = chain
;
9757 OMP_CLAUSE_CHAIN (clause
) = nc
;
9758 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
9759 gimplify_omp_ctxp
= ctx
->outer_context
;
9760 lang_hooks
.decls
.omp_finish_clause (nc
, pre_p
);
9761 gimplify_omp_ctxp
= ctx
;
9764 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
9765 gimplify_omp_ctxp
= ctx
->outer_context
;
9766 lang_hooks
.decls
.omp_finish_clause (clause
, pre_p
);
9767 if (gimplify_omp_ctxp
)
9768 for (; clause
!= chain
; clause
= OMP_CLAUSE_CHAIN (clause
))
9769 if (OMP_CLAUSE_CODE (clause
) == OMP_CLAUSE_MAP
9770 && DECL_P (OMP_CLAUSE_SIZE (clause
)))
9771 omp_notice_variable (gimplify_omp_ctxp
, OMP_CLAUSE_SIZE (clause
),
9773 gimplify_omp_ctxp
= ctx
;
9778 gimplify_adjust_omp_clauses (gimple_seq
*pre_p
, gimple_seq body
, tree
*list_p
,
9779 enum tree_code code
)
9781 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
9782 tree
*orig_list_p
= list_p
;
9784 bool has_inscan_reductions
= false;
9788 struct gimplify_omp_ctx
*octx
;
9789 for (octx
= ctx
; octx
; octx
= octx
->outer_context
)
9790 if ((octx
->region_type
& (ORT_PARALLEL
| ORT_TASK
| ORT_TEAMS
)) != 0)
9794 struct walk_stmt_info wi
;
9795 memset (&wi
, 0, sizeof (wi
));
9796 walk_gimple_seq (body
, omp_find_stores_stmt
,
9797 omp_find_stores_op
, &wi
);
9801 if (ctx
->region_type
== ORT_WORKSHARE
9802 && ctx
->outer_context
9803 && ctx
->outer_context
->region_type
== ORT_COMBINED_PARALLEL
)
9805 for (c
= ctx
->outer_context
->clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9806 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9807 && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
))
9809 decl
= OMP_CLAUSE_DECL (c
);
9811 = splay_tree_lookup (ctx
->outer_context
->variables
,
9812 (splay_tree_key
) decl
);
9813 gcc_checking_assert (!splay_tree_lookup (ctx
->variables
,
9814 (splay_tree_key
) decl
));
9815 omp_add_variable (ctx
, decl
, n
->value
);
9816 tree c2
= copy_node (c
);
9817 OMP_CLAUSE_CHAIN (c2
) = *list_p
;
9819 if ((n
->value
& GOVD_FIRSTPRIVATE
) == 0)
9821 c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
9822 OMP_CLAUSE_FIRSTPRIVATE
);
9823 OMP_CLAUSE_DECL (c2
) = decl
;
9824 OMP_CLAUSE_CHAIN (c2
) = *list_p
;
9828 while ((c
= *list_p
) != NULL
)
9831 bool remove
= false;
9833 switch (OMP_CLAUSE_CODE (c
))
9835 case OMP_CLAUSE_FIRSTPRIVATE
:
9836 if ((ctx
->region_type
& ORT_TARGET
)
9837 && (ctx
->region_type
& ORT_ACC
) == 0
9838 && TYPE_ATOMIC (strip_array_types
9839 (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
9841 error_at (OMP_CLAUSE_LOCATION (c
),
9842 "%<_Atomic%> %qD in %<firstprivate%> clause on "
9843 "%<target%> construct", OMP_CLAUSE_DECL (c
));
9848 case OMP_CLAUSE_PRIVATE
:
9849 case OMP_CLAUSE_SHARED
:
9850 case OMP_CLAUSE_LINEAR
:
9851 decl
= OMP_CLAUSE_DECL (c
);
9852 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9853 remove
= !(n
->value
& GOVD_SEEN
);
9854 if ((n
->value
& GOVD_LASTPRIVATE_CONDITIONAL
) != 0
9855 && code
== OMP_PARALLEL
9856 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9860 bool shared
= OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
;
9861 if ((n
->value
& GOVD_DEBUG_PRIVATE
)
9862 || lang_hooks
.decls
.omp_private_debug_clause (decl
, shared
))
9864 gcc_assert ((n
->value
& GOVD_DEBUG_PRIVATE
) == 0
9865 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
9867 OMP_CLAUSE_SET_CODE (c
, OMP_CLAUSE_PRIVATE
);
9868 OMP_CLAUSE_PRIVATE_DEBUG (c
) = 1;
9870 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
9871 && (n
->value
& GOVD_WRITTEN
) == 0
9873 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9874 OMP_CLAUSE_SHARED_READONLY (c
) = 1;
9875 else if (DECL_P (decl
)
9876 && ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
9877 && (n
->value
& GOVD_WRITTEN
) != 0)
9878 || (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
9879 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)))
9880 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9881 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9885 case OMP_CLAUSE_LASTPRIVATE
:
9886 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to
9887 accurately reflect the presence of a FIRSTPRIVATE clause. */
9888 decl
= OMP_CLAUSE_DECL (c
);
9889 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9890 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
)
9891 = (n
->value
& GOVD_FIRSTPRIVATE
) != 0;
9892 if (code
== OMP_DISTRIBUTE
9893 && OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
9896 error_at (OMP_CLAUSE_LOCATION (c
),
9897 "same variable used in %<firstprivate%> and "
9898 "%<lastprivate%> clauses on %<distribute%> "
9902 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9904 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9905 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9906 if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
) && code
== OMP_PARALLEL
)
9910 case OMP_CLAUSE_ALIGNED
:
9911 decl
= OMP_CLAUSE_DECL (c
);
9912 if (!is_global_var (decl
))
9914 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9915 remove
= n
== NULL
|| !(n
->value
& GOVD_SEEN
);
9916 if (!remove
&& TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
9918 struct gimplify_omp_ctx
*octx
;
9920 && (n
->value
& (GOVD_DATA_SHARE_CLASS
9921 & ~GOVD_FIRSTPRIVATE
)))
9924 for (octx
= ctx
->outer_context
; octx
;
9925 octx
= octx
->outer_context
)
9927 n
= splay_tree_lookup (octx
->variables
,
9928 (splay_tree_key
) decl
);
9931 if (n
->value
& GOVD_LOCAL
)
9933 /* We have to avoid assigning a shared variable
9934 to itself when trying to add
9935 __builtin_assume_aligned. */
9936 if (n
->value
& GOVD_SHARED
)
9944 else if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9946 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9947 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
9952 case OMP_CLAUSE_NONTEMPORAL
:
9953 decl
= OMP_CLAUSE_DECL (c
);
9954 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9955 remove
= n
== NULL
|| !(n
->value
& GOVD_SEEN
);
9958 case OMP_CLAUSE_MAP
:
9959 if (code
== OMP_TARGET_EXIT_DATA
9960 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
)
9965 decl
= OMP_CLAUSE_DECL (c
);
9966 /* Data clauses associated with acc parallel reductions must be
9967 compatible with present_or_copy. Warn and adjust the clause
9968 if that is not the case. */
9969 if (ctx
->region_type
== ORT_ACC_PARALLEL
)
9971 tree t
= DECL_P (decl
) ? decl
: TREE_OPERAND (decl
, 0);
9975 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
9977 if (n
&& (n
->value
& GOVD_REDUCTION
))
9979 enum gomp_map_kind kind
= OMP_CLAUSE_MAP_KIND (c
);
9981 OMP_CLAUSE_MAP_IN_REDUCTION (c
) = 1;
9982 if ((kind
& GOMP_MAP_TOFROM
) != GOMP_MAP_TOFROM
9983 && kind
!= GOMP_MAP_FORCE_PRESENT
9984 && kind
!= GOMP_MAP_POINTER
)
9986 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
9987 "incompatible data clause with reduction "
9988 "on %qE; promoting to %<present_or_copy%>",
9990 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TOFROM
);
9996 if ((ctx
->region_type
& ORT_TARGET
) != 0
9997 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
9999 if (TREE_CODE (decl
) == INDIRECT_REF
10000 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
10001 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
10002 == REFERENCE_TYPE
))
10003 decl
= TREE_OPERAND (decl
, 0);
10004 if (TREE_CODE (decl
) == COMPONENT_REF
)
10006 while (TREE_CODE (decl
) == COMPONENT_REF
)
10007 decl
= TREE_OPERAND (decl
, 0);
10010 n
= splay_tree_lookup (ctx
->variables
,
10011 (splay_tree_key
) decl
);
10012 if (!(n
->value
& GOVD_SEEN
))
10019 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
10020 if ((ctx
->region_type
& ORT_TARGET
) != 0
10021 && !(n
->value
& GOVD_SEEN
)
10022 && GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) == 0
10023 && (!is_global_var (decl
)
10024 || !lookup_attribute ("omp declare target link",
10025 DECL_ATTRIBUTES (decl
))))
10028 /* For struct element mapping, if struct is never referenced
10029 in target block and none of the mapping has always modifier,
10030 remove all the struct element mappings, which immediately
10031 follow the GOMP_MAP_STRUCT map clause. */
10032 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_STRUCT
)
10034 HOST_WIDE_INT cnt
= tree_to_shwi (OMP_CLAUSE_SIZE (c
));
10036 OMP_CLAUSE_CHAIN (c
)
10037 = OMP_CLAUSE_CHAIN (OMP_CLAUSE_CHAIN (c
));
10040 else if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_STRUCT
10041 && code
== OMP_TARGET_EXIT_DATA
)
10043 else if (DECL_SIZE (decl
)
10044 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
10045 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_POINTER
10046 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FIRSTPRIVATE_POINTER
10047 && (OMP_CLAUSE_MAP_KIND (c
)
10048 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
10050 /* For GOMP_MAP_FORCE_DEVICEPTR, we'll never enter here, because
10051 for these, TREE_CODE (DECL_SIZE (decl)) will always be
10053 gcc_assert (OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FORCE_DEVICEPTR
);
10055 tree decl2
= DECL_VALUE_EXPR (decl
);
10056 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
10057 decl2
= TREE_OPERAND (decl2
, 0);
10058 gcc_assert (DECL_P (decl2
));
10059 tree mem
= build_simple_mem_ref (decl2
);
10060 OMP_CLAUSE_DECL (c
) = mem
;
10061 OMP_CLAUSE_SIZE (c
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
10062 if (ctx
->outer_context
)
10064 omp_notice_variable (ctx
->outer_context
, decl2
, true);
10065 omp_notice_variable (ctx
->outer_context
,
10066 OMP_CLAUSE_SIZE (c
), true);
10068 if (((ctx
->region_type
& ORT_TARGET
) != 0
10069 || !ctx
->target_firstprivatize_array_bases
)
10070 && ((n
->value
& GOVD_SEEN
) == 0
10071 || (n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
)) == 0))
10073 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
10075 OMP_CLAUSE_DECL (nc
) = decl
;
10076 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
10077 if (ctx
->target_firstprivatize_array_bases
)
10078 OMP_CLAUSE_SET_MAP_KIND (nc
,
10079 GOMP_MAP_FIRSTPRIVATE_POINTER
);
10081 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_POINTER
);
10082 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (c
);
10083 OMP_CLAUSE_CHAIN (c
) = nc
;
10089 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
10090 OMP_CLAUSE_SIZE (c
) = DECL_SIZE_UNIT (decl
);
10091 gcc_assert ((n
->value
& GOVD_SEEN
) == 0
10092 || ((n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
))
10097 case OMP_CLAUSE_TO
:
10098 case OMP_CLAUSE_FROM
:
10099 case OMP_CLAUSE__CACHE_
:
10100 decl
= OMP_CLAUSE_DECL (c
);
10101 if (!DECL_P (decl
))
10103 if (DECL_SIZE (decl
)
10104 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
10106 tree decl2
= DECL_VALUE_EXPR (decl
);
10107 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
10108 decl2
= TREE_OPERAND (decl2
, 0);
10109 gcc_assert (DECL_P (decl2
));
10110 tree mem
= build_simple_mem_ref (decl2
);
10111 OMP_CLAUSE_DECL (c
) = mem
;
10112 OMP_CLAUSE_SIZE (c
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
10113 if (ctx
->outer_context
)
10115 omp_notice_variable (ctx
->outer_context
, decl2
, true);
10116 omp_notice_variable (ctx
->outer_context
,
10117 OMP_CLAUSE_SIZE (c
), true);
10120 else if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
10121 OMP_CLAUSE_SIZE (c
) = DECL_SIZE_UNIT (decl
);
10124 case OMP_CLAUSE_REDUCTION
:
10125 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
10127 decl
= OMP_CLAUSE_DECL (c
);
10128 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
10129 if ((n
->value
& GOVD_REDUCTION_INSCAN
) == 0)
10132 error_at (OMP_CLAUSE_LOCATION (c
),
10133 "%qD specified in %<inscan%> %<reduction%> clause "
10134 "but not in %<scan%> directive clause", decl
);
10137 has_inscan_reductions
= true;
10140 case OMP_CLAUSE_IN_REDUCTION
:
10141 case OMP_CLAUSE_TASK_REDUCTION
:
10142 decl
= OMP_CLAUSE_DECL (c
);
10143 /* OpenACC reductions need a present_or_copy data clause.
10144 Add one if necessary. Emit error when the reduction is private. */
10145 if (ctx
->region_type
== ORT_ACC_PARALLEL
)
10147 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
10148 if (n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
))
10151 error_at (OMP_CLAUSE_LOCATION (c
), "invalid private "
10152 "reduction on %qE", DECL_NAME (decl
));
10154 else if ((n
->value
& GOVD_MAP
) == 0)
10156 tree next
= OMP_CLAUSE_CHAIN (c
);
10157 tree nc
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE_MAP
);
10158 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_TOFROM
);
10159 OMP_CLAUSE_DECL (nc
) = decl
;
10160 OMP_CLAUSE_CHAIN (c
) = nc
;
10161 lang_hooks
.decls
.omp_finish_clause (nc
, pre_p
);
10164 OMP_CLAUSE_MAP_IN_REDUCTION (nc
) = 1;
10165 if (OMP_CLAUSE_CHAIN (nc
) == NULL
)
10167 nc
= OMP_CLAUSE_CHAIN (nc
);
10169 OMP_CLAUSE_CHAIN (nc
) = next
;
10170 n
->value
|= GOVD_MAP
;
10174 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
10175 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
10177 case OMP_CLAUSE_COPYIN
:
10178 case OMP_CLAUSE_COPYPRIVATE
:
10179 case OMP_CLAUSE_IF
:
10180 case OMP_CLAUSE_NUM_THREADS
:
10181 case OMP_CLAUSE_NUM_TEAMS
:
10182 case OMP_CLAUSE_THREAD_LIMIT
:
10183 case OMP_CLAUSE_DIST_SCHEDULE
:
10184 case OMP_CLAUSE_DEVICE
:
10185 case OMP_CLAUSE_SCHEDULE
:
10186 case OMP_CLAUSE_NOWAIT
:
10187 case OMP_CLAUSE_ORDERED
:
10188 case OMP_CLAUSE_DEFAULT
:
10189 case OMP_CLAUSE_UNTIED
:
10190 case OMP_CLAUSE_COLLAPSE
:
10191 case OMP_CLAUSE_FINAL
:
10192 case OMP_CLAUSE_MERGEABLE
:
10193 case OMP_CLAUSE_PROC_BIND
:
10194 case OMP_CLAUSE_SAFELEN
:
10195 case OMP_CLAUSE_SIMDLEN
:
10196 case OMP_CLAUSE_DEPEND
:
10197 case OMP_CLAUSE_PRIORITY
:
10198 case OMP_CLAUSE_GRAINSIZE
:
10199 case OMP_CLAUSE_NUM_TASKS
:
10200 case OMP_CLAUSE_NOGROUP
:
10201 case OMP_CLAUSE_THREADS
:
10202 case OMP_CLAUSE_SIMD
:
10203 case OMP_CLAUSE_HINT
:
10204 case OMP_CLAUSE_DEFAULTMAP
:
10205 case OMP_CLAUSE_USE_DEVICE_PTR
:
10206 case OMP_CLAUSE_IS_DEVICE_PTR
:
10207 case OMP_CLAUSE_ASYNC
:
10208 case OMP_CLAUSE_WAIT
:
10209 case OMP_CLAUSE_INDEPENDENT
:
10210 case OMP_CLAUSE_NUM_GANGS
:
10211 case OMP_CLAUSE_NUM_WORKERS
:
10212 case OMP_CLAUSE_VECTOR_LENGTH
:
10213 case OMP_CLAUSE_GANG
:
10214 case OMP_CLAUSE_WORKER
:
10215 case OMP_CLAUSE_VECTOR
:
10216 case OMP_CLAUSE_AUTO
:
10217 case OMP_CLAUSE_SEQ
:
10218 case OMP_CLAUSE_TILE
:
10219 case OMP_CLAUSE_IF_PRESENT
:
10220 case OMP_CLAUSE_FINALIZE
:
10221 case OMP_CLAUSE_INCLUSIVE
:
10222 case OMP_CLAUSE_EXCLUSIVE
:
10226 gcc_unreachable ();
10230 *list_p
= OMP_CLAUSE_CHAIN (c
);
10232 list_p
= &OMP_CLAUSE_CHAIN (c
);
10235 /* Add in any implicit data sharing. */
10236 struct gimplify_adjust_omp_clauses_data data
;
10237 data
.list_p
= list_p
;
10238 data
.pre_p
= pre_p
;
10239 splay_tree_foreach (ctx
->variables
, gimplify_adjust_omp_clauses_1
, &data
);
10241 if (has_inscan_reductions
)
10242 for (c
= *orig_list_p
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10243 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
10244 && !OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
10246 error_at (OMP_CLAUSE_LOCATION (c
),
10247 "%<inscan%> %<reduction%> clause used together with "
10248 "%<linear%> clause for a variable other than loop "
10253 gimplify_omp_ctxp
= ctx
->outer_context
;
10254 delete_omp_context (ctx
);
10257 /* Gimplify OACC_CACHE. */
10260 gimplify_oacc_cache (tree
*expr_p
, gimple_seq
*pre_p
)
10262 tree expr
= *expr_p
;
10264 gimplify_scan_omp_clauses (&OACC_CACHE_CLAUSES (expr
), pre_p
, ORT_ACC
,
10266 gimplify_adjust_omp_clauses (pre_p
, NULL
, &OACC_CACHE_CLAUSES (expr
),
10269 /* TODO: Do something sensible with this information. */
10271 *expr_p
= NULL_TREE
;
10274 /* Helper function of gimplify_oacc_declare. The helper's purpose is to,
10275 if required, translate 'kind' in CLAUSE into an 'entry' kind and 'exit'
10276 kind. The entry kind will replace the one in CLAUSE, while the exit
10277 kind will be used in a new omp_clause and returned to the caller. */
10280 gimplify_oacc_declare_1 (tree clause
)
10282 HOST_WIDE_INT kind
, new_op
;
10286 kind
= OMP_CLAUSE_MAP_KIND (clause
);
10290 case GOMP_MAP_ALLOC
:
10291 new_op
= GOMP_MAP_RELEASE
;
10295 case GOMP_MAP_FROM
:
10296 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_FORCE_ALLOC
);
10297 new_op
= GOMP_MAP_FROM
;
10301 case GOMP_MAP_TOFROM
:
10302 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_TO
);
10303 new_op
= GOMP_MAP_FROM
;
10307 case GOMP_MAP_DEVICE_RESIDENT
:
10308 case GOMP_MAP_FORCE_DEVICEPTR
:
10309 case GOMP_MAP_FORCE_PRESENT
:
10310 case GOMP_MAP_LINK
:
10311 case GOMP_MAP_POINTER
:
10316 gcc_unreachable ();
10322 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
), OMP_CLAUSE_MAP
);
10323 OMP_CLAUSE_SET_MAP_KIND (c
, new_op
);
10324 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clause
);
10330 /* Gimplify OACC_DECLARE. */
10333 gimplify_oacc_declare (tree
*expr_p
, gimple_seq
*pre_p
)
10335 tree expr
= *expr_p
;
10337 tree clauses
, t
, decl
;
10339 clauses
= OACC_DECLARE_CLAUSES (expr
);
10341 gimplify_scan_omp_clauses (&clauses
, pre_p
, ORT_TARGET_DATA
, OACC_DECLARE
);
10342 gimplify_adjust_omp_clauses (pre_p
, NULL
, &clauses
, OACC_DECLARE
);
10344 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
10346 decl
= OMP_CLAUSE_DECL (t
);
10348 if (TREE_CODE (decl
) == MEM_REF
)
10349 decl
= TREE_OPERAND (decl
, 0);
10351 if (VAR_P (decl
) && !is_oacc_declared (decl
))
10353 tree attr
= get_identifier ("oacc declare target");
10354 DECL_ATTRIBUTES (decl
) = tree_cons (attr
, NULL_TREE
,
10355 DECL_ATTRIBUTES (decl
));
10359 && !is_global_var (decl
)
10360 && DECL_CONTEXT (decl
) == current_function_decl
)
10362 tree c
= gimplify_oacc_declare_1 (t
);
10365 if (oacc_declare_returns
== NULL
)
10366 oacc_declare_returns
= new hash_map
<tree
, tree
>;
10368 oacc_declare_returns
->put (decl
, c
);
10372 if (gimplify_omp_ctxp
)
10373 omp_add_variable (gimplify_omp_ctxp
, decl
, GOVD_SEEN
);
10376 stmt
= gimple_build_omp_target (NULL
, GF_OMP_TARGET_KIND_OACC_DECLARE
,
10379 gimplify_seq_add_stmt (pre_p
, stmt
);
10381 *expr_p
= NULL_TREE
;
10384 /* Gimplify the contents of an OMP_PARALLEL statement. This involves
10385 gimplification of the body, as well as scanning the body for used
10386 variables. We need to do this scan now, because variable-sized
10387 decls will be decomposed during gimplification. */
10390 gimplify_omp_parallel (tree
*expr_p
, gimple_seq
*pre_p
)
10392 tree expr
= *expr_p
;
10394 gimple_seq body
= NULL
;
10396 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr
), pre_p
,
10397 OMP_PARALLEL_COMBINED (expr
)
10398 ? ORT_COMBINED_PARALLEL
10399 : ORT_PARALLEL
, OMP_PARALLEL
);
10401 push_gimplify_context ();
10403 g
= gimplify_and_return_first (OMP_PARALLEL_BODY (expr
), &body
);
10404 if (gimple_code (g
) == GIMPLE_BIND
)
10405 pop_gimplify_context (g
);
10407 pop_gimplify_context (NULL
);
10409 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_PARALLEL_CLAUSES (expr
),
10412 g
= gimple_build_omp_parallel (body
,
10413 OMP_PARALLEL_CLAUSES (expr
),
10414 NULL_TREE
, NULL_TREE
);
10415 if (OMP_PARALLEL_COMBINED (expr
))
10416 gimple_omp_set_subcode (g
, GF_OMP_PARALLEL_COMBINED
);
10417 gimplify_seq_add_stmt (pre_p
, g
);
10418 *expr_p
= NULL_TREE
;
10421 /* Gimplify the contents of an OMP_TASK statement. This involves
10422 gimplification of the body, as well as scanning the body for used
10423 variables. We need to do this scan now, because variable-sized
10424 decls will be decomposed during gimplification. */
10427 gimplify_omp_task (tree
*expr_p
, gimple_seq
*pre_p
)
10429 tree expr
= *expr_p
;
10431 gimple_seq body
= NULL
;
10433 if (OMP_TASK_BODY (expr
) == NULL_TREE
)
10434 for (tree c
= OMP_TASK_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10435 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
10436 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_MUTEXINOUTSET
)
10438 error_at (OMP_CLAUSE_LOCATION (c
),
10439 "%<mutexinoutset%> kind in %<depend%> clause on a "
10440 "%<taskwait%> construct");
10444 gimplify_scan_omp_clauses (&OMP_TASK_CLAUSES (expr
), pre_p
,
10445 omp_find_clause (OMP_TASK_CLAUSES (expr
),
10447 ? ORT_UNTIED_TASK
: ORT_TASK
, OMP_TASK
);
10449 if (OMP_TASK_BODY (expr
))
10451 push_gimplify_context ();
10453 g
= gimplify_and_return_first (OMP_TASK_BODY (expr
), &body
);
10454 if (gimple_code (g
) == GIMPLE_BIND
)
10455 pop_gimplify_context (g
);
10457 pop_gimplify_context (NULL
);
10460 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_TASK_CLAUSES (expr
),
10463 g
= gimple_build_omp_task (body
,
10464 OMP_TASK_CLAUSES (expr
),
10465 NULL_TREE
, NULL_TREE
,
10466 NULL_TREE
, NULL_TREE
, NULL_TREE
);
10467 if (OMP_TASK_BODY (expr
) == NULL_TREE
)
10468 gimple_omp_task_set_taskwait_p (g
, true);
10469 gimplify_seq_add_stmt (pre_p
, g
);
10470 *expr_p
= NULL_TREE
;
10473 /* Helper function of gimplify_omp_for, find OMP_FOR resp. OMP_SIMD
10474 with non-NULL OMP_FOR_INIT. Also, fill in pdata array,
10475 pdata[0] non-NULL if there is anything non-trivial in between, pdata[1]
10476 is address of OMP_PARALLEL in between if any, pdata[2] is address of
10477 OMP_FOR in between if any and pdata[3] is address of the inner
10478 OMP_FOR/OMP_SIMD. */
10481 find_combined_omp_for (tree
*tp
, int *walk_subtrees
, void *data
)
10483 tree
**pdata
= (tree
**) data
;
10484 *walk_subtrees
= 0;
10485 switch (TREE_CODE (*tp
))
10488 if (OMP_FOR_INIT (*tp
) != NULL_TREE
)
10494 *walk_subtrees
= 1;
10497 if (OMP_FOR_INIT (*tp
) != NULL_TREE
)
10504 if (BIND_EXPR_VARS (*tp
)
10505 || (BIND_EXPR_BLOCK (*tp
)
10506 && BLOCK_VARS (BIND_EXPR_BLOCK (*tp
))))
10508 *walk_subtrees
= 1;
10510 case STATEMENT_LIST
:
10511 if (!tsi_one_before_end_p (tsi_start (*tp
)))
10513 *walk_subtrees
= 1;
10515 case TRY_FINALLY_EXPR
:
10517 *walk_subtrees
= 1;
10521 *walk_subtrees
= 1;
10529 /* Gimplify the gross structure of an OMP_FOR statement. */
10531 static enum gimplify_status
10532 gimplify_omp_for (tree
*expr_p
, gimple_seq
*pre_p
)
10534 tree for_stmt
, orig_for_stmt
, inner_for_stmt
= NULL_TREE
, decl
, var
, t
;
10535 enum gimplify_status ret
= GS_ALL_DONE
;
10536 enum gimplify_status tret
;
10538 gimple_seq for_body
, for_pre_body
;
10540 bitmap has_decl_expr
= NULL
;
10541 enum omp_region_type ort
= ORT_WORKSHARE
;
10543 orig_for_stmt
= for_stmt
= *expr_p
;
10545 if (OMP_FOR_INIT (for_stmt
) == NULL_TREE
)
10547 tree
*data
[4] = { NULL
, NULL
, NULL
, NULL
};
10548 gcc_assert (TREE_CODE (for_stmt
) != OACC_LOOP
);
10549 inner_for_stmt
= walk_tree (&OMP_FOR_BODY (for_stmt
),
10550 find_combined_omp_for
, data
, NULL
);
10551 if (inner_for_stmt
== NULL_TREE
)
10553 gcc_assert (seen_error ());
10554 *expr_p
= NULL_TREE
;
10557 if (data
[2] && OMP_FOR_PRE_BODY (*data
[2]))
10559 append_to_statement_list_force (OMP_FOR_PRE_BODY (*data
[2]),
10560 &OMP_FOR_PRE_BODY (for_stmt
));
10561 OMP_FOR_PRE_BODY (*data
[2]) = NULL_TREE
;
10563 if (OMP_FOR_PRE_BODY (inner_for_stmt
))
10565 append_to_statement_list_force (OMP_FOR_PRE_BODY (inner_for_stmt
),
10566 &OMP_FOR_PRE_BODY (for_stmt
));
10567 OMP_FOR_PRE_BODY (inner_for_stmt
) = NULL_TREE
;
10572 /* We have some statements or variable declarations in between
10573 the composite construct directives. Move them around the
10576 for (i
= 0; i
< 3; i
++)
10580 if (i
< 2 && data
[i
+ 1] == &OMP_BODY (t
))
10581 data
[i
+ 1] = data
[i
];
10582 *data
[i
] = OMP_BODY (t
);
10583 tree body
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
10584 NULL_TREE
, make_node (BLOCK
));
10585 OMP_BODY (t
) = body
;
10586 append_to_statement_list_force (inner_for_stmt
,
10587 &BIND_EXPR_BODY (body
));
10589 data
[3] = tsi_stmt_ptr (tsi_start (BIND_EXPR_BODY (body
)));
10590 gcc_assert (*data
[3] == inner_for_stmt
);
10595 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt
)); i
++)
10596 if (OMP_FOR_ORIG_DECLS (inner_for_stmt
)
10597 && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
),
10599 && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
),
10602 tree orig
= TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
), i
);
10603 /* Class iterators aren't allowed on OMP_SIMD, so the only
10604 case we need to solve is distribute parallel for. */
10605 gcc_assert (TREE_CODE (inner_for_stmt
) == OMP_FOR
10606 && TREE_CODE (for_stmt
) == OMP_DISTRIBUTE
10608 tree orig_decl
= TREE_PURPOSE (orig
);
10609 tree last
= TREE_VALUE (orig
);
10611 for (pc
= &OMP_FOR_CLAUSES (inner_for_stmt
);
10612 *pc
; pc
= &OMP_CLAUSE_CHAIN (*pc
))
10613 if ((OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_PRIVATE
10614 || OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LASTPRIVATE
)
10615 && OMP_CLAUSE_DECL (*pc
) == orig_decl
)
10617 if (*pc
== NULL_TREE
)
10619 else if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_PRIVATE
)
10621 /* private clause will appear only on inner_for_stmt.
10622 Change it into firstprivate, and add private clause
10624 tree c
= copy_node (*pc
);
10625 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (for_stmt
);
10626 OMP_FOR_CLAUSES (for_stmt
) = c
;
10627 OMP_CLAUSE_CODE (*pc
) = OMP_CLAUSE_FIRSTPRIVATE
;
10628 lang_hooks
.decls
.omp_finish_clause (*pc
, pre_p
);
10632 /* lastprivate clause will appear on both inner_for_stmt
10633 and for_stmt. Add firstprivate clause to
10635 tree c
= build_omp_clause (OMP_CLAUSE_LOCATION (*pc
),
10636 OMP_CLAUSE_FIRSTPRIVATE
);
10637 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (*pc
);
10638 OMP_CLAUSE_CHAIN (c
) = *pc
;
10640 lang_hooks
.decls
.omp_finish_clause (*pc
, pre_p
);
10642 tree c
= build_omp_clause (UNKNOWN_LOCATION
,
10643 OMP_CLAUSE_FIRSTPRIVATE
);
10644 OMP_CLAUSE_DECL (c
) = last
;
10645 OMP_CLAUSE_CHAIN (c
) = OMP_PARALLEL_CLAUSES (*data
[1]);
10646 OMP_PARALLEL_CLAUSES (*data
[1]) = c
;
10647 c
= build_omp_clause (UNKNOWN_LOCATION
,
10648 *pc
? OMP_CLAUSE_SHARED
10649 : OMP_CLAUSE_FIRSTPRIVATE
);
10650 OMP_CLAUSE_DECL (c
) = orig_decl
;
10651 OMP_CLAUSE_CHAIN (c
) = OMP_PARALLEL_CLAUSES (*data
[1]);
10652 OMP_PARALLEL_CLAUSES (*data
[1]) = c
;
10654 /* Similarly, take care of C++ range for temporaries, those should
10655 be firstprivate on OMP_PARALLEL if any. */
10657 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt
)); i
++)
10658 if (OMP_FOR_ORIG_DECLS (inner_for_stmt
)
10659 && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
),
10661 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
),
10665 = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt
), i
);
10666 tree v
= TREE_CHAIN (orig
);
10667 tree c
= build_omp_clause (UNKNOWN_LOCATION
,
10668 OMP_CLAUSE_FIRSTPRIVATE
);
10669 /* First add firstprivate clause for the __for_end artificial
10671 OMP_CLAUSE_DECL (c
) = TREE_VEC_ELT (v
, 1);
10672 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
10674 OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c
) = 1;
10675 OMP_CLAUSE_CHAIN (c
) = OMP_PARALLEL_CLAUSES (*data
[1]);
10676 OMP_PARALLEL_CLAUSES (*data
[1]) = c
;
10677 if (TREE_VEC_ELT (v
, 0))
10679 /* And now the same for __for_range artificial decl if it
10681 c
= build_omp_clause (UNKNOWN_LOCATION
,
10682 OMP_CLAUSE_FIRSTPRIVATE
);
10683 OMP_CLAUSE_DECL (c
) = TREE_VEC_ELT (v
, 0);
10684 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
10686 OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c
) = 1;
10687 OMP_CLAUSE_CHAIN (c
) = OMP_PARALLEL_CLAUSES (*data
[1]);
10688 OMP_PARALLEL_CLAUSES (*data
[1]) = c
;
10693 switch (TREE_CODE (for_stmt
))
10696 case OMP_DISTRIBUTE
:
10702 if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_UNTIED
))
10703 ort
= ORT_UNTIED_TASKLOOP
;
10705 ort
= ORT_TASKLOOP
;
10711 gcc_unreachable ();
10714 /* Set OMP_CLAUSE_LINEAR_NO_COPYIN flag on explicit linear
10715 clause for the IV. */
10716 if (ort
== ORT_SIMD
&& TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
10718 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), 0);
10719 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
10720 decl
= TREE_OPERAND (t
, 0);
10721 for (tree c
= OMP_FOR_CLAUSES (for_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10722 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
10723 && OMP_CLAUSE_DECL (c
) == decl
)
10725 OMP_CLAUSE_LINEAR_NO_COPYIN (c
) = 1;
10730 if (TREE_CODE (for_stmt
) != OMP_TASKLOOP
)
10731 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt
), pre_p
, ort
,
10732 TREE_CODE (for_stmt
));
10734 if (TREE_CODE (for_stmt
) == OMP_DISTRIBUTE
)
10735 gimplify_omp_ctxp
->distribute
= true;
10737 /* Handle OMP_FOR_INIT. */
10738 for_pre_body
= NULL
;
10739 if ((ort
== ORT_SIMD
10740 || (inner_for_stmt
&& TREE_CODE (inner_for_stmt
) == OMP_SIMD
))
10741 && OMP_FOR_PRE_BODY (for_stmt
))
10743 has_decl_expr
= BITMAP_ALLOC (NULL
);
10744 if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt
)) == DECL_EXPR
10745 && TREE_CODE (DECL_EXPR_DECL (OMP_FOR_PRE_BODY (for_stmt
)))
10748 t
= OMP_FOR_PRE_BODY (for_stmt
);
10749 bitmap_set_bit (has_decl_expr
, DECL_UID (DECL_EXPR_DECL (t
)));
10751 else if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt
)) == STATEMENT_LIST
)
10753 tree_stmt_iterator si
;
10754 for (si
= tsi_start (OMP_FOR_PRE_BODY (for_stmt
)); !tsi_end_p (si
);
10758 if (TREE_CODE (t
) == DECL_EXPR
10759 && TREE_CODE (DECL_EXPR_DECL (t
)) == VAR_DECL
)
10760 bitmap_set_bit (has_decl_expr
, DECL_UID (DECL_EXPR_DECL (t
)));
10764 if (OMP_FOR_PRE_BODY (for_stmt
))
10766 if (TREE_CODE (for_stmt
) != OMP_TASKLOOP
|| gimplify_omp_ctxp
)
10767 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt
), &for_pre_body
);
10770 struct gimplify_omp_ctx ctx
;
10771 memset (&ctx
, 0, sizeof (ctx
));
10772 ctx
.region_type
= ORT_NONE
;
10773 gimplify_omp_ctxp
= &ctx
;
10774 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt
), &for_pre_body
);
10775 gimplify_omp_ctxp
= NULL
;
10778 OMP_FOR_PRE_BODY (for_stmt
) = NULL_TREE
;
10780 if (OMP_FOR_INIT (for_stmt
) == NULL_TREE
)
10781 for_stmt
= inner_for_stmt
;
10783 /* For taskloop, need to gimplify the start, end and step before the
10784 taskloop, outside of the taskloop omp context. */
10785 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
10787 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
10789 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
10790 if (!is_gimple_constant (TREE_OPERAND (t
, 1)))
10792 tree type
= TREE_TYPE (TREE_OPERAND (t
, 0));
10793 TREE_OPERAND (t
, 1)
10794 = get_initialized_tmp_var (TREE_OPERAND (t
, 1),
10795 gimple_seq_empty_p (for_pre_body
)
10796 ? pre_p
: &for_pre_body
, NULL
,
10798 /* Reference to pointer conversion is considered useless,
10799 but is significant for firstprivate clause. Force it
10801 if (TREE_CODE (type
) == POINTER_TYPE
10802 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 1)))
10803 == REFERENCE_TYPE
))
10805 tree v
= create_tmp_var (TYPE_MAIN_VARIANT (type
));
10806 tree m
= build2 (INIT_EXPR
, TREE_TYPE (v
), v
,
10807 TREE_OPERAND (t
, 1));
10808 gimplify_and_add (m
, gimple_seq_empty_p (for_pre_body
)
10809 ? pre_p
: &for_pre_body
);
10810 TREE_OPERAND (t
, 1) = v
;
10812 tree c
= build_omp_clause (input_location
,
10813 OMP_CLAUSE_FIRSTPRIVATE
);
10814 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (t
, 1);
10815 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
10816 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
10819 /* Handle OMP_FOR_COND. */
10820 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
10821 if (!is_gimple_constant (TREE_OPERAND (t
, 1)))
10823 tree type
= TREE_TYPE (TREE_OPERAND (t
, 0));
10824 TREE_OPERAND (t
, 1)
10825 = get_initialized_tmp_var (TREE_OPERAND (t
, 1),
10826 gimple_seq_empty_p (for_pre_body
)
10827 ? pre_p
: &for_pre_body
, NULL
,
10829 /* Reference to pointer conversion is considered useless,
10830 but is significant for firstprivate clause. Force it
10832 if (TREE_CODE (type
) == POINTER_TYPE
10833 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 1)))
10834 == REFERENCE_TYPE
))
10836 tree v
= create_tmp_var (TYPE_MAIN_VARIANT (type
));
10837 tree m
= build2 (INIT_EXPR
, TREE_TYPE (v
), v
,
10838 TREE_OPERAND (t
, 1));
10839 gimplify_and_add (m
, gimple_seq_empty_p (for_pre_body
)
10840 ? pre_p
: &for_pre_body
);
10841 TREE_OPERAND (t
, 1) = v
;
10843 tree c
= build_omp_clause (input_location
,
10844 OMP_CLAUSE_FIRSTPRIVATE
);
10845 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (t
, 1);
10846 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
10847 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
10850 /* Handle OMP_FOR_INCR. */
10851 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
10852 if (TREE_CODE (t
) == MODIFY_EXPR
)
10854 decl
= TREE_OPERAND (t
, 0);
10855 t
= TREE_OPERAND (t
, 1);
10856 tree
*tp
= &TREE_OPERAND (t
, 1);
10857 if (TREE_CODE (t
) == PLUS_EXPR
&& *tp
== decl
)
10858 tp
= &TREE_OPERAND (t
, 0);
10860 if (!is_gimple_constant (*tp
))
10862 gimple_seq
*seq
= gimple_seq_empty_p (for_pre_body
)
10863 ? pre_p
: &for_pre_body
;
10864 *tp
= get_initialized_tmp_var (*tp
, seq
, NULL
, false);
10865 tree c
= build_omp_clause (input_location
,
10866 OMP_CLAUSE_FIRSTPRIVATE
);
10867 OMP_CLAUSE_DECL (c
) = *tp
;
10868 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
10869 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
10874 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (orig_for_stmt
), pre_p
, ort
,
10878 if (orig_for_stmt
!= for_stmt
)
10879 gimplify_omp_ctxp
->combined_loop
= true;
10882 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
10883 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt
)));
10884 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
10885 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt
)));
10887 tree c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_ORDERED
);
10888 bool is_doacross
= false;
10889 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
10891 is_doacross
= true;
10892 gimplify_omp_ctxp
->loop_iter_var
.create (TREE_VEC_LENGTH
10893 (OMP_FOR_INIT (for_stmt
))
10896 int collapse
= 1, tile
= 0;
10897 c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_COLLAPSE
);
10899 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
10900 c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_TILE
);
10902 tile
= list_length (OMP_CLAUSE_TILE_LIST (c
));
10903 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
10905 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
10906 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
10907 decl
= TREE_OPERAND (t
, 0);
10908 gcc_assert (DECL_P (decl
));
10909 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl
))
10910 || POINTER_TYPE_P (TREE_TYPE (decl
)));
10913 if (TREE_CODE (for_stmt
) == OMP_FOR
&& OMP_FOR_ORIG_DECLS (for_stmt
))
10915 tree orig_decl
= TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt
), i
);
10916 if (TREE_CODE (orig_decl
) == TREE_LIST
)
10918 orig_decl
= TREE_PURPOSE (orig_decl
);
10922 gimplify_omp_ctxp
->loop_iter_var
.quick_push (orig_decl
);
10925 gimplify_omp_ctxp
->loop_iter_var
.quick_push (decl
);
10926 gimplify_omp_ctxp
->loop_iter_var
.quick_push (decl
);
10929 /* Make sure the iteration variable is private. */
10930 tree c
= NULL_TREE
;
10931 tree c2
= NULL_TREE
;
10932 if (orig_for_stmt
!= for_stmt
)
10934 /* Preserve this information until we gimplify the inner simd. */
10936 && bitmap_bit_p (has_decl_expr
, DECL_UID (decl
)))
10937 TREE_PRIVATE (t
) = 1;
10939 else if (ort
== ORT_SIMD
)
10941 splay_tree_node n
= splay_tree_lookup (gimplify_omp_ctxp
->variables
,
10942 (splay_tree_key
) decl
);
10943 omp_is_private (gimplify_omp_ctxp
, decl
,
10944 1 + (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
10946 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
10948 omp_notice_variable (gimplify_omp_ctxp
, decl
, true);
10949 if (n
->value
& GOVD_LASTPRIVATE_CONDITIONAL
)
10950 for (tree c3
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
),
10951 OMP_CLAUSE_LASTPRIVATE
);
10952 c3
; c3
= omp_find_clause (OMP_CLAUSE_CHAIN (c3
),
10953 OMP_CLAUSE_LASTPRIVATE
))
10954 if (OMP_CLAUSE_DECL (c3
) == decl
)
10956 warning_at (OMP_CLAUSE_LOCATION (c3
), 0,
10957 "conditional %<lastprivate%> on loop "
10958 "iterator %qD ignored", decl
);
10959 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3
) = 0;
10960 n
->value
&= ~GOVD_LASTPRIVATE_CONDITIONAL
;
10963 else if (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
10965 c
= build_omp_clause (input_location
, OMP_CLAUSE_LINEAR
);
10966 OMP_CLAUSE_LINEAR_NO_COPYIN (c
) = 1;
10967 unsigned int flags
= GOVD_LINEAR
| GOVD_EXPLICIT
| GOVD_SEEN
;
10969 && bitmap_bit_p (has_decl_expr
, DECL_UID (decl
)))
10970 || TREE_PRIVATE (t
))
10972 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
10973 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
10975 struct gimplify_omp_ctx
*outer
10976 = gimplify_omp_ctxp
->outer_context
;
10977 if (outer
&& !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
10979 if (outer
->region_type
== ORT_WORKSHARE
10980 && outer
->combined_loop
)
10982 n
= splay_tree_lookup (outer
->variables
,
10983 (splay_tree_key
)decl
);
10984 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
10986 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
10987 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
10991 struct gimplify_omp_ctx
*octx
= outer
->outer_context
;
10993 && octx
->region_type
== ORT_COMBINED_PARALLEL
10994 && octx
->outer_context
10995 && (octx
->outer_context
->region_type
10997 && octx
->outer_context
->combined_loop
)
10999 octx
= octx
->outer_context
;
11000 n
= splay_tree_lookup (octx
->variables
,
11001 (splay_tree_key
)decl
);
11002 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
11004 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
11005 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
11012 OMP_CLAUSE_DECL (c
) = decl
;
11013 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (for_stmt
);
11014 OMP_FOR_CLAUSES (for_stmt
) = c
;
11015 omp_add_variable (gimplify_omp_ctxp
, decl
, flags
);
11016 if (outer
&& !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
11018 if (outer
->region_type
== ORT_WORKSHARE
11019 && outer
->combined_loop
)
11021 if (outer
->outer_context
11022 && (outer
->outer_context
->region_type
11023 == ORT_COMBINED_PARALLEL
))
11024 outer
= outer
->outer_context
;
11025 else if (omp_check_private (outer
, decl
, false))
11028 else if (((outer
->region_type
& ORT_TASKLOOP
)
11030 && outer
->combined_loop
11031 && !omp_check_private (gimplify_omp_ctxp
,
11034 else if (outer
->region_type
!= ORT_COMBINED_PARALLEL
)
11036 omp_notice_variable (outer
, decl
, true);
11041 n
= splay_tree_lookup (outer
->variables
,
11042 (splay_tree_key
)decl
);
11043 if (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
11045 omp_add_variable (outer
, decl
,
11046 GOVD_LASTPRIVATE
| GOVD_SEEN
);
11047 if (outer
->region_type
== ORT_COMBINED_PARALLEL
11048 && outer
->outer_context
11049 && (outer
->outer_context
->region_type
11051 && outer
->outer_context
->combined_loop
)
11053 outer
= outer
->outer_context
;
11054 n
= splay_tree_lookup (outer
->variables
,
11055 (splay_tree_key
)decl
);
11056 if (omp_check_private (outer
, decl
, false))
11059 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
11061 omp_add_variable (outer
, decl
,
11067 if (outer
&& outer
->outer_context
11068 && ((outer
->outer_context
->region_type
11069 & ORT_COMBINED_TEAMS
) == ORT_COMBINED_TEAMS
11070 || (((outer
->region_type
& ORT_TASKLOOP
)
11072 && (outer
->outer_context
->region_type
11073 == ORT_COMBINED_PARALLEL
))))
11075 outer
= outer
->outer_context
;
11076 n
= splay_tree_lookup (outer
->variables
,
11077 (splay_tree_key
)decl
);
11079 || (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
11080 omp_add_variable (outer
, decl
,
11081 GOVD_SHARED
| GOVD_SEEN
);
11085 if (outer
&& outer
->outer_context
)
11086 omp_notice_variable (outer
->outer_context
, decl
,
11096 || !bitmap_bit_p (has_decl_expr
, DECL_UID (decl
)));
11097 if (TREE_PRIVATE (t
))
11098 lastprivate
= false;
11099 struct gimplify_omp_ctx
*outer
11100 = gimplify_omp_ctxp
->outer_context
;
11101 if (outer
&& lastprivate
)
11103 if (outer
->region_type
== ORT_WORKSHARE
11104 && outer
->combined_loop
)
11106 n
= splay_tree_lookup (outer
->variables
,
11107 (splay_tree_key
)decl
);
11108 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
11110 lastprivate
= false;
11113 else if (outer
->outer_context
11114 && (outer
->outer_context
->region_type
11115 == ORT_COMBINED_PARALLEL
))
11116 outer
= outer
->outer_context
;
11117 else if (omp_check_private (outer
, decl
, false))
11120 else if (((outer
->region_type
& ORT_TASKLOOP
)
11122 && outer
->combined_loop
11123 && !omp_check_private (gimplify_omp_ctxp
,
11126 else if (outer
->region_type
!= ORT_COMBINED_PARALLEL
)
11128 omp_notice_variable (outer
, decl
, true);
11133 n
= splay_tree_lookup (outer
->variables
,
11134 (splay_tree_key
)decl
);
11135 if (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
11137 omp_add_variable (outer
, decl
,
11138 GOVD_LASTPRIVATE
| GOVD_SEEN
);
11139 if (outer
->region_type
== ORT_COMBINED_PARALLEL
11140 && outer
->outer_context
11141 && (outer
->outer_context
->region_type
11143 && outer
->outer_context
->combined_loop
)
11145 outer
= outer
->outer_context
;
11146 n
= splay_tree_lookup (outer
->variables
,
11147 (splay_tree_key
)decl
);
11148 if (omp_check_private (outer
, decl
, false))
11151 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
11153 omp_add_variable (outer
, decl
,
11159 if (outer
&& outer
->outer_context
11160 && ((outer
->outer_context
->region_type
11161 & ORT_COMBINED_TEAMS
) == ORT_COMBINED_TEAMS
11162 || (((outer
->region_type
& ORT_TASKLOOP
)
11164 && (outer
->outer_context
->region_type
11165 == ORT_COMBINED_PARALLEL
))))
11167 outer
= outer
->outer_context
;
11168 n
= splay_tree_lookup (outer
->variables
,
11169 (splay_tree_key
)decl
);
11171 || (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
11172 omp_add_variable (outer
, decl
,
11173 GOVD_SHARED
| GOVD_SEEN
);
11177 if (outer
&& outer
->outer_context
)
11178 omp_notice_variable (outer
->outer_context
, decl
,
11184 c
= build_omp_clause (input_location
,
11185 lastprivate
? OMP_CLAUSE_LASTPRIVATE
11186 : OMP_CLAUSE_PRIVATE
);
11187 OMP_CLAUSE_DECL (c
) = decl
;
11188 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (for_stmt
);
11189 OMP_FOR_CLAUSES (for_stmt
) = c
;
11190 omp_add_variable (gimplify_omp_ctxp
, decl
,
11191 (lastprivate
? GOVD_LASTPRIVATE
: GOVD_PRIVATE
)
11192 | GOVD_EXPLICIT
| GOVD_SEEN
);
11196 else if (omp_is_private (gimplify_omp_ctxp
, decl
, 0))
11198 omp_notice_variable (gimplify_omp_ctxp
, decl
, true);
11199 splay_tree_node n
= splay_tree_lookup (gimplify_omp_ctxp
->variables
,
11200 (splay_tree_key
) decl
);
11201 if (n
&& (n
->value
& GOVD_LASTPRIVATE_CONDITIONAL
))
11202 for (tree c3
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
),
11203 OMP_CLAUSE_LASTPRIVATE
);
11204 c3
; c3
= omp_find_clause (OMP_CLAUSE_CHAIN (c3
),
11205 OMP_CLAUSE_LASTPRIVATE
))
11206 if (OMP_CLAUSE_DECL (c3
) == decl
)
11208 warning_at (OMP_CLAUSE_LOCATION (c3
), 0,
11209 "conditional %<lastprivate%> on loop "
11210 "iterator %qD ignored", decl
);
11211 OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3
) = 0;
11212 n
->value
&= ~GOVD_LASTPRIVATE_CONDITIONAL
;
11216 omp_add_variable (gimplify_omp_ctxp
, decl
, GOVD_PRIVATE
| GOVD_SEEN
);
11218 /* If DECL is not a gimple register, create a temporary variable to act
11219 as an iteration counter. This is valid, since DECL cannot be
11220 modified in the body of the loop. Similarly for any iteration vars
11221 in simd with collapse > 1 where the iterator vars must be
11223 if (orig_for_stmt
!= for_stmt
)
11225 else if (!is_gimple_reg (decl
)
11226 || (ort
== ORT_SIMD
11227 && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) > 1))
11229 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
11230 /* Make sure omp_add_variable is not called on it prematurely.
11231 We call it ourselves a few lines later. */
11232 gimplify_omp_ctxp
= NULL
;
11233 var
= create_tmp_var (TREE_TYPE (decl
), get_name (decl
));
11234 gimplify_omp_ctxp
= ctx
;
11235 TREE_OPERAND (t
, 0) = var
;
11237 gimplify_seq_add_stmt (&for_body
, gimple_build_assign (decl
, var
));
11239 if (ort
== ORT_SIMD
11240 && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
11242 c2
= build_omp_clause (input_location
, OMP_CLAUSE_LINEAR
);
11243 OMP_CLAUSE_LINEAR_NO_COPYIN (c2
) = 1;
11244 OMP_CLAUSE_LINEAR_NO_COPYOUT (c2
) = 1;
11245 OMP_CLAUSE_DECL (c2
) = var
;
11246 OMP_CLAUSE_CHAIN (c2
) = OMP_FOR_CLAUSES (for_stmt
);
11247 OMP_FOR_CLAUSES (for_stmt
) = c2
;
11248 omp_add_variable (gimplify_omp_ctxp
, var
,
11249 GOVD_LINEAR
| GOVD_EXPLICIT
| GOVD_SEEN
);
11250 if (c
== NULL_TREE
)
11257 omp_add_variable (gimplify_omp_ctxp
, var
,
11258 GOVD_PRIVATE
| GOVD_SEEN
);
11263 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
11264 is_gimple_val
, fb_rvalue
, false);
11265 ret
= MIN (ret
, tret
);
11266 if (ret
== GS_ERROR
)
11269 /* Handle OMP_FOR_COND. */
11270 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
11271 gcc_assert (COMPARISON_CLASS_P (t
));
11272 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
11274 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
11275 is_gimple_val
, fb_rvalue
, false);
11276 ret
= MIN (ret
, tret
);
11278 /* Handle OMP_FOR_INCR. */
11279 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
11280 switch (TREE_CODE (t
))
11282 case PREINCREMENT_EXPR
:
11283 case POSTINCREMENT_EXPR
:
11285 tree decl
= TREE_OPERAND (t
, 0);
11286 /* c_omp_for_incr_canonicalize_ptr() should have been
11287 called to massage things appropriately. */
11288 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
11290 if (orig_for_stmt
!= for_stmt
)
11292 t
= build_int_cst (TREE_TYPE (decl
), 1);
11294 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
11295 t
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), var
, t
);
11296 t
= build2 (MODIFY_EXPR
, TREE_TYPE (var
), var
, t
);
11297 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
) = t
;
11301 case PREDECREMENT_EXPR
:
11302 case POSTDECREMENT_EXPR
:
11303 /* c_omp_for_incr_canonicalize_ptr() should have been
11304 called to massage things appropriately. */
11305 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
11306 if (orig_for_stmt
!= for_stmt
)
11308 t
= build_int_cst (TREE_TYPE (decl
), -1);
11310 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
11311 t
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), var
, t
);
11312 t
= build2 (MODIFY_EXPR
, TREE_TYPE (var
), var
, t
);
11313 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
) = t
;
11317 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
11318 TREE_OPERAND (t
, 0) = var
;
11320 t
= TREE_OPERAND (t
, 1);
11321 switch (TREE_CODE (t
))
11324 if (TREE_OPERAND (t
, 1) == decl
)
11326 TREE_OPERAND (t
, 1) = TREE_OPERAND (t
, 0);
11327 TREE_OPERAND (t
, 0) = var
;
11333 case POINTER_PLUS_EXPR
:
11334 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
11335 TREE_OPERAND (t
, 0) = var
;
11338 gcc_unreachable ();
11341 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
11342 is_gimple_val
, fb_rvalue
, false);
11343 ret
= MIN (ret
, tret
);
11346 tree step
= TREE_OPERAND (t
, 1);
11347 tree stept
= TREE_TYPE (decl
);
11348 if (POINTER_TYPE_P (stept
))
11350 step
= fold_convert (stept
, step
);
11351 if (TREE_CODE (t
) == MINUS_EXPR
)
11352 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
11353 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11354 if (step
!= TREE_OPERAND (t
, 1))
11356 tret
= gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c
),
11357 &for_pre_body
, NULL
,
11358 is_gimple_val
, fb_rvalue
, false);
11359 ret
= MIN (ret
, tret
);
11365 gcc_unreachable ();
11371 OMP_CLAUSE_LINEAR_STEP (c2
) = OMP_CLAUSE_LINEAR_STEP (c
);
11374 if ((var
!= decl
|| collapse
> 1 || tile
) && orig_for_stmt
== for_stmt
)
11376 for (c
= OMP_FOR_CLAUSES (for_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
11377 if (((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
11378 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
) == NULL
)
11379 || (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
11380 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)
11381 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
) == NULL
))
11382 && OMP_CLAUSE_DECL (c
) == decl
)
11384 if (is_doacross
&& (collapse
== 1 || i
>= collapse
))
11388 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
11389 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
11390 gcc_assert (TREE_OPERAND (t
, 0) == var
);
11391 t
= TREE_OPERAND (t
, 1);
11392 gcc_assert (TREE_CODE (t
) == PLUS_EXPR
11393 || TREE_CODE (t
) == MINUS_EXPR
11394 || TREE_CODE (t
) == POINTER_PLUS_EXPR
);
11395 gcc_assert (TREE_OPERAND (t
, 0) == var
);
11396 t
= build2 (TREE_CODE (t
), TREE_TYPE (decl
),
11397 is_doacross
? var
: decl
,
11398 TREE_OPERAND (t
, 1));
11401 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
11402 seq
= &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
);
11404 seq
= &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
);
11405 push_gimplify_context ();
11406 gimplify_assign (decl
, t
, seq
);
11407 gimple
*bind
= NULL
;
11408 if (gimplify_ctxp
->temps
)
11410 bind
= gimple_build_bind (NULL_TREE
, *seq
, NULL_TREE
);
11412 gimplify_seq_add_stmt (seq
, bind
);
11414 pop_gimplify_context (bind
);
11419 BITMAP_FREE (has_decl_expr
);
11421 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
11423 push_gimplify_context ();
11424 if (TREE_CODE (OMP_FOR_BODY (orig_for_stmt
)) != BIND_EXPR
)
11426 OMP_FOR_BODY (orig_for_stmt
)
11427 = build3 (BIND_EXPR
, void_type_node
, NULL
,
11428 OMP_FOR_BODY (orig_for_stmt
), NULL
);
11429 TREE_SIDE_EFFECTS (OMP_FOR_BODY (orig_for_stmt
)) = 1;
11433 gimple
*g
= gimplify_and_return_first (OMP_FOR_BODY (orig_for_stmt
),
11436 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
11438 if (gimple_code (g
) == GIMPLE_BIND
)
11439 pop_gimplify_context (g
);
11441 pop_gimplify_context (NULL
);
11444 if (orig_for_stmt
!= for_stmt
)
11445 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
11447 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
11448 decl
= TREE_OPERAND (t
, 0);
11449 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
11450 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
11451 gimplify_omp_ctxp
= ctx
->outer_context
;
11452 var
= create_tmp_var (TREE_TYPE (decl
), get_name (decl
));
11453 gimplify_omp_ctxp
= ctx
;
11454 omp_add_variable (gimplify_omp_ctxp
, var
, GOVD_PRIVATE
| GOVD_SEEN
);
11455 TREE_OPERAND (t
, 0) = var
;
11456 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
11457 TREE_OPERAND (t
, 1) = copy_node (TREE_OPERAND (t
, 1));
11458 TREE_OPERAND (TREE_OPERAND (t
, 1), 0) = var
;
11461 gimplify_adjust_omp_clauses (pre_p
, for_body
,
11462 &OMP_FOR_CLAUSES (orig_for_stmt
),
11463 TREE_CODE (orig_for_stmt
));
11466 switch (TREE_CODE (orig_for_stmt
))
11468 case OMP_FOR
: kind
= GF_OMP_FOR_KIND_FOR
; break;
11469 case OMP_SIMD
: kind
= GF_OMP_FOR_KIND_SIMD
; break;
11470 case OMP_DISTRIBUTE
: kind
= GF_OMP_FOR_KIND_DISTRIBUTE
; break;
11471 case OMP_TASKLOOP
: kind
= GF_OMP_FOR_KIND_TASKLOOP
; break;
11472 case OACC_LOOP
: kind
= GF_OMP_FOR_KIND_OACC_LOOP
; break;
11474 gcc_unreachable ();
11476 gfor
= gimple_build_omp_for (for_body
, kind
, OMP_FOR_CLAUSES (orig_for_stmt
),
11477 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)),
11479 if (orig_for_stmt
!= for_stmt
)
11480 gimple_omp_for_set_combined_p (gfor
, true);
11481 if (gimplify_omp_ctxp
11482 && (gimplify_omp_ctxp
->combined_loop
11483 || (gimplify_omp_ctxp
->region_type
== ORT_COMBINED_PARALLEL
11484 && gimplify_omp_ctxp
->outer_context
11485 && gimplify_omp_ctxp
->outer_context
->combined_loop
)))
11487 gimple_omp_for_set_combined_into_p (gfor
, true);
11488 if (gimplify_omp_ctxp
->combined_loop
)
11489 gcc_assert (TREE_CODE (orig_for_stmt
) == OMP_SIMD
);
11491 gcc_assert (TREE_CODE (orig_for_stmt
) == OMP_FOR
);
11494 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
11496 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
11497 gimple_omp_for_set_index (gfor
, i
, TREE_OPERAND (t
, 0));
11498 gimple_omp_for_set_initial (gfor
, i
, TREE_OPERAND (t
, 1));
11499 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
11500 gimple_omp_for_set_cond (gfor
, i
, TREE_CODE (t
));
11501 gimple_omp_for_set_final (gfor
, i
, TREE_OPERAND (t
, 1));
11502 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
11503 gimple_omp_for_set_incr (gfor
, i
, TREE_OPERAND (t
, 1));
11506 /* OMP_TASKLOOP is gimplified as two GIMPLE_OMP_FOR taskloop
11507 constructs with GIMPLE_OMP_TASK sandwiched in between them.
11508 The outer taskloop stands for computing the number of iterations,
11509 counts for collapsed loops and holding taskloop specific clauses.
11510 The task construct stands for the effect of data sharing on the
11511 explicit task it creates and the inner taskloop stands for expansion
11512 of the static loop inside of the explicit task construct. */
11513 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
11515 tree
*gfor_clauses_ptr
= gimple_omp_for_clauses_ptr (gfor
);
11516 tree task_clauses
= NULL_TREE
;
11517 tree c
= *gfor_clauses_ptr
;
11518 tree
*gtask_clauses_ptr
= &task_clauses
;
11519 tree outer_for_clauses
= NULL_TREE
;
11520 tree
*gforo_clauses_ptr
= &outer_for_clauses
;
11521 for (; c
; c
= OMP_CLAUSE_CHAIN (c
))
11522 switch (OMP_CLAUSE_CODE (c
))
11524 /* These clauses are allowed on task, move them there. */
11525 case OMP_CLAUSE_SHARED
:
11526 case OMP_CLAUSE_FIRSTPRIVATE
:
11527 case OMP_CLAUSE_DEFAULT
:
11528 case OMP_CLAUSE_IF
:
11529 case OMP_CLAUSE_UNTIED
:
11530 case OMP_CLAUSE_FINAL
:
11531 case OMP_CLAUSE_MERGEABLE
:
11532 case OMP_CLAUSE_PRIORITY
:
11533 case OMP_CLAUSE_REDUCTION
:
11534 case OMP_CLAUSE_IN_REDUCTION
:
11535 *gtask_clauses_ptr
= c
;
11536 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11538 case OMP_CLAUSE_PRIVATE
:
11539 if (OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
))
11541 /* We want private on outer for and firstprivate
11544 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
11545 OMP_CLAUSE_FIRSTPRIVATE
);
11546 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
11547 lang_hooks
.decls
.omp_finish_clause (*gtask_clauses_ptr
, NULL
);
11548 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
11549 *gforo_clauses_ptr
= c
;
11550 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11554 *gtask_clauses_ptr
= c
;
11555 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11558 /* These clauses go into outer taskloop clauses. */
11559 case OMP_CLAUSE_GRAINSIZE
:
11560 case OMP_CLAUSE_NUM_TASKS
:
11561 case OMP_CLAUSE_NOGROUP
:
11562 *gforo_clauses_ptr
= c
;
11563 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11565 /* Taskloop clause we duplicate on both taskloops. */
11566 case OMP_CLAUSE_COLLAPSE
:
11567 *gfor_clauses_ptr
= c
;
11568 gfor_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11569 *gforo_clauses_ptr
= copy_node (c
);
11570 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr
);
11572 /* For lastprivate, keep the clause on inner taskloop, and add
11573 a shared clause on task. If the same decl is also firstprivate,
11574 add also firstprivate clause on the inner taskloop. */
11575 case OMP_CLAUSE_LASTPRIVATE
:
11576 if (OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
))
11578 /* For taskloop C++ lastprivate IVs, we want:
11579 1) private on outer taskloop
11580 2) firstprivate and shared on task
11581 3) lastprivate on inner taskloop */
11583 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
11584 OMP_CLAUSE_FIRSTPRIVATE
);
11585 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
11586 lang_hooks
.decls
.omp_finish_clause (*gtask_clauses_ptr
, NULL
);
11587 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
11588 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
) = 1;
11589 *gforo_clauses_ptr
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
11590 OMP_CLAUSE_PRIVATE
);
11591 OMP_CLAUSE_DECL (*gforo_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
11592 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (*gforo_clauses_ptr
) = 1;
11593 TREE_TYPE (*gforo_clauses_ptr
) = TREE_TYPE (c
);
11594 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr
);
11596 *gfor_clauses_ptr
= c
;
11597 gfor_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
11599 = build_omp_clause (OMP_CLAUSE_LOCATION (c
), OMP_CLAUSE_SHARED
);
11600 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
11601 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
11602 OMP_CLAUSE_SHARED_FIRSTPRIVATE (*gtask_clauses_ptr
) = 1;
11604 = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
11607 gcc_unreachable ();
11609 *gfor_clauses_ptr
= NULL_TREE
;
11610 *gtask_clauses_ptr
= NULL_TREE
;
11611 *gforo_clauses_ptr
= NULL_TREE
;
11612 g
= gimple_build_bind (NULL_TREE
, gfor
, NULL_TREE
);
11613 g
= gimple_build_omp_task (g
, task_clauses
, NULL_TREE
, NULL_TREE
,
11614 NULL_TREE
, NULL_TREE
, NULL_TREE
);
11615 gimple_omp_task_set_taskloop_p (g
, true);
11616 g
= gimple_build_bind (NULL_TREE
, g
, NULL_TREE
);
11618 = gimple_build_omp_for (g
, GF_OMP_FOR_KIND_TASKLOOP
, outer_for_clauses
,
11619 gimple_omp_for_collapse (gfor
),
11620 gimple_omp_for_pre_body (gfor
));
11621 gimple_omp_for_set_pre_body (gfor
, NULL
);
11622 gimple_omp_for_set_combined_p (gforo
, true);
11623 gimple_omp_for_set_combined_into_p (gfor
, true);
11624 for (i
= 0; i
< (int) gimple_omp_for_collapse (gfor
); i
++)
11626 tree type
= TREE_TYPE (gimple_omp_for_index (gfor
, i
));
11627 tree v
= create_tmp_var (type
);
11628 gimple_omp_for_set_index (gforo
, i
, v
);
11629 t
= unshare_expr (gimple_omp_for_initial (gfor
, i
));
11630 gimple_omp_for_set_initial (gforo
, i
, t
);
11631 gimple_omp_for_set_cond (gforo
, i
,
11632 gimple_omp_for_cond (gfor
, i
));
11633 t
= unshare_expr (gimple_omp_for_final (gfor
, i
));
11634 gimple_omp_for_set_final (gforo
, i
, t
);
11635 t
= unshare_expr (gimple_omp_for_incr (gfor
, i
));
11636 gcc_assert (TREE_OPERAND (t
, 0) == gimple_omp_for_index (gfor
, i
));
11637 TREE_OPERAND (t
, 0) = v
;
11638 gimple_omp_for_set_incr (gforo
, i
, t
);
11639 t
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
11640 OMP_CLAUSE_DECL (t
) = v
;
11641 OMP_CLAUSE_CHAIN (t
) = gimple_omp_for_clauses (gforo
);
11642 gimple_omp_for_set_clauses (gforo
, t
);
11644 gimplify_seq_add_stmt (pre_p
, gforo
);
11647 gimplify_seq_add_stmt (pre_p
, gfor
);
11649 if (TREE_CODE (orig_for_stmt
) == OMP_FOR
)
11651 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
11652 unsigned lastprivate_conditional
= 0;
11654 && (ctx
->region_type
== ORT_TARGET_DATA
11655 || ctx
->region_type
== ORT_TASKGROUP
))
11656 ctx
= ctx
->outer_context
;
11657 if (ctx
&& (ctx
->region_type
& ORT_PARALLEL
) != 0)
11658 for (tree c
= gimple_omp_for_clauses (gfor
);
11659 c
; c
= OMP_CLAUSE_CHAIN (c
))
11660 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
11661 && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
))
11662 ++lastprivate_conditional
;
11663 if (lastprivate_conditional
)
11665 struct omp_for_data fd
;
11666 omp_extract_for_data (gfor
, &fd
, NULL
);
11667 tree type
= build_array_type_nelts (unsigned_type_for (fd
.iter_type
),
11668 lastprivate_conditional
);
11669 tree var
= create_tmp_var_raw (type
);
11670 tree c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE__CONDTEMP_
);
11671 OMP_CLAUSE_DECL (c
) = var
;
11672 OMP_CLAUSE_CHAIN (c
) = gimple_omp_for_clauses (gfor
);
11673 gimple_omp_for_set_clauses (gfor
, c
);
11674 omp_add_variable (ctx
, var
, GOVD_CONDTEMP
| GOVD_SEEN
);
11677 else if (TREE_CODE (orig_for_stmt
) == OMP_SIMD
)
11679 unsigned lastprivate_conditional
= 0;
11680 for (tree c
= gimple_omp_for_clauses (gfor
); c
; c
= OMP_CLAUSE_CHAIN (c
))
11681 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
11682 && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c
))
11683 ++lastprivate_conditional
;
11684 if (lastprivate_conditional
)
11686 struct omp_for_data fd
;
11687 omp_extract_for_data (gfor
, &fd
, NULL
);
11688 tree type
= unsigned_type_for (fd
.iter_type
);
11689 while (lastprivate_conditional
--)
11691 tree c
= build_omp_clause (UNKNOWN_LOCATION
,
11692 OMP_CLAUSE__CONDTEMP_
);
11693 OMP_CLAUSE_DECL (c
) = create_tmp_var (type
);
11694 OMP_CLAUSE_CHAIN (c
) = gimple_omp_for_clauses (gfor
);
11695 gimple_omp_for_set_clauses (gfor
, c
);
11700 if (ret
!= GS_ALL_DONE
)
11702 *expr_p
= NULL_TREE
;
11703 return GS_ALL_DONE
;
11706 /* Helper function of optimize_target_teams, find OMP_TEAMS inside
11707 of OMP_TARGET's body. */
11710 find_omp_teams (tree
*tp
, int *walk_subtrees
, void *)
11712 *walk_subtrees
= 0;
11713 switch (TREE_CODE (*tp
))
11718 case STATEMENT_LIST
:
11719 *walk_subtrees
= 1;
11727 /* Helper function of optimize_target_teams, determine if the expression
11728 can be computed safely before the target construct on the host. */
11731 computable_teams_clause (tree
*tp
, int *walk_subtrees
, void *)
11737 *walk_subtrees
= 0;
11740 switch (TREE_CODE (*tp
))
11745 *walk_subtrees
= 0;
11746 if (error_operand_p (*tp
)
11747 || !INTEGRAL_TYPE_P (TREE_TYPE (*tp
))
11748 || DECL_HAS_VALUE_EXPR_P (*tp
)
11749 || DECL_THREAD_LOCAL_P (*tp
)
11750 || TREE_SIDE_EFFECTS (*tp
)
11751 || TREE_THIS_VOLATILE (*tp
))
11753 if (is_global_var (*tp
)
11754 && (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (*tp
))
11755 || lookup_attribute ("omp declare target link",
11756 DECL_ATTRIBUTES (*tp
))))
11759 && !DECL_SEEN_IN_BIND_EXPR_P (*tp
)
11760 && !is_global_var (*tp
)
11761 && decl_function_context (*tp
) == current_function_decl
)
11763 n
= splay_tree_lookup (gimplify_omp_ctxp
->variables
,
11764 (splay_tree_key
) *tp
);
11767 if (gimplify_omp_ctxp
->defaultmap
[GDMK_SCALAR
] & GOVD_FIRSTPRIVATE
)
11771 else if (n
->value
& GOVD_LOCAL
)
11773 else if (n
->value
& GOVD_FIRSTPRIVATE
)
11775 else if ((n
->value
& (GOVD_MAP
| GOVD_MAP_ALWAYS_TO
))
11776 == (GOVD_MAP
| GOVD_MAP_ALWAYS_TO
))
11780 if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp
)))
11784 if (TARGET_EXPR_INITIAL (*tp
)
11785 || TREE_CODE (TARGET_EXPR_SLOT (*tp
)) != VAR_DECL
)
11787 return computable_teams_clause (&TARGET_EXPR_SLOT (*tp
),
11788 walk_subtrees
, NULL
);
11789 /* Allow some reasonable subset of integral arithmetics. */
11793 case TRUNC_DIV_EXPR
:
11794 case CEIL_DIV_EXPR
:
11795 case FLOOR_DIV_EXPR
:
11796 case ROUND_DIV_EXPR
:
11797 case TRUNC_MOD_EXPR
:
11798 case CEIL_MOD_EXPR
:
11799 case FLOOR_MOD_EXPR
:
11800 case ROUND_MOD_EXPR
:
11802 case EXACT_DIV_EXPR
:
11813 case NON_LVALUE_EXPR
:
11815 if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp
)))
11818 /* And disallow anything else, except for comparisons. */
11820 if (COMPARISON_CLASS_P (*tp
))
11826 /* Try to determine if the num_teams and/or thread_limit expressions
11827 can have their values determined already before entering the
11829 INTEGER_CSTs trivially are,
11830 integral decls that are firstprivate (explicitly or implicitly)
11831 or explicitly map(always, to:) or map(always, tofrom:) on the target
11832 region too, and expressions involving simple arithmetics on those
11833 too, function calls are not ok, dereferencing something neither etc.
11834 Add NUM_TEAMS and THREAD_LIMIT clauses to the OMP_CLAUSES of
11835 EXPR based on what we find:
11836 0 stands for clause not specified at all, use implementation default
11837 -1 stands for value that can't be determined easily before entering
11838 the target construct.
11839 If teams construct is not present at all, use 1 for num_teams
11840 and 0 for thread_limit (only one team is involved, and the thread
11841 limit is implementation defined. */
11844 optimize_target_teams (tree target
, gimple_seq
*pre_p
)
11846 tree body
= OMP_BODY (target
);
11847 tree teams
= walk_tree (&body
, find_omp_teams
, NULL
, NULL
);
11848 tree num_teams
= integer_zero_node
;
11849 tree thread_limit
= integer_zero_node
;
11850 location_t num_teams_loc
= EXPR_LOCATION (target
);
11851 location_t thread_limit_loc
= EXPR_LOCATION (target
);
11853 struct gimplify_omp_ctx
*target_ctx
= gimplify_omp_ctxp
;
11855 if (teams
== NULL_TREE
)
11856 num_teams
= integer_one_node
;
11858 for (c
= OMP_TEAMS_CLAUSES (teams
); c
; c
= OMP_CLAUSE_CHAIN (c
))
11860 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
)
11863 num_teams_loc
= OMP_CLAUSE_LOCATION (c
);
11865 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
11868 thread_limit_loc
= OMP_CLAUSE_LOCATION (c
);
11872 expr
= OMP_CLAUSE_OPERAND (c
, 0);
11873 if (TREE_CODE (expr
) == INTEGER_CST
)
11878 if (walk_tree (&expr
, computable_teams_clause
, NULL
, NULL
))
11880 *p
= integer_minus_one_node
;
11884 gimplify_omp_ctxp
= gimplify_omp_ctxp
->outer_context
;
11885 if (gimplify_expr (p
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
, false)
11888 gimplify_omp_ctxp
= target_ctx
;
11889 *p
= integer_minus_one_node
;
11892 gimplify_omp_ctxp
= target_ctx
;
11893 if (!DECL_P (expr
) && TREE_CODE (expr
) != TARGET_EXPR
)
11894 OMP_CLAUSE_OPERAND (c
, 0) = *p
;
11896 c
= build_omp_clause (thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11897 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = thread_limit
;
11898 OMP_CLAUSE_CHAIN (c
) = OMP_TARGET_CLAUSES (target
);
11899 OMP_TARGET_CLAUSES (target
) = c
;
11900 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11901 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = num_teams
;
11902 OMP_CLAUSE_CHAIN (c
) = OMP_TARGET_CLAUSES (target
);
11903 OMP_TARGET_CLAUSES (target
) = c
;
11906 /* Gimplify the gross structure of several OMP constructs. */
11909 gimplify_omp_workshare (tree
*expr_p
, gimple_seq
*pre_p
)
11911 tree expr
= *expr_p
;
11913 gimple_seq body
= NULL
;
11914 enum omp_region_type ort
;
11916 switch (TREE_CODE (expr
))
11920 ort
= ORT_WORKSHARE
;
11923 ort
= OMP_TARGET_COMBINED (expr
) ? ORT_COMBINED_TARGET
: ORT_TARGET
;
11926 ort
= ORT_ACC_KERNELS
;
11928 case OACC_PARALLEL
:
11929 ort
= ORT_ACC_PARALLEL
;
11932 ort
= ORT_ACC_DATA
;
11934 case OMP_TARGET_DATA
:
11935 ort
= ORT_TARGET_DATA
;
11938 ort
= OMP_TEAMS_COMBINED (expr
) ? ORT_COMBINED_TEAMS
: ORT_TEAMS
;
11939 if (gimplify_omp_ctxp
== NULL
11940 || (gimplify_omp_ctxp
->region_type
== ORT_TARGET
11941 && gimplify_omp_ctxp
->outer_context
== NULL
11942 && lookup_attribute ("omp declare target",
11943 DECL_ATTRIBUTES (current_function_decl
))))
11944 ort
= (enum omp_region_type
) (ort
| ORT_HOST_TEAMS
);
11946 case OACC_HOST_DATA
:
11947 ort
= ORT_ACC_HOST_DATA
;
11950 gcc_unreachable ();
11952 gimplify_scan_omp_clauses (&OMP_CLAUSES (expr
), pre_p
, ort
,
11954 if (TREE_CODE (expr
) == OMP_TARGET
)
11955 optimize_target_teams (expr
, pre_p
);
11956 if ((ort
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0
11957 || (ort
& ORT_HOST_TEAMS
) == ORT_HOST_TEAMS
)
11959 push_gimplify_context ();
11960 gimple
*g
= gimplify_and_return_first (OMP_BODY (expr
), &body
);
11961 if (gimple_code (g
) == GIMPLE_BIND
)
11962 pop_gimplify_context (g
);
11964 pop_gimplify_context (NULL
);
11965 if ((ort
& ORT_TARGET_DATA
) != 0)
11967 enum built_in_function end_ix
;
11968 switch (TREE_CODE (expr
))
11971 case OACC_HOST_DATA
:
11972 end_ix
= BUILT_IN_GOACC_DATA_END
;
11974 case OMP_TARGET_DATA
:
11975 end_ix
= BUILT_IN_GOMP_TARGET_END_DATA
;
11978 gcc_unreachable ();
11980 tree fn
= builtin_decl_explicit (end_ix
);
11981 g
= gimple_build_call (fn
, 0);
11982 gimple_seq cleanup
= NULL
;
11983 gimple_seq_add_stmt (&cleanup
, g
);
11984 g
= gimple_build_try (body
, cleanup
, GIMPLE_TRY_FINALLY
);
11986 gimple_seq_add_stmt (&body
, g
);
11990 gimplify_and_add (OMP_BODY (expr
), &body
);
11991 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_CLAUSES (expr
),
11994 switch (TREE_CODE (expr
))
11997 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_DATA
,
11998 OMP_CLAUSES (expr
));
12001 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_KERNELS
,
12002 OMP_CLAUSES (expr
));
12004 case OACC_HOST_DATA
:
12005 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_HOST_DATA
,
12006 OMP_CLAUSES (expr
));
12008 case OACC_PARALLEL
:
12009 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_PARALLEL
,
12010 OMP_CLAUSES (expr
));
12013 stmt
= gimple_build_omp_sections (body
, OMP_CLAUSES (expr
));
12016 stmt
= gimple_build_omp_single (body
, OMP_CLAUSES (expr
));
12019 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_REGION
,
12020 OMP_CLAUSES (expr
));
12022 case OMP_TARGET_DATA
:
12023 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_DATA
,
12024 OMP_CLAUSES (expr
));
12027 stmt
= gimple_build_omp_teams (body
, OMP_CLAUSES (expr
));
12028 if ((ort
& ORT_HOST_TEAMS
) == ORT_HOST_TEAMS
)
12029 gimple_omp_teams_set_host (as_a
<gomp_teams
*> (stmt
), true);
12032 gcc_unreachable ();
12035 gimplify_seq_add_stmt (pre_p
, stmt
);
12036 *expr_p
= NULL_TREE
;
12039 /* Gimplify the gross structure of OpenACC enter/exit data, update, and OpenMP
12040 target update constructs. */
12043 gimplify_omp_target_update (tree
*expr_p
, gimple_seq
*pre_p
)
12045 tree expr
= *expr_p
;
12048 enum omp_region_type ort
= ORT_WORKSHARE
;
12050 switch (TREE_CODE (expr
))
12052 case OACC_ENTER_DATA
:
12053 case OACC_EXIT_DATA
:
12054 kind
= GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA
;
12058 kind
= GF_OMP_TARGET_KIND_OACC_UPDATE
;
12061 case OMP_TARGET_UPDATE
:
12062 kind
= GF_OMP_TARGET_KIND_UPDATE
;
12064 case OMP_TARGET_ENTER_DATA
:
12065 kind
= GF_OMP_TARGET_KIND_ENTER_DATA
;
12067 case OMP_TARGET_EXIT_DATA
:
12068 kind
= GF_OMP_TARGET_KIND_EXIT_DATA
;
12071 gcc_unreachable ();
12073 gimplify_scan_omp_clauses (&OMP_STANDALONE_CLAUSES (expr
), pre_p
,
12074 ort
, TREE_CODE (expr
));
12075 gimplify_adjust_omp_clauses (pre_p
, NULL
, &OMP_STANDALONE_CLAUSES (expr
),
12077 if (TREE_CODE (expr
) == OACC_UPDATE
12078 && omp_find_clause (OMP_STANDALONE_CLAUSES (expr
),
12079 OMP_CLAUSE_IF_PRESENT
))
12081 /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
12083 for (tree c
= OMP_STANDALONE_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
12084 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
12085 switch (OMP_CLAUSE_MAP_KIND (c
))
12087 case GOMP_MAP_FORCE_TO
:
12088 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TO
);
12090 case GOMP_MAP_FORCE_FROM
:
12091 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_FROM
);
12097 else if (TREE_CODE (expr
) == OACC_EXIT_DATA
12098 && omp_find_clause (OMP_STANDALONE_CLAUSES (expr
),
12099 OMP_CLAUSE_FINALIZE
))
12101 /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
12102 semantics apply to all mappings of this OpenACC directive. */
12103 bool finalize_marked
= false;
12104 for (tree c
= OMP_STANDALONE_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
12105 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
12106 switch (OMP_CLAUSE_MAP_KIND (c
))
12108 case GOMP_MAP_FROM
:
12109 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_FORCE_FROM
);
12110 finalize_marked
= true;
12112 case GOMP_MAP_RELEASE
:
12113 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_DELETE
);
12114 finalize_marked
= true;
12117 /* Check consistency: libgomp relies on the very first data
12118 mapping clause being marked, so make sure we did that before
12119 any other mapping clauses. */
12120 gcc_assert (finalize_marked
);
12124 stmt
= gimple_build_omp_target (NULL
, kind
, OMP_STANDALONE_CLAUSES (expr
));
12126 gimplify_seq_add_stmt (pre_p
, stmt
);
12127 *expr_p
= NULL_TREE
;
12130 /* A subroutine of gimplify_omp_atomic. The front end is supposed to have
12131 stabilized the lhs of the atomic operation as *ADDR. Return true if
12132 EXPR is this stabilized form. */
12135 goa_lhs_expr_p (tree expr
, tree addr
)
12137 /* Also include casts to other type variants. The C front end is fond
12138 of adding these for e.g. volatile variables. This is like
12139 STRIP_TYPE_NOPS but includes the main variant lookup. */
12140 STRIP_USELESS_TYPE_CONVERSION (expr
);
12142 if (TREE_CODE (expr
) == INDIRECT_REF
)
12144 expr
= TREE_OPERAND (expr
, 0);
12145 while (expr
!= addr
12146 && (CONVERT_EXPR_P (expr
)
12147 || TREE_CODE (expr
) == NON_LVALUE_EXPR
)
12148 && TREE_CODE (expr
) == TREE_CODE (addr
)
12149 && types_compatible_p (TREE_TYPE (expr
), TREE_TYPE (addr
)))
12151 expr
= TREE_OPERAND (expr
, 0);
12152 addr
= TREE_OPERAND (addr
, 0);
12156 return (TREE_CODE (addr
) == ADDR_EXPR
12157 && TREE_CODE (expr
) == ADDR_EXPR
12158 && TREE_OPERAND (addr
, 0) == TREE_OPERAND (expr
, 0));
12160 if (TREE_CODE (addr
) == ADDR_EXPR
&& expr
== TREE_OPERAND (addr
, 0))
12165 /* Walk *EXPR_P and replace appearances of *LHS_ADDR with LHS_VAR. If an
12166 expression does not involve the lhs, evaluate it into a temporary.
12167 Return 1 if the lhs appeared as a subexpression, 0 if it did not,
12168 or -1 if an error was encountered. */
12171 goa_stabilize_expr (tree
*expr_p
, gimple_seq
*pre_p
, tree lhs_addr
,
12174 tree expr
= *expr_p
;
12177 if (goa_lhs_expr_p (expr
, lhs_addr
))
12182 if (is_gimple_val (expr
))
12186 switch (TREE_CODE_CLASS (TREE_CODE (expr
)))
12189 case tcc_comparison
:
12190 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 1), pre_p
, lhs_addr
,
12194 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
, lhs_addr
,
12197 case tcc_expression
:
12198 switch (TREE_CODE (expr
))
12200 case TRUTH_ANDIF_EXPR
:
12201 case TRUTH_ORIF_EXPR
:
12202 case TRUTH_AND_EXPR
:
12203 case TRUTH_OR_EXPR
:
12204 case TRUTH_XOR_EXPR
:
12205 case BIT_INSERT_EXPR
:
12206 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 1), pre_p
,
12207 lhs_addr
, lhs_var
);
12209 case TRUTH_NOT_EXPR
:
12210 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
,
12211 lhs_addr
, lhs_var
);
12213 case COMPOUND_EXPR
:
12214 /* Break out any preevaluations from cp_build_modify_expr. */
12215 for (; TREE_CODE (expr
) == COMPOUND_EXPR
;
12216 expr
= TREE_OPERAND (expr
, 1))
12217 gimplify_stmt (&TREE_OPERAND (expr
, 0), pre_p
);
12219 return goa_stabilize_expr (expr_p
, pre_p
, lhs_addr
, lhs_var
);
12224 case tcc_reference
:
12225 if (TREE_CODE (expr
) == BIT_FIELD_REF
)
12226 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
,
12227 lhs_addr
, lhs_var
);
12235 enum gimplify_status gs
;
12236 gs
= gimplify_expr (expr_p
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
12237 if (gs
!= GS_ALL_DONE
)
12244 /* Gimplify an OMP_ATOMIC statement. */
12246 static enum gimplify_status
12247 gimplify_omp_atomic (tree
*expr_p
, gimple_seq
*pre_p
)
12249 tree addr
= TREE_OPERAND (*expr_p
, 0);
12250 tree rhs
= TREE_CODE (*expr_p
) == OMP_ATOMIC_READ
12251 ? NULL
: TREE_OPERAND (*expr_p
, 1);
12252 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr
)));
12254 gomp_atomic_load
*loadstmt
;
12255 gomp_atomic_store
*storestmt
;
12257 tmp_load
= create_tmp_reg (type
);
12258 if (rhs
&& goa_stabilize_expr (&rhs
, pre_p
, addr
, tmp_load
) < 0)
12261 if (gimplify_expr (&addr
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
12265 loadstmt
= gimple_build_omp_atomic_load (tmp_load
, addr
,
12266 OMP_ATOMIC_MEMORY_ORDER (*expr_p
));
12267 gimplify_seq_add_stmt (pre_p
, loadstmt
);
12270 /* BIT_INSERT_EXPR is not valid for non-integral bitfield
12271 representatives. Use BIT_FIELD_REF on the lhs instead. */
12272 if (TREE_CODE (rhs
) == BIT_INSERT_EXPR
12273 && !INTEGRAL_TYPE_P (TREE_TYPE (tmp_load
)))
12275 tree bitpos
= TREE_OPERAND (rhs
, 2);
12276 tree op1
= TREE_OPERAND (rhs
, 1);
12278 tree tmp_store
= tmp_load
;
12279 if (TREE_CODE (*expr_p
) == OMP_ATOMIC_CAPTURE_OLD
)
12280 tmp_store
= get_initialized_tmp_var (tmp_load
, pre_p
, NULL
);
12281 if (INTEGRAL_TYPE_P (TREE_TYPE (op1
)))
12282 bitsize
= bitsize_int (TYPE_PRECISION (TREE_TYPE (op1
)));
12284 bitsize
= TYPE_SIZE (TREE_TYPE (op1
));
12285 gcc_assert (TREE_OPERAND (rhs
, 0) == tmp_load
);
12286 tree t
= build2_loc (EXPR_LOCATION (rhs
),
12287 MODIFY_EXPR
, void_type_node
,
12288 build3_loc (EXPR_LOCATION (rhs
), BIT_FIELD_REF
,
12289 TREE_TYPE (op1
), tmp_store
, bitsize
,
12291 gimplify_and_add (t
, pre_p
);
12294 if (gimplify_expr (&rhs
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
12299 if (TREE_CODE (*expr_p
) == OMP_ATOMIC_READ
)
12302 = gimple_build_omp_atomic_store (rhs
, OMP_ATOMIC_MEMORY_ORDER (*expr_p
));
12303 gimplify_seq_add_stmt (pre_p
, storestmt
);
12304 switch (TREE_CODE (*expr_p
))
12306 case OMP_ATOMIC_READ
:
12307 case OMP_ATOMIC_CAPTURE_OLD
:
12308 *expr_p
= tmp_load
;
12309 gimple_omp_atomic_set_need_value (loadstmt
);
12311 case OMP_ATOMIC_CAPTURE_NEW
:
12313 gimple_omp_atomic_set_need_value (storestmt
);
12320 return GS_ALL_DONE
;
12323 /* Gimplify a TRANSACTION_EXPR. This involves gimplification of the
12324 body, and adding some EH bits. */
12326 static enum gimplify_status
12327 gimplify_transaction (tree
*expr_p
, gimple_seq
*pre_p
)
12329 tree expr
= *expr_p
, temp
, tbody
= TRANSACTION_EXPR_BODY (expr
);
12331 gtransaction
*trans_stmt
;
12332 gimple_seq body
= NULL
;
12335 /* Wrap the transaction body in a BIND_EXPR so we have a context
12336 where to put decls for OMP. */
12337 if (TREE_CODE (tbody
) != BIND_EXPR
)
12339 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, tbody
, NULL
);
12340 TREE_SIDE_EFFECTS (bind
) = 1;
12341 SET_EXPR_LOCATION (bind
, EXPR_LOCATION (tbody
));
12342 TRANSACTION_EXPR_BODY (expr
) = bind
;
12345 push_gimplify_context ();
12346 temp
= voidify_wrapper_expr (*expr_p
, NULL
);
12348 body_stmt
= gimplify_and_return_first (TRANSACTION_EXPR_BODY (expr
), &body
);
12349 pop_gimplify_context (body_stmt
);
12351 trans_stmt
= gimple_build_transaction (body
);
12352 if (TRANSACTION_EXPR_OUTER (expr
))
12353 subcode
= GTMA_IS_OUTER
;
12354 else if (TRANSACTION_EXPR_RELAXED (expr
))
12355 subcode
= GTMA_IS_RELAXED
;
12356 gimple_transaction_set_subcode (trans_stmt
, subcode
);
12358 gimplify_seq_add_stmt (pre_p
, trans_stmt
);
12366 *expr_p
= NULL_TREE
;
12367 return GS_ALL_DONE
;
12370 /* Gimplify an OMP_ORDERED construct. EXPR is the tree version. BODY
12371 is the OMP_BODY of the original EXPR (which has already been
12372 gimplified so it's not present in the EXPR).
12374 Return the gimplified GIMPLE_OMP_ORDERED tuple. */
12377 gimplify_omp_ordered (tree expr
, gimple_seq body
)
12382 tree source_c
= NULL_TREE
;
12383 tree sink_c
= NULL_TREE
;
12385 if (gimplify_omp_ctxp
)
12387 for (c
= OMP_ORDERED_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
12388 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12389 && gimplify_omp_ctxp
->loop_iter_var
.is_empty ()
12390 && (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
12391 || OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
))
12393 error_at (OMP_CLAUSE_LOCATION (c
),
12394 "%<ordered%> construct with %<depend%> clause must be "
12395 "closely nested inside a loop with %<ordered%> clause "
12396 "with a parameter");
12399 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12400 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
12403 for (decls
= OMP_CLAUSE_DECL (c
), i
= 0;
12404 decls
&& TREE_CODE (decls
) == TREE_LIST
;
12405 decls
= TREE_CHAIN (decls
), ++i
)
12406 if (i
>= gimplify_omp_ctxp
->loop_iter_var
.length () / 2)
12408 else if (TREE_VALUE (decls
)
12409 != gimplify_omp_ctxp
->loop_iter_var
[2 * i
])
12411 error_at (OMP_CLAUSE_LOCATION (c
),
12412 "variable %qE is not an iteration "
12413 "of outermost loop %d, expected %qE",
12414 TREE_VALUE (decls
), i
+ 1,
12415 gimplify_omp_ctxp
->loop_iter_var
[2 * i
]);
12421 = gimplify_omp_ctxp
->loop_iter_var
[2 * i
+ 1];
12422 if (!fail
&& i
!= gimplify_omp_ctxp
->loop_iter_var
.length () / 2)
12424 error_at (OMP_CLAUSE_LOCATION (c
),
12425 "number of variables in %<depend%> clause with "
12426 "%<sink%> modifier does not match number of "
12427 "iteration variables");
12432 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12433 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
)
12437 error_at (OMP_CLAUSE_LOCATION (c
),
12438 "more than one %<depend%> clause with %<source%> "
12439 "modifier on an %<ordered%> construct");
12446 if (source_c
&& sink_c
)
12448 error_at (OMP_CLAUSE_LOCATION (source_c
),
12449 "%<depend%> clause with %<source%> modifier specified "
12450 "together with %<depend%> clauses with %<sink%> modifier "
12451 "on the same construct");
12456 return gimple_build_nop ();
12457 return gimple_build_omp_ordered (body
, OMP_ORDERED_CLAUSES (expr
));
12460 /* Convert the GENERIC expression tree *EXPR_P to GIMPLE. If the
12461 expression produces a value to be used as an operand inside a GIMPLE
12462 statement, the value will be stored back in *EXPR_P. This value will
12463 be a tree of class tcc_declaration, tcc_constant, tcc_reference or
12464 an SSA_NAME. The corresponding sequence of GIMPLE statements is
12465 emitted in PRE_P and POST_P.
12467 Additionally, this process may overwrite parts of the input
12468 expression during gimplification. Ideally, it should be
12469 possible to do non-destructive gimplification.
12471 EXPR_P points to the GENERIC expression to convert to GIMPLE. If
12472 the expression needs to evaluate to a value to be used as
12473 an operand in a GIMPLE statement, this value will be stored in
12474 *EXPR_P on exit. This happens when the caller specifies one
12475 of fb_lvalue or fb_rvalue fallback flags.
12477 PRE_P will contain the sequence of GIMPLE statements corresponding
12478 to the evaluation of EXPR and all the side-effects that must
12479 be executed before the main expression. On exit, the last
12480 statement of PRE_P is the core statement being gimplified. For
12481 instance, when gimplifying 'if (++a)' the last statement in
12482 PRE_P will be 'if (t.1)' where t.1 is the result of
12483 pre-incrementing 'a'.
12485 POST_P will contain the sequence of GIMPLE statements corresponding
12486 to the evaluation of all the side-effects that must be executed
12487 after the main expression. If this is NULL, the post
12488 side-effects are stored at the end of PRE_P.
12490 The reason why the output is split in two is to handle post
12491 side-effects explicitly. In some cases, an expression may have
12492 inner and outer post side-effects which need to be emitted in
12493 an order different from the one given by the recursive
12494 traversal. For instance, for the expression (*p--)++ the post
12495 side-effects of '--' must actually occur *after* the post
12496 side-effects of '++'. However, gimplification will first visit
12497 the inner expression, so if a separate POST sequence was not
12498 used, the resulting sequence would be:
12505 However, the post-decrement operation in line #2 must not be
12506 evaluated until after the store to *p at line #4, so the
12507 correct sequence should be:
12514 So, by specifying a separate post queue, it is possible
12515 to emit the post side-effects in the correct order.
12516 If POST_P is NULL, an internal queue will be used. Before
12517 returning to the caller, the sequence POST_P is appended to
12518 the main output sequence PRE_P.
12520 GIMPLE_TEST_F points to a function that takes a tree T and
12521 returns nonzero if T is in the GIMPLE form requested by the
12522 caller. The GIMPLE predicates are in gimple.c.
12524 FALLBACK tells the function what sort of a temporary we want if
12525 gimplification cannot produce an expression that complies with
12528 fb_none means that no temporary should be generated
12529 fb_rvalue means that an rvalue is OK to generate
12530 fb_lvalue means that an lvalue is OK to generate
12531 fb_either means that either is OK, but an lvalue is preferable.
12532 fb_mayfail means that gimplification may fail (in which case
12533 GS_ERROR will be returned)
12535 The return value is either GS_ERROR or GS_ALL_DONE, since this
12536 function iterates until EXPR is completely gimplified or an error
12539 enum gimplify_status
12540 gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
12541 bool (*gimple_test_f
) (tree
), fallback_t fallback
)
12544 gimple_seq internal_pre
= NULL
;
12545 gimple_seq internal_post
= NULL
;
12548 location_t saved_location
;
12549 enum gimplify_status ret
;
12550 gimple_stmt_iterator pre_last_gsi
, post_last_gsi
;
12553 save_expr
= *expr_p
;
12554 if (save_expr
== NULL_TREE
)
12555 return GS_ALL_DONE
;
12557 /* If we are gimplifying a top-level statement, PRE_P must be valid. */
12558 is_statement
= gimple_test_f
== is_gimple_stmt
;
12560 gcc_assert (pre_p
);
12562 /* Consistency checks. */
12563 if (gimple_test_f
== is_gimple_reg
)
12564 gcc_assert (fallback
& (fb_rvalue
| fb_lvalue
));
12565 else if (gimple_test_f
== is_gimple_val
12566 || gimple_test_f
== is_gimple_call_addr
12567 || gimple_test_f
== is_gimple_condexpr
12568 || gimple_test_f
== is_gimple_mem_rhs
12569 || gimple_test_f
== is_gimple_mem_rhs_or_call
12570 || gimple_test_f
== is_gimple_reg_rhs
12571 || gimple_test_f
== is_gimple_reg_rhs_or_call
12572 || gimple_test_f
== is_gimple_asm_val
12573 || gimple_test_f
== is_gimple_mem_ref_addr
)
12574 gcc_assert (fallback
& fb_rvalue
);
12575 else if (gimple_test_f
== is_gimple_min_lval
12576 || gimple_test_f
== is_gimple_lvalue
)
12577 gcc_assert (fallback
& fb_lvalue
);
12578 else if (gimple_test_f
== is_gimple_addressable
)
12579 gcc_assert (fallback
& fb_either
);
12580 else if (gimple_test_f
== is_gimple_stmt
)
12581 gcc_assert (fallback
== fb_none
);
12584 /* We should have recognized the GIMPLE_TEST_F predicate to
12585 know what kind of fallback to use in case a temporary is
12586 needed to hold the value or address of *EXPR_P. */
12587 gcc_unreachable ();
12590 /* We used to check the predicate here and return immediately if it
12591 succeeds. This is wrong; the design is for gimplification to be
12592 idempotent, and for the predicates to only test for valid forms, not
12593 whether they are fully simplified. */
12595 pre_p
= &internal_pre
;
12597 if (post_p
== NULL
)
12598 post_p
= &internal_post
;
12600 /* Remember the last statements added to PRE_P and POST_P. Every
12601 new statement added by the gimplification helpers needs to be
12602 annotated with location information. To centralize the
12603 responsibility, we remember the last statement that had been
12604 added to both queues before gimplifying *EXPR_P. If
12605 gimplification produces new statements in PRE_P and POST_P, those
12606 statements will be annotated with the same location information
12608 pre_last_gsi
= gsi_last (*pre_p
);
12609 post_last_gsi
= gsi_last (*post_p
);
12611 saved_location
= input_location
;
12612 if (save_expr
!= error_mark_node
12613 && EXPR_HAS_LOCATION (*expr_p
))
12614 input_location
= EXPR_LOCATION (*expr_p
);
12616 /* Loop over the specific gimplifiers until the toplevel node
12617 remains the same. */
12620 /* Strip away as many useless type conversions as possible
12621 at the toplevel. */
12622 STRIP_USELESS_TYPE_CONVERSION (*expr_p
);
12624 /* Remember the expr. */
12625 save_expr
= *expr_p
;
12627 /* Die, die, die, my darling. */
12628 if (error_operand_p (save_expr
))
12634 /* Do any language-specific gimplification. */
12635 ret
= ((enum gimplify_status
)
12636 lang_hooks
.gimplify_expr (expr_p
, pre_p
, post_p
));
12639 if (*expr_p
== NULL_TREE
)
12641 if (*expr_p
!= save_expr
)
12644 else if (ret
!= GS_UNHANDLED
)
12647 /* Make sure that all the cases set 'ret' appropriately. */
12648 ret
= GS_UNHANDLED
;
12649 switch (TREE_CODE (*expr_p
))
12651 /* First deal with the special cases. */
12653 case POSTINCREMENT_EXPR
:
12654 case POSTDECREMENT_EXPR
:
12655 case PREINCREMENT_EXPR
:
12656 case PREDECREMENT_EXPR
:
12657 ret
= gimplify_self_mod_expr (expr_p
, pre_p
, post_p
,
12658 fallback
!= fb_none
,
12659 TREE_TYPE (*expr_p
));
12662 case VIEW_CONVERT_EXPR
:
12663 if ((fallback
& fb_rvalue
)
12664 && is_gimple_reg_type (TREE_TYPE (*expr_p
))
12665 && is_gimple_reg_type (TREE_TYPE (TREE_OPERAND (*expr_p
, 0))))
12667 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12668 post_p
, is_gimple_val
, fb_rvalue
);
12669 recalculate_side_effects (*expr_p
);
12675 case ARRAY_RANGE_REF
:
12676 case REALPART_EXPR
:
12677 case IMAGPART_EXPR
:
12678 case COMPONENT_REF
:
12679 ret
= gimplify_compound_lval (expr_p
, pre_p
, post_p
,
12680 fallback
? fallback
: fb_rvalue
);
12684 ret
= gimplify_cond_expr (expr_p
, pre_p
, fallback
);
12686 /* C99 code may assign to an array in a structure value of a
12687 conditional expression, and this has undefined behavior
12688 only on execution, so create a temporary if an lvalue is
12690 if (fallback
== fb_lvalue
)
12692 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
12693 mark_addressable (*expr_p
);
12699 ret
= gimplify_call_expr (expr_p
, pre_p
, fallback
!= fb_none
);
12701 /* C99 code may assign to an array in a structure returned
12702 from a function, and this has undefined behavior only on
12703 execution, so create a temporary if an lvalue is
12705 if (fallback
== fb_lvalue
)
12707 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
12708 mark_addressable (*expr_p
);
12714 gcc_unreachable ();
12716 case COMPOUND_EXPR
:
12717 ret
= gimplify_compound_expr (expr_p
, pre_p
, fallback
!= fb_none
);
12720 case COMPOUND_LITERAL_EXPR
:
12721 ret
= gimplify_compound_literal_expr (expr_p
, pre_p
,
12722 gimple_test_f
, fallback
);
12727 ret
= gimplify_modify_expr (expr_p
, pre_p
, post_p
,
12728 fallback
!= fb_none
);
12731 case TRUTH_ANDIF_EXPR
:
12732 case TRUTH_ORIF_EXPR
:
12734 /* Preserve the original type of the expression and the
12735 source location of the outer expression. */
12736 tree org_type
= TREE_TYPE (*expr_p
);
12737 *expr_p
= gimple_boolify (*expr_p
);
12738 *expr_p
= build3_loc (input_location
, COND_EXPR
,
12742 org_type
, boolean_true_node
),
12745 org_type
, boolean_false_node
));
12750 case TRUTH_NOT_EXPR
:
12752 tree type
= TREE_TYPE (*expr_p
);
12753 /* The parsers are careful to generate TRUTH_NOT_EXPR
12754 only with operands that are always zero or one.
12755 We do not fold here but handle the only interesting case
12756 manually, as fold may re-introduce the TRUTH_NOT_EXPR. */
12757 *expr_p
= gimple_boolify (*expr_p
);
12758 if (TYPE_PRECISION (TREE_TYPE (*expr_p
)) == 1)
12759 *expr_p
= build1_loc (input_location
, BIT_NOT_EXPR
,
12760 TREE_TYPE (*expr_p
),
12761 TREE_OPERAND (*expr_p
, 0));
12763 *expr_p
= build2_loc (input_location
, BIT_XOR_EXPR
,
12764 TREE_TYPE (*expr_p
),
12765 TREE_OPERAND (*expr_p
, 0),
12766 build_int_cst (TREE_TYPE (*expr_p
), 1));
12767 if (!useless_type_conversion_p (type
, TREE_TYPE (*expr_p
)))
12768 *expr_p
= fold_convert_loc (input_location
, type
, *expr_p
);
12774 ret
= gimplify_addr_expr (expr_p
, pre_p
, post_p
);
12777 case ANNOTATE_EXPR
:
12779 tree cond
= TREE_OPERAND (*expr_p
, 0);
12780 tree kind
= TREE_OPERAND (*expr_p
, 1);
12781 tree data
= TREE_OPERAND (*expr_p
, 2);
12782 tree type
= TREE_TYPE (cond
);
12783 if (!INTEGRAL_TYPE_P (type
))
12789 tree tmp
= create_tmp_var (type
);
12790 gimplify_arg (&cond
, pre_p
, EXPR_LOCATION (*expr_p
));
12792 = gimple_build_call_internal (IFN_ANNOTATE
, 3, cond
, kind
, data
);
12793 gimple_call_set_lhs (call
, tmp
);
12794 gimplify_seq_add_stmt (pre_p
, call
);
12801 ret
= gimplify_va_arg_expr (expr_p
, pre_p
, post_p
);
12805 if (IS_EMPTY_STMT (*expr_p
))
12811 if (VOID_TYPE_P (TREE_TYPE (*expr_p
))
12812 || fallback
== fb_none
)
12814 /* Just strip a conversion to void (or in void context) and
12816 *expr_p
= TREE_OPERAND (*expr_p
, 0);
12821 ret
= gimplify_conversion (expr_p
);
12822 if (ret
== GS_ERROR
)
12824 if (*expr_p
!= save_expr
)
12828 case FIX_TRUNC_EXPR
:
12829 /* unary_expr: ... | '(' cast ')' val | ... */
12830 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
12831 is_gimple_val
, fb_rvalue
);
12832 recalculate_side_effects (*expr_p
);
12837 bool volatilep
= TREE_THIS_VOLATILE (*expr_p
);
12838 bool notrap
= TREE_THIS_NOTRAP (*expr_p
);
12839 tree saved_ptr_type
= TREE_TYPE (TREE_OPERAND (*expr_p
, 0));
12841 *expr_p
= fold_indirect_ref_loc (input_location
, *expr_p
);
12842 if (*expr_p
!= save_expr
)
12848 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
12849 is_gimple_reg
, fb_rvalue
);
12850 if (ret
== GS_ERROR
)
12853 recalculate_side_effects (*expr_p
);
12854 *expr_p
= fold_build2_loc (input_location
, MEM_REF
,
12855 TREE_TYPE (*expr_p
),
12856 TREE_OPERAND (*expr_p
, 0),
12857 build_int_cst (saved_ptr_type
, 0));
12858 TREE_THIS_VOLATILE (*expr_p
) = volatilep
;
12859 TREE_THIS_NOTRAP (*expr_p
) = notrap
;
12864 /* We arrive here through the various re-gimplifcation paths. */
12866 /* First try re-folding the whole thing. */
12867 tmp
= fold_binary (MEM_REF
, TREE_TYPE (*expr_p
),
12868 TREE_OPERAND (*expr_p
, 0),
12869 TREE_OPERAND (*expr_p
, 1));
12872 REF_REVERSE_STORAGE_ORDER (tmp
)
12873 = REF_REVERSE_STORAGE_ORDER (*expr_p
);
12875 recalculate_side_effects (*expr_p
);
12879 /* Avoid re-gimplifying the address operand if it is already
12880 in suitable form. Re-gimplifying would mark the address
12881 operand addressable. Always gimplify when not in SSA form
12882 as we still may have to gimplify decls with value-exprs. */
12883 if (!gimplify_ctxp
|| !gimple_in_ssa_p (cfun
)
12884 || !is_gimple_mem_ref_addr (TREE_OPERAND (*expr_p
, 0)))
12886 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
12887 is_gimple_mem_ref_addr
, fb_rvalue
);
12888 if (ret
== GS_ERROR
)
12891 recalculate_side_effects (*expr_p
);
12895 /* Constants need not be gimplified. */
12902 /* Drop the overflow flag on constants, we do not want
12903 that in the GIMPLE IL. */
12904 if (TREE_OVERFLOW_P (*expr_p
))
12905 *expr_p
= drop_tree_overflow (*expr_p
);
12910 /* If we require an lvalue, such as for ADDR_EXPR, retain the
12911 CONST_DECL node. Otherwise the decl is replaceable by its
12913 /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either. */
12914 if (fallback
& fb_lvalue
)
12918 *expr_p
= DECL_INITIAL (*expr_p
);
12924 ret
= gimplify_decl_expr (expr_p
, pre_p
);
12928 ret
= gimplify_bind_expr (expr_p
, pre_p
);
12932 ret
= gimplify_loop_expr (expr_p
, pre_p
);
12936 ret
= gimplify_switch_expr (expr_p
, pre_p
);
12940 ret
= gimplify_exit_expr (expr_p
);
12944 /* If the target is not LABEL, then it is a computed jump
12945 and the target needs to be gimplified. */
12946 if (TREE_CODE (GOTO_DESTINATION (*expr_p
)) != LABEL_DECL
)
12948 ret
= gimplify_expr (&GOTO_DESTINATION (*expr_p
), pre_p
,
12949 NULL
, is_gimple_val
, fb_rvalue
);
12950 if (ret
== GS_ERROR
)
12953 gimplify_seq_add_stmt (pre_p
,
12954 gimple_build_goto (GOTO_DESTINATION (*expr_p
)));
12959 gimplify_seq_add_stmt (pre_p
,
12960 gimple_build_predict (PREDICT_EXPR_PREDICTOR (*expr_p
),
12961 PREDICT_EXPR_OUTCOME (*expr_p
)));
12966 ret
= gimplify_label_expr (expr_p
, pre_p
);
12967 label
= LABEL_EXPR_LABEL (*expr_p
);
12968 gcc_assert (decl_function_context (label
) == current_function_decl
);
12970 /* If the label is used in a goto statement, or address of the label
12971 is taken, we need to unpoison all variables that were seen so far.
12972 Doing so would prevent us from reporting a false positives. */
12973 if (asan_poisoned_variables
12974 && asan_used_labels
!= NULL
12975 && asan_used_labels
->contains (label
))
12976 asan_poison_variables (asan_poisoned_variables
, false, pre_p
);
12979 case CASE_LABEL_EXPR
:
12980 ret
= gimplify_case_label_expr (expr_p
, pre_p
);
12982 if (gimplify_ctxp
->live_switch_vars
)
12983 asan_poison_variables (gimplify_ctxp
->live_switch_vars
, false,
12988 ret
= gimplify_return_expr (*expr_p
, pre_p
);
12992 /* Don't reduce this in place; let gimplify_init_constructor work its
12993 magic. Buf if we're just elaborating this for side effects, just
12994 gimplify any element that has side-effects. */
12995 if (fallback
== fb_none
)
12997 unsigned HOST_WIDE_INT ix
;
12999 tree temp
= NULL_TREE
;
13000 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (*expr_p
), ix
, val
)
13001 if (TREE_SIDE_EFFECTS (val
))
13002 append_to_statement_list (val
, &temp
);
13005 ret
= temp
? GS_OK
: GS_ALL_DONE
;
13007 /* C99 code may assign to an array in a constructed
13008 structure or union, and this has undefined behavior only
13009 on execution, so create a temporary if an lvalue is
13011 else if (fallback
== fb_lvalue
)
13013 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
13014 mark_addressable (*expr_p
);
13021 /* The following are special cases that are not handled by the
13022 original GIMPLE grammar. */
13024 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
13027 ret
= gimplify_save_expr (expr_p
, pre_p
, post_p
);
13030 case BIT_FIELD_REF
:
13031 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13032 post_p
, is_gimple_lvalue
, fb_either
);
13033 recalculate_side_effects (*expr_p
);
13036 case TARGET_MEM_REF
:
13038 enum gimplify_status r0
= GS_ALL_DONE
, r1
= GS_ALL_DONE
;
13040 if (TMR_BASE (*expr_p
))
13041 r0
= gimplify_expr (&TMR_BASE (*expr_p
), pre_p
,
13042 post_p
, is_gimple_mem_ref_addr
, fb_either
);
13043 if (TMR_INDEX (*expr_p
))
13044 r1
= gimplify_expr (&TMR_INDEX (*expr_p
), pre_p
,
13045 post_p
, is_gimple_val
, fb_rvalue
);
13046 if (TMR_INDEX2 (*expr_p
))
13047 r1
= gimplify_expr (&TMR_INDEX2 (*expr_p
), pre_p
,
13048 post_p
, is_gimple_val
, fb_rvalue
);
13049 /* TMR_STEP and TMR_OFFSET are always integer constants. */
13050 ret
= MIN (r0
, r1
);
13054 case NON_LVALUE_EXPR
:
13055 /* This should have been stripped above. */
13056 gcc_unreachable ();
13059 ret
= gimplify_asm_expr (expr_p
, pre_p
, post_p
);
13062 case TRY_FINALLY_EXPR
:
13063 case TRY_CATCH_EXPR
:
13065 gimple_seq eval
, cleanup
;
13068 /* Calls to destructors are generated automatically in FINALLY/CATCH
13069 block. They should have location as UNKNOWN_LOCATION. However,
13070 gimplify_call_expr will reset these call stmts to input_location
13071 if it finds stmt's location is unknown. To prevent resetting for
13072 destructors, we set the input_location to unknown.
13073 Note that this only affects the destructor calls in FINALLY/CATCH
13074 block, and will automatically reset to its original value by the
13075 end of gimplify_expr. */
13076 input_location
= UNKNOWN_LOCATION
;
13077 eval
= cleanup
= NULL
;
13078 gimplify_and_add (TREE_OPERAND (*expr_p
, 0), &eval
);
13079 gimplify_and_add (TREE_OPERAND (*expr_p
, 1), &cleanup
);
13080 /* Don't create bogus GIMPLE_TRY with empty cleanup. */
13081 if (gimple_seq_empty_p (cleanup
))
13083 gimple_seq_add_seq (pre_p
, eval
);
13087 try_
= gimple_build_try (eval
, cleanup
,
13088 TREE_CODE (*expr_p
) == TRY_FINALLY_EXPR
13089 ? GIMPLE_TRY_FINALLY
13090 : GIMPLE_TRY_CATCH
);
13091 if (EXPR_HAS_LOCATION (save_expr
))
13092 gimple_set_location (try_
, EXPR_LOCATION (save_expr
));
13093 else if (LOCATION_LOCUS (saved_location
) != UNKNOWN_LOCATION
)
13094 gimple_set_location (try_
, saved_location
);
13095 if (TREE_CODE (*expr_p
) == TRY_CATCH_EXPR
)
13096 gimple_try_set_catch_is_cleanup (try_
,
13097 TRY_CATCH_IS_CLEANUP (*expr_p
));
13098 gimplify_seq_add_stmt (pre_p
, try_
);
13103 case CLEANUP_POINT_EXPR
:
13104 ret
= gimplify_cleanup_point_expr (expr_p
, pre_p
);
13108 ret
= gimplify_target_expr (expr_p
, pre_p
, post_p
);
13114 gimple_seq handler
= NULL
;
13115 gimplify_and_add (CATCH_BODY (*expr_p
), &handler
);
13116 c
= gimple_build_catch (CATCH_TYPES (*expr_p
), handler
);
13117 gimplify_seq_add_stmt (pre_p
, c
);
13122 case EH_FILTER_EXPR
:
13125 gimple_seq failure
= NULL
;
13127 gimplify_and_add (EH_FILTER_FAILURE (*expr_p
), &failure
);
13128 ehf
= gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p
), failure
);
13129 gimple_set_no_warning (ehf
, TREE_NO_WARNING (*expr_p
));
13130 gimplify_seq_add_stmt (pre_p
, ehf
);
13137 enum gimplify_status r0
, r1
;
13138 r0
= gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p
), pre_p
,
13139 post_p
, is_gimple_val
, fb_rvalue
);
13140 r1
= gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p
), pre_p
,
13141 post_p
, is_gimple_val
, fb_rvalue
);
13142 TREE_SIDE_EFFECTS (*expr_p
) = 0;
13143 ret
= MIN (r0
, r1
);
13148 /* We get here when taking the address of a label. We mark
13149 the label as "forced"; meaning it can never be removed and
13150 it is a potential target for any computed goto. */
13151 FORCED_LABEL (*expr_p
) = 1;
13155 case STATEMENT_LIST
:
13156 ret
= gimplify_statement_list (expr_p
, pre_p
);
13159 case WITH_SIZE_EXPR
:
13161 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13162 post_p
== &internal_post
? NULL
: post_p
,
13163 gimple_test_f
, fallback
);
13164 gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
13165 is_gimple_val
, fb_rvalue
);
13172 ret
= gimplify_var_or_parm_decl (expr_p
);
13176 /* When within an OMP context, notice uses of variables. */
13177 if (gimplify_omp_ctxp
)
13178 omp_notice_variable (gimplify_omp_ctxp
, *expr_p
, true);
13182 case DEBUG_EXPR_DECL
:
13183 gcc_unreachable ();
13185 case DEBUG_BEGIN_STMT
:
13186 gimplify_seq_add_stmt (pre_p
,
13187 gimple_build_debug_begin_stmt
13188 (TREE_BLOCK (*expr_p
),
13189 EXPR_LOCATION (*expr_p
)));
13195 /* Allow callbacks into the gimplifier during optimization. */
13200 gimplify_omp_parallel (expr_p
, pre_p
);
13205 gimplify_omp_task (expr_p
, pre_p
);
13211 case OMP_DISTRIBUTE
:
13214 ret
= gimplify_omp_for (expr_p
, pre_p
);
13218 gimplify_oacc_cache (expr_p
, pre_p
);
13223 gimplify_oacc_declare (expr_p
, pre_p
);
13227 case OACC_HOST_DATA
:
13230 case OACC_PARALLEL
:
13234 case OMP_TARGET_DATA
:
13236 gimplify_omp_workshare (expr_p
, pre_p
);
13240 case OACC_ENTER_DATA
:
13241 case OACC_EXIT_DATA
:
13243 case OMP_TARGET_UPDATE
:
13244 case OMP_TARGET_ENTER_DATA
:
13245 case OMP_TARGET_EXIT_DATA
:
13246 gimplify_omp_target_update (expr_p
, pre_p
);
13256 gimple_seq body
= NULL
;
13259 gimplify_and_add (OMP_BODY (*expr_p
), &body
);
13260 switch (TREE_CODE (*expr_p
))
13263 g
= gimple_build_omp_section (body
);
13266 g
= gimple_build_omp_master (body
);
13269 g
= gimplify_omp_ordered (*expr_p
, body
);
13272 gimplify_scan_omp_clauses (&OMP_CRITICAL_CLAUSES (*expr_p
),
13273 pre_p
, ORT_WORKSHARE
, OMP_CRITICAL
);
13274 gimplify_adjust_omp_clauses (pre_p
, body
,
13275 &OMP_CRITICAL_CLAUSES (*expr_p
),
13277 g
= gimple_build_omp_critical (body
,
13278 OMP_CRITICAL_NAME (*expr_p
),
13279 OMP_CRITICAL_CLAUSES (*expr_p
));
13282 gimplify_scan_omp_clauses (&OMP_SCAN_CLAUSES (*expr_p
),
13283 pre_p
, ORT_WORKSHARE
, OMP_SCAN
);
13284 gimplify_adjust_omp_clauses (pre_p
, body
,
13285 &OMP_SCAN_CLAUSES (*expr_p
),
13287 g
= gimple_build_omp_scan (body
, OMP_SCAN_CLAUSES (*expr_p
));
13290 gcc_unreachable ();
13292 gimplify_seq_add_stmt (pre_p
, g
);
13297 case OMP_TASKGROUP
:
13299 gimple_seq body
= NULL
;
13301 tree
*pclauses
= &OMP_TASKGROUP_CLAUSES (*expr_p
);
13302 gimplify_scan_omp_clauses (pclauses
, pre_p
, ORT_TASKGROUP
,
13304 gimplify_adjust_omp_clauses (pre_p
, NULL
, pclauses
, OMP_TASKGROUP
);
13305 gimplify_and_add (OMP_BODY (*expr_p
), &body
);
13306 gimple_seq cleanup
= NULL
;
13307 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END
);
13308 gimple
*g
= gimple_build_call (fn
, 0);
13309 gimple_seq_add_stmt (&cleanup
, g
);
13310 g
= gimple_build_try (body
, cleanup
, GIMPLE_TRY_FINALLY
);
13312 gimple_seq_add_stmt (&body
, g
);
13313 g
= gimple_build_omp_taskgroup (body
, *pclauses
);
13314 gimplify_seq_add_stmt (pre_p
, g
);
13320 case OMP_ATOMIC_READ
:
13321 case OMP_ATOMIC_CAPTURE_OLD
:
13322 case OMP_ATOMIC_CAPTURE_NEW
:
13323 ret
= gimplify_omp_atomic (expr_p
, pre_p
);
13326 case TRANSACTION_EXPR
:
13327 ret
= gimplify_transaction (expr_p
, pre_p
);
13330 case TRUTH_AND_EXPR
:
13331 case TRUTH_OR_EXPR
:
13332 case TRUTH_XOR_EXPR
:
13334 tree orig_type
= TREE_TYPE (*expr_p
);
13335 tree new_type
, xop0
, xop1
;
13336 *expr_p
= gimple_boolify (*expr_p
);
13337 new_type
= TREE_TYPE (*expr_p
);
13338 if (!useless_type_conversion_p (orig_type
, new_type
))
13340 *expr_p
= fold_convert_loc (input_location
, orig_type
, *expr_p
);
13345 /* Boolified binary truth expressions are semantically equivalent
13346 to bitwise binary expressions. Canonicalize them to the
13347 bitwise variant. */
13348 switch (TREE_CODE (*expr_p
))
13350 case TRUTH_AND_EXPR
:
13351 TREE_SET_CODE (*expr_p
, BIT_AND_EXPR
);
13353 case TRUTH_OR_EXPR
:
13354 TREE_SET_CODE (*expr_p
, BIT_IOR_EXPR
);
13356 case TRUTH_XOR_EXPR
:
13357 TREE_SET_CODE (*expr_p
, BIT_XOR_EXPR
);
13362 /* Now make sure that operands have compatible type to
13363 expression's new_type. */
13364 xop0
= TREE_OPERAND (*expr_p
, 0);
13365 xop1
= TREE_OPERAND (*expr_p
, 1);
13366 if (!useless_type_conversion_p (new_type
, TREE_TYPE (xop0
)))
13367 TREE_OPERAND (*expr_p
, 0) = fold_convert_loc (input_location
,
13370 if (!useless_type_conversion_p (new_type
, TREE_TYPE (xop1
)))
13371 TREE_OPERAND (*expr_p
, 1) = fold_convert_loc (input_location
,
13374 /* Continue classified as tcc_binary. */
13378 case VEC_COND_EXPR
:
13380 enum gimplify_status r0
, r1
, r2
;
13382 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13383 post_p
, is_gimple_condexpr
, fb_rvalue
);
13384 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
13385 post_p
, is_gimple_val
, fb_rvalue
);
13386 r2
= gimplify_expr (&TREE_OPERAND (*expr_p
, 2), pre_p
,
13387 post_p
, is_gimple_val
, fb_rvalue
);
13389 ret
= MIN (MIN (r0
, r1
), r2
);
13390 recalculate_side_effects (*expr_p
);
13394 case VEC_PERM_EXPR
:
13395 /* Classified as tcc_expression. */
13398 case BIT_INSERT_EXPR
:
13399 /* Argument 3 is a constant. */
13402 case POINTER_PLUS_EXPR
:
13404 enum gimplify_status r0
, r1
;
13405 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13406 post_p
, is_gimple_val
, fb_rvalue
);
13407 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
13408 post_p
, is_gimple_val
, fb_rvalue
);
13409 recalculate_side_effects (*expr_p
);
13410 ret
= MIN (r0
, r1
);
13415 switch (TREE_CODE_CLASS (TREE_CODE (*expr_p
)))
13417 case tcc_comparison
:
13418 /* Handle comparison of objects of non scalar mode aggregates
13419 with a call to memcmp. It would be nice to only have to do
13420 this for variable-sized objects, but then we'd have to allow
13421 the same nest of reference nodes we allow for MODIFY_EXPR and
13422 that's too complex.
13424 Compare scalar mode aggregates as scalar mode values. Using
13425 memcmp for them would be very inefficient at best, and is
13426 plain wrong if bitfields are involved. */
13428 tree type
= TREE_TYPE (TREE_OPERAND (*expr_p
, 1));
13430 /* Vector comparisons need no boolification. */
13431 if (TREE_CODE (type
) == VECTOR_TYPE
)
13433 else if (!AGGREGATE_TYPE_P (type
))
13435 tree org_type
= TREE_TYPE (*expr_p
);
13436 *expr_p
= gimple_boolify (*expr_p
);
13437 if (!useless_type_conversion_p (org_type
,
13438 TREE_TYPE (*expr_p
)))
13440 *expr_p
= fold_convert_loc (input_location
,
13441 org_type
, *expr_p
);
13447 else if (TYPE_MODE (type
) != BLKmode
)
13448 ret
= gimplify_scalar_mode_aggregate_compare (expr_p
);
13450 ret
= gimplify_variable_sized_compare (expr_p
);
13455 /* If *EXPR_P does not need to be special-cased, handle it
13456 according to its class. */
13458 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13459 post_p
, is_gimple_val
, fb_rvalue
);
13465 enum gimplify_status r0
, r1
;
13467 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13468 post_p
, is_gimple_val
, fb_rvalue
);
13469 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
13470 post_p
, is_gimple_val
, fb_rvalue
);
13472 ret
= MIN (r0
, r1
);
13478 enum gimplify_status r0
, r1
, r2
;
13480 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
13481 post_p
, is_gimple_val
, fb_rvalue
);
13482 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
13483 post_p
, is_gimple_val
, fb_rvalue
);
13484 r2
= gimplify_expr (&TREE_OPERAND (*expr_p
, 2), pre_p
,
13485 post_p
, is_gimple_val
, fb_rvalue
);
13487 ret
= MIN (MIN (r0
, r1
), r2
);
13491 case tcc_declaration
:
13494 goto dont_recalculate
;
13497 gcc_unreachable ();
13500 recalculate_side_effects (*expr_p
);
13506 gcc_assert (*expr_p
|| ret
!= GS_OK
);
13508 while (ret
== GS_OK
);
13510 /* If we encountered an error_mark somewhere nested inside, either
13511 stub out the statement or propagate the error back out. */
13512 if (ret
== GS_ERROR
)
13519 /* This was only valid as a return value from the langhook, which
13520 we handled. Make sure it doesn't escape from any other context. */
13521 gcc_assert (ret
!= GS_UNHANDLED
);
13523 if (fallback
== fb_none
&& *expr_p
&& !is_gimple_stmt (*expr_p
))
13525 /* We aren't looking for a value, and we don't have a valid
13526 statement. If it doesn't have side-effects, throw it away.
13527 We can also get here with code such as "*&&L;", where L is
13528 a LABEL_DECL that is marked as FORCED_LABEL. */
13529 if (TREE_CODE (*expr_p
) == LABEL_DECL
13530 || !TREE_SIDE_EFFECTS (*expr_p
))
13532 else if (!TREE_THIS_VOLATILE (*expr_p
))
13534 /* This is probably a _REF that contains something nested that
13535 has side effects. Recurse through the operands to find it. */
13536 enum tree_code code
= TREE_CODE (*expr_p
);
13540 case COMPONENT_REF
:
13541 case REALPART_EXPR
:
13542 case IMAGPART_EXPR
:
13543 case VIEW_CONVERT_EXPR
:
13544 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
13545 gimple_test_f
, fallback
);
13549 case ARRAY_RANGE_REF
:
13550 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
13551 gimple_test_f
, fallback
);
13552 gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
13553 gimple_test_f
, fallback
);
13557 /* Anything else with side-effects must be converted to
13558 a valid statement before we get here. */
13559 gcc_unreachable ();
13564 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p
))
13565 && TYPE_MODE (TREE_TYPE (*expr_p
)) != BLKmode
)
13567 /* Historically, the compiler has treated a bare reference
13568 to a non-BLKmode volatile lvalue as forcing a load. */
13569 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p
));
13571 /* Normally, we do not want to create a temporary for a
13572 TREE_ADDRESSABLE type because such a type should not be
13573 copied by bitwise-assignment. However, we make an
13574 exception here, as all we are doing here is ensuring that
13575 we read the bytes that make up the type. We use
13576 create_tmp_var_raw because create_tmp_var will abort when
13577 given a TREE_ADDRESSABLE type. */
13578 tree tmp
= create_tmp_var_raw (type
, "vol");
13579 gimple_add_tmp_var (tmp
);
13580 gimplify_assign (tmp
, *expr_p
, pre_p
);
13584 /* We can't do anything useful with a volatile reference to
13585 an incomplete type, so just throw it away. Likewise for
13586 a BLKmode type, since any implicit inner load should
13587 already have been turned into an explicit one by the
13588 gimplification process. */
13592 /* If we are gimplifying at the statement level, we're done. Tack
13593 everything together and return. */
13594 if (fallback
== fb_none
|| is_statement
)
13596 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear
13597 it out for GC to reclaim it. */
13598 *expr_p
= NULL_TREE
;
13600 if (!gimple_seq_empty_p (internal_pre
)
13601 || !gimple_seq_empty_p (internal_post
))
13603 gimplify_seq_add_seq (&internal_pre
, internal_post
);
13604 gimplify_seq_add_seq (pre_p
, internal_pre
);
13607 /* The result of gimplifying *EXPR_P is going to be the last few
13608 statements in *PRE_P and *POST_P. Add location information
13609 to all the statements that were added by the gimplification
13611 if (!gimple_seq_empty_p (*pre_p
))
13612 annotate_all_with_location_after (*pre_p
, pre_last_gsi
, input_location
);
13614 if (!gimple_seq_empty_p (*post_p
))
13615 annotate_all_with_location_after (*post_p
, post_last_gsi
,
13621 #ifdef ENABLE_GIMPLE_CHECKING
13624 enum tree_code code
= TREE_CODE (*expr_p
);
13625 /* These expressions should already be in gimple IR form. */
13626 gcc_assert (code
!= MODIFY_EXPR
13627 && code
!= ASM_EXPR
13628 && code
!= BIND_EXPR
13629 && code
!= CATCH_EXPR
13630 && (code
!= COND_EXPR
|| gimplify_ctxp
->allow_rhs_cond_expr
)
13631 && code
!= EH_FILTER_EXPR
13632 && code
!= GOTO_EXPR
13633 && code
!= LABEL_EXPR
13634 && code
!= LOOP_EXPR
13635 && code
!= SWITCH_EXPR
13636 && code
!= TRY_FINALLY_EXPR
13637 && code
!= OACC_PARALLEL
13638 && code
!= OACC_KERNELS
13639 && code
!= OACC_DATA
13640 && code
!= OACC_HOST_DATA
13641 && code
!= OACC_DECLARE
13642 && code
!= OACC_UPDATE
13643 && code
!= OACC_ENTER_DATA
13644 && code
!= OACC_EXIT_DATA
13645 && code
!= OACC_CACHE
13646 && code
!= OMP_CRITICAL
13648 && code
!= OACC_LOOP
13649 && code
!= OMP_MASTER
13650 && code
!= OMP_TASKGROUP
13651 && code
!= OMP_ORDERED
13652 && code
!= OMP_PARALLEL
13653 && code
!= OMP_SCAN
13654 && code
!= OMP_SECTIONS
13655 && code
!= OMP_SECTION
13656 && code
!= OMP_SINGLE
);
13660 /* Otherwise we're gimplifying a subexpression, so the resulting
13661 value is interesting. If it's a valid operand that matches
13662 GIMPLE_TEST_F, we're done. Unless we are handling some
13663 post-effects internally; if that's the case, we need to copy into
13664 a temporary before adding the post-effects to POST_P. */
13665 if (gimple_seq_empty_p (internal_post
) && (*gimple_test_f
) (*expr_p
))
13668 /* Otherwise, we need to create a new temporary for the gimplified
13671 /* We can't return an lvalue if we have an internal postqueue. The
13672 object the lvalue refers to would (probably) be modified by the
13673 postqueue; we need to copy the value out first, which means an
13675 if ((fallback
& fb_lvalue
)
13676 && gimple_seq_empty_p (internal_post
)
13677 && is_gimple_addressable (*expr_p
))
13679 /* An lvalue will do. Take the address of the expression, store it
13680 in a temporary, and replace the expression with an INDIRECT_REF of
13682 tree ref_alias_type
= reference_alias_ptr_type (*expr_p
);
13683 unsigned int ref_align
= get_object_alignment (*expr_p
);
13684 tree ref_type
= TREE_TYPE (*expr_p
);
13685 tmp
= build_fold_addr_expr_loc (input_location
, *expr_p
);
13686 gimplify_expr (&tmp
, pre_p
, post_p
, is_gimple_reg
, fb_rvalue
);
13687 if (TYPE_ALIGN (ref_type
) != ref_align
)
13688 ref_type
= build_aligned_type (ref_type
, ref_align
);
13689 *expr_p
= build2 (MEM_REF
, ref_type
,
13690 tmp
, build_zero_cst (ref_alias_type
));
13692 else if ((fallback
& fb_rvalue
) && is_gimple_reg_rhs_or_call (*expr_p
))
13694 /* An rvalue will do. Assign the gimplified expression into a
13695 new temporary TMP and replace the original expression with
13696 TMP. First, make sure that the expression has a type so that
13697 it can be assigned into a temporary. */
13698 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p
)));
13699 *expr_p
= get_formal_tmp_var (*expr_p
, pre_p
);
13703 #ifdef ENABLE_GIMPLE_CHECKING
13704 if (!(fallback
& fb_mayfail
))
13706 fprintf (stderr
, "gimplification failed:\n");
13707 print_generic_expr (stderr
, *expr_p
);
13708 debug_tree (*expr_p
);
13709 internal_error ("gimplification failed");
13712 gcc_assert (fallback
& fb_mayfail
);
13714 /* If this is an asm statement, and the user asked for the
13715 impossible, don't die. Fail and let gimplify_asm_expr
13721 /* Make sure the temporary matches our predicate. */
13722 gcc_assert ((*gimple_test_f
) (*expr_p
));
13724 if (!gimple_seq_empty_p (internal_post
))
13726 annotate_all_with_location (internal_post
, input_location
);
13727 gimplify_seq_add_seq (pre_p
, internal_post
);
13731 input_location
= saved_location
;
13735 /* Like gimplify_expr but make sure the gimplified result is not itself
13736 a SSA name (but a decl if it were). Temporaries required by
13737 evaluating *EXPR_P may be still SSA names. */
13739 static enum gimplify_status
13740 gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
13741 bool (*gimple_test_f
) (tree
), fallback_t fallback
,
13744 bool was_ssa_name_p
= TREE_CODE (*expr_p
) == SSA_NAME
;
13745 enum gimplify_status ret
= gimplify_expr (expr_p
, pre_p
, post_p
,
13746 gimple_test_f
, fallback
);
13748 && TREE_CODE (*expr_p
) == SSA_NAME
)
13750 tree name
= *expr_p
;
13751 if (was_ssa_name_p
)
13752 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, NULL
, false);
13755 /* Avoid the extra copy if possible. */
13756 *expr_p
= create_tmp_reg (TREE_TYPE (name
));
13757 gimple_set_lhs (SSA_NAME_DEF_STMT (name
), *expr_p
);
13758 release_ssa_name (name
);
13764 /* Look through TYPE for variable-sized objects and gimplify each such
13765 size that we find. Add to LIST_P any statements generated. */
13768 gimplify_type_sizes (tree type
, gimple_seq
*list_p
)
13772 if (type
== NULL
|| type
== error_mark_node
)
13775 /* We first do the main variant, then copy into any other variants. */
13776 type
= TYPE_MAIN_VARIANT (type
);
13778 /* Avoid infinite recursion. */
13779 if (TYPE_SIZES_GIMPLIFIED (type
))
13782 TYPE_SIZES_GIMPLIFIED (type
) = 1;
13784 switch (TREE_CODE (type
))
13787 case ENUMERAL_TYPE
:
13790 case FIXED_POINT_TYPE
:
13791 gimplify_one_sizepos (&TYPE_MIN_VALUE (type
), list_p
);
13792 gimplify_one_sizepos (&TYPE_MAX_VALUE (type
), list_p
);
13794 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
13796 TYPE_MIN_VALUE (t
) = TYPE_MIN_VALUE (type
);
13797 TYPE_MAX_VALUE (t
) = TYPE_MAX_VALUE (type
);
13802 /* These types may not have declarations, so handle them here. */
13803 gimplify_type_sizes (TREE_TYPE (type
), list_p
);
13804 gimplify_type_sizes (TYPE_DOMAIN (type
), list_p
);
13805 /* Ensure VLA bounds aren't removed, for -O0 they should be variables
13806 with assigned stack slots, for -O1+ -g they should be tracked
13808 if (!(TYPE_NAME (type
)
13809 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13810 && DECL_IGNORED_P (TYPE_NAME (type
)))
13811 && TYPE_DOMAIN (type
)
13812 && INTEGRAL_TYPE_P (TYPE_DOMAIN (type
)))
13814 t
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
13815 if (t
&& VAR_P (t
) && DECL_ARTIFICIAL (t
))
13816 DECL_IGNORED_P (t
) = 0;
13817 t
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
13818 if (t
&& VAR_P (t
) && DECL_ARTIFICIAL (t
))
13819 DECL_IGNORED_P (t
) = 0;
13825 case QUAL_UNION_TYPE
:
13826 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
13827 if (TREE_CODE (field
) == FIELD_DECL
)
13829 gimplify_one_sizepos (&DECL_FIELD_OFFSET (field
), list_p
);
13830 gimplify_one_sizepos (&DECL_SIZE (field
), list_p
);
13831 gimplify_one_sizepos (&DECL_SIZE_UNIT (field
), list_p
);
13832 gimplify_type_sizes (TREE_TYPE (field
), list_p
);
13837 case REFERENCE_TYPE
:
13838 /* We used to recurse on the pointed-to type here, which turned out to
13839 be incorrect because its definition might refer to variables not
13840 yet initialized at this point if a forward declaration is involved.
13842 It was actually useful for anonymous pointed-to types to ensure
13843 that the sizes evaluation dominates every possible later use of the
13844 values. Restricting to such types here would be safe since there
13845 is no possible forward declaration around, but would introduce an
13846 undesirable middle-end semantic to anonymity. We then defer to
13847 front-ends the responsibility of ensuring that the sizes are
13848 evaluated both early and late enough, e.g. by attaching artificial
13849 type declarations to the tree. */
13856 gimplify_one_sizepos (&TYPE_SIZE (type
), list_p
);
13857 gimplify_one_sizepos (&TYPE_SIZE_UNIT (type
), list_p
);
13859 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
13861 TYPE_SIZE (t
) = TYPE_SIZE (type
);
13862 TYPE_SIZE_UNIT (t
) = TYPE_SIZE_UNIT (type
);
13863 TYPE_SIZES_GIMPLIFIED (t
) = 1;
13867 /* A subroutine of gimplify_type_sizes to make sure that *EXPR_P,
13868 a size or position, has had all of its SAVE_EXPRs evaluated.
13869 We add any required statements to *STMT_P. */
13872 gimplify_one_sizepos (tree
*expr_p
, gimple_seq
*stmt_p
)
13874 tree expr
= *expr_p
;
13876 /* We don't do anything if the value isn't there, is constant, or contains
13877 A PLACEHOLDER_EXPR. We also don't want to do anything if it's already
13878 a VAR_DECL. If it's a VAR_DECL from another function, the gimplifier
13879 will want to replace it with a new variable, but that will cause problems
13880 if this type is from outside the function. It's OK to have that here. */
13881 if (expr
== NULL_TREE
13882 || is_gimple_constant (expr
)
13883 || TREE_CODE (expr
) == VAR_DECL
13884 || CONTAINS_PLACEHOLDER_P (expr
))
13887 *expr_p
= unshare_expr (expr
);
13889 /* SSA names in decl/type fields are a bad idea - they'll get reclaimed
13890 if the def vanishes. */
13891 gimplify_expr (expr_p
, stmt_p
, NULL
, is_gimple_val
, fb_rvalue
, false);
13893 /* If expr wasn't already is_gimple_sizepos or is_gimple_constant from the
13894 FE, ensure that it is a VAR_DECL, otherwise we might handle some decls
13895 as gimplify_vla_decl even when they would have all sizes INTEGER_CSTs. */
13896 if (is_gimple_constant (*expr_p
))
13897 *expr_p
= get_initialized_tmp_var (*expr_p
, stmt_p
, NULL
, false);
13900 /* Gimplify the body of statements of FNDECL and return a GIMPLE_BIND node
13901 containing the sequence of corresponding GIMPLE statements. If DO_PARMS
13902 is true, also gimplify the parameters. */
13905 gimplify_body (tree fndecl
, bool do_parms
)
13907 location_t saved_location
= input_location
;
13908 gimple_seq parm_stmts
, parm_cleanup
= NULL
, seq
;
13909 gimple
*outer_stmt
;
13912 timevar_push (TV_TREE_GIMPLIFY
);
13914 init_tree_ssa (cfun
);
13916 /* Initialize for optimize_insn_for_s{ize,peed}_p possibly called during
13918 default_rtl_profile ();
13920 gcc_assert (gimplify_ctxp
== NULL
);
13921 push_gimplify_context (true);
13923 if (flag_openacc
|| flag_openmp
)
13925 gcc_assert (gimplify_omp_ctxp
== NULL
);
13926 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl
)))
13927 gimplify_omp_ctxp
= new_omp_context (ORT_TARGET
);
13930 /* Unshare most shared trees in the body and in that of any nested functions.
13931 It would seem we don't have to do this for nested functions because
13932 they are supposed to be output and then the outer function gimplified
13933 first, but the g++ front end doesn't always do it that way. */
13934 unshare_body (fndecl
);
13935 unvisit_body (fndecl
);
13937 /* Make sure input_location isn't set to something weird. */
13938 input_location
= DECL_SOURCE_LOCATION (fndecl
);
13940 /* Resolve callee-copies. This has to be done before processing
13941 the body so that DECL_VALUE_EXPR gets processed correctly. */
13942 parm_stmts
= do_parms
? gimplify_parameters (&parm_cleanup
) : NULL
;
13944 /* Gimplify the function's body. */
13946 gimplify_stmt (&DECL_SAVED_TREE (fndecl
), &seq
);
13947 outer_stmt
= gimple_seq_first_stmt (seq
);
13950 outer_stmt
= gimple_build_nop ();
13951 gimplify_seq_add_stmt (&seq
, outer_stmt
);
13954 /* The body must contain exactly one statement, a GIMPLE_BIND. If this is
13955 not the case, wrap everything in a GIMPLE_BIND to make it so. */
13956 if (gimple_code (outer_stmt
) == GIMPLE_BIND
13957 && gimple_seq_first (seq
) == gimple_seq_last (seq
))
13958 outer_bind
= as_a
<gbind
*> (outer_stmt
);
13960 outer_bind
= gimple_build_bind (NULL_TREE
, seq
, NULL
);
13962 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
13964 /* If we had callee-copies statements, insert them at the beginning
13965 of the function and clear DECL_VALUE_EXPR_P on the parameters. */
13966 if (!gimple_seq_empty_p (parm_stmts
))
13970 gimplify_seq_add_seq (&parm_stmts
, gimple_bind_body (outer_bind
));
13973 gtry
*g
= gimple_build_try (parm_stmts
, parm_cleanup
,
13974 GIMPLE_TRY_FINALLY
);
13976 gimple_seq_add_stmt (&parm_stmts
, g
);
13978 gimple_bind_set_body (outer_bind
, parm_stmts
);
13980 for (parm
= DECL_ARGUMENTS (current_function_decl
);
13981 parm
; parm
= DECL_CHAIN (parm
))
13982 if (DECL_HAS_VALUE_EXPR_P (parm
))
13984 DECL_HAS_VALUE_EXPR_P (parm
) = 0;
13985 DECL_IGNORED_P (parm
) = 0;
13989 if ((flag_openacc
|| flag_openmp
|| flag_openmp_simd
)
13990 && gimplify_omp_ctxp
)
13992 delete_omp_context (gimplify_omp_ctxp
);
13993 gimplify_omp_ctxp
= NULL
;
13996 pop_gimplify_context (outer_bind
);
13997 gcc_assert (gimplify_ctxp
== NULL
);
13999 if (flag_checking
&& !seen_error ())
14000 verify_gimple_in_seq (gimple_bind_body (outer_bind
));
14002 timevar_pop (TV_TREE_GIMPLIFY
);
14003 input_location
= saved_location
;
14008 typedef char *char_p
; /* For DEF_VEC_P. */
14010 /* Return whether we should exclude FNDECL from instrumentation. */
14013 flag_instrument_functions_exclude_p (tree fndecl
)
14017 v
= (vec
<char_p
> *) flag_instrument_functions_exclude_functions
;
14018 if (v
&& v
->length () > 0)
14024 name
= lang_hooks
.decl_printable_name (fndecl
, 0);
14025 FOR_EACH_VEC_ELT (*v
, i
, s
)
14026 if (strstr (name
, s
) != NULL
)
14030 v
= (vec
<char_p
> *) flag_instrument_functions_exclude_files
;
14031 if (v
&& v
->length () > 0)
14037 name
= DECL_SOURCE_FILE (fndecl
);
14038 FOR_EACH_VEC_ELT (*v
, i
, s
)
14039 if (strstr (name
, s
) != NULL
)
14046 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL
14047 node for the function we want to gimplify.
14049 Return the sequence of GIMPLE statements corresponding to the body
14053 gimplify_function_tree (tree fndecl
)
14059 gcc_assert (!gimple_body (fndecl
));
14061 if (DECL_STRUCT_FUNCTION (fndecl
))
14062 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
14064 push_struct_function (fndecl
);
14066 /* Tentatively set PROP_gimple_lva here, and reset it in gimplify_va_arg_expr
14068 cfun
->curr_properties
|= PROP_gimple_lva
;
14070 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= DECL_CHAIN (parm
))
14072 /* Preliminarily mark non-addressed complex variables as eligible
14073 for promotion to gimple registers. We'll transform their uses
14074 as we find them. */
14075 if ((TREE_CODE (TREE_TYPE (parm
)) == COMPLEX_TYPE
14076 || TREE_CODE (TREE_TYPE (parm
)) == VECTOR_TYPE
)
14077 && !TREE_THIS_VOLATILE (parm
)
14078 && !needs_to_live_in_memory (parm
))
14079 DECL_GIMPLE_REG_P (parm
) = 1;
14082 ret
= DECL_RESULT (fndecl
);
14083 if ((TREE_CODE (TREE_TYPE (ret
)) == COMPLEX_TYPE
14084 || TREE_CODE (TREE_TYPE (ret
)) == VECTOR_TYPE
)
14085 && !needs_to_live_in_memory (ret
))
14086 DECL_GIMPLE_REG_P (ret
) = 1;
14088 if (asan_sanitize_use_after_scope () && sanitize_flags_p (SANITIZE_ADDRESS
))
14089 asan_poisoned_variables
= new hash_set
<tree
> ();
14090 bind
= gimplify_body (fndecl
, true);
14091 if (asan_poisoned_variables
)
14093 delete asan_poisoned_variables
;
14094 asan_poisoned_variables
= NULL
;
14097 /* The tree body of the function is no longer needed, replace it
14098 with the new GIMPLE body. */
14100 gimple_seq_add_stmt (&seq
, bind
);
14101 gimple_set_body (fndecl
, seq
);
14103 /* If we're instrumenting function entry/exit, then prepend the call to
14104 the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
14105 catch the exit hook. */
14106 /* ??? Add some way to ignore exceptions for this TFE. */
14107 if (flag_instrument_function_entry_exit
14108 && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl
)
14109 /* Do not instrument extern inline functions. */
14110 && !(DECL_DECLARED_INLINE_P (fndecl
)
14111 && DECL_EXTERNAL (fndecl
)
14112 && DECL_DISREGARD_INLINE_LIMITS (fndecl
))
14113 && !flag_instrument_functions_exclude_p (fndecl
))
14118 gimple_seq cleanup
= NULL
, body
= NULL
;
14119 tree tmp_var
, this_fn_addr
;
14122 /* The instrumentation hooks aren't going to call the instrumented
14123 function and the address they receive is expected to be matchable
14124 against symbol addresses. Make sure we don't create a trampoline,
14125 in case the current function is nested. */
14126 this_fn_addr
= build_fold_addr_expr (current_function_decl
);
14127 TREE_NO_TRAMPOLINE (this_fn_addr
) = 1;
14129 x
= builtin_decl_implicit (BUILT_IN_RETURN_ADDRESS
);
14130 call
= gimple_build_call (x
, 1, integer_zero_node
);
14131 tmp_var
= create_tmp_var (ptr_type_node
, "return_addr");
14132 gimple_call_set_lhs (call
, tmp_var
);
14133 gimplify_seq_add_stmt (&cleanup
, call
);
14134 x
= builtin_decl_implicit (BUILT_IN_PROFILE_FUNC_EXIT
);
14135 call
= gimple_build_call (x
, 2, this_fn_addr
, tmp_var
);
14136 gimplify_seq_add_stmt (&cleanup
, call
);
14137 tf
= gimple_build_try (seq
, cleanup
, GIMPLE_TRY_FINALLY
);
14139 x
= builtin_decl_implicit (BUILT_IN_RETURN_ADDRESS
);
14140 call
= gimple_build_call (x
, 1, integer_zero_node
);
14141 tmp_var
= create_tmp_var (ptr_type_node
, "return_addr");
14142 gimple_call_set_lhs (call
, tmp_var
);
14143 gimplify_seq_add_stmt (&body
, call
);
14144 x
= builtin_decl_implicit (BUILT_IN_PROFILE_FUNC_ENTER
);
14145 call
= gimple_build_call (x
, 2, this_fn_addr
, tmp_var
);
14146 gimplify_seq_add_stmt (&body
, call
);
14147 gimplify_seq_add_stmt (&body
, tf
);
14148 new_bind
= gimple_build_bind (NULL
, body
, NULL
);
14150 /* Replace the current function body with the body
14151 wrapped in the try/finally TF. */
14153 gimple_seq_add_stmt (&seq
, new_bind
);
14154 gimple_set_body (fndecl
, seq
);
14158 if (sanitize_flags_p (SANITIZE_THREAD
))
14160 gcall
*call
= gimple_build_call_internal (IFN_TSAN_FUNC_EXIT
, 0);
14161 gimple
*tf
= gimple_build_try (seq
, call
, GIMPLE_TRY_FINALLY
);
14162 gbind
*new_bind
= gimple_build_bind (NULL
, tf
, NULL
);
14163 /* Replace the current function body with the body
14164 wrapped in the try/finally TF. */
14166 gimple_seq_add_stmt (&seq
, new_bind
);
14167 gimple_set_body (fndecl
, seq
);
14170 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
14171 cfun
->curr_properties
|= PROP_gimple_any
;
14175 dump_function (TDI_gimple
, fndecl
);
14178 /* Return a dummy expression of type TYPE in order to keep going after an
14182 dummy_object (tree type
)
14184 tree t
= build_int_cst (build_pointer_type (type
), 0);
14185 return build2 (MEM_REF
, type
, t
, t
);
14188 /* Gimplify __builtin_va_arg, aka VA_ARG_EXPR, which is not really a
14189 builtin function, but a very special sort of operator. */
14191 enum gimplify_status
14192 gimplify_va_arg_expr (tree
*expr_p
, gimple_seq
*pre_p
,
14193 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
14195 tree promoted_type
, have_va_type
;
14196 tree valist
= TREE_OPERAND (*expr_p
, 0);
14197 tree type
= TREE_TYPE (*expr_p
);
14198 tree t
, tag
, aptag
;
14199 location_t loc
= EXPR_LOCATION (*expr_p
);
14201 /* Verify that valist is of the proper type. */
14202 have_va_type
= TREE_TYPE (valist
);
14203 if (have_va_type
== error_mark_node
)
14205 have_va_type
= targetm
.canonical_va_list_type (have_va_type
);
14206 if (have_va_type
== NULL_TREE
14207 && POINTER_TYPE_P (TREE_TYPE (valist
)))
14208 /* Handle 'Case 1: Not an array type' from c-common.c/build_va_arg. */
14210 = targetm
.canonical_va_list_type (TREE_TYPE (TREE_TYPE (valist
)));
14211 gcc_assert (have_va_type
!= NULL_TREE
);
14213 /* Generate a diagnostic for requesting data of a type that cannot
14214 be passed through `...' due to type promotion at the call site. */
14215 if ((promoted_type
= lang_hooks
.types
.type_promotes_to (type
))
14218 static bool gave_help
;
14220 /* Use the expansion point to handle cases such as passing bool (defined
14221 in a system header) through `...'. */
14223 = expansion_point_location_if_in_system_header (loc
);
14225 /* Unfortunately, this is merely undefined, rather than a constraint
14226 violation, so we cannot make this an error. If this call is never
14227 executed, the program is still strictly conforming. */
14228 auto_diagnostic_group d
;
14229 warned
= warning_at (xloc
, 0,
14230 "%qT is promoted to %qT when passed through %<...%>",
14231 type
, promoted_type
);
14232 if (!gave_help
&& warned
)
14235 inform (xloc
, "(so you should pass %qT not %qT to %<va_arg%>)",
14236 promoted_type
, type
);
14239 /* We can, however, treat "undefined" any way we please.
14240 Call abort to encourage the user to fix the program. */
14242 inform (xloc
, "if this code is reached, the program will abort");
14243 /* Before the abort, allow the evaluation of the va_list
14244 expression to exit or longjmp. */
14245 gimplify_and_add (valist
, pre_p
);
14246 t
= build_call_expr_loc (loc
,
14247 builtin_decl_implicit (BUILT_IN_TRAP
), 0);
14248 gimplify_and_add (t
, pre_p
);
14250 /* This is dead code, but go ahead and finish so that the
14251 mode of the result comes out right. */
14252 *expr_p
= dummy_object (type
);
14253 return GS_ALL_DONE
;
14256 tag
= build_int_cst (build_pointer_type (type
), 0);
14257 aptag
= build_int_cst (TREE_TYPE (valist
), 0);
14259 *expr_p
= build_call_expr_internal_loc (loc
, IFN_VA_ARG
, type
, 3,
14260 valist
, tag
, aptag
);
14262 /* Clear the tentatively set PROP_gimple_lva, to indicate that IFN_VA_ARG
14263 needs to be expanded. */
14264 cfun
->curr_properties
&= ~PROP_gimple_lva
;
14269 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
14271 DST/SRC are the destination and source respectively. You can pass
14272 ungimplified trees in DST or SRC, in which case they will be
14273 converted to a gimple operand if necessary.
14275 This function returns the newly created GIMPLE_ASSIGN tuple. */
14278 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
14280 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
14281 gimplify_and_add (t
, seq_p
);
14283 return gimple_seq_last_stmt (*seq_p
);
14287 gimplify_hasher::hash (const elt_t
*p
)
14290 return iterative_hash_expr (t
, 0);
14294 gimplify_hasher::equal (const elt_t
*p1
, const elt_t
*p2
)
14298 enum tree_code code
= TREE_CODE (t1
);
14300 if (TREE_CODE (t2
) != code
14301 || TREE_TYPE (t1
) != TREE_TYPE (t2
))
14304 if (!operand_equal_p (t1
, t2
, 0))
14307 /* Only allow them to compare equal if they also hash equal; otherwise
14308 results are nondeterminate, and we fail bootstrap comparison. */
14309 gcc_checking_assert (hash (p1
) == hash (p2
));