1 /* Tree lowering pass. This pass converts the GENERIC functions-as-trees
2 tree representation into the GIMPLE form.
4 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
5 Major work done by Sebastian Pop <s.pop@laposte.net>,
6 Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "coretypes.h"
33 #include "tree-gimple.h"
34 #include "tree-inline.h"
35 #include "diagnostic.h"
36 #include "langhooks.h"
37 #include "langhooks-def.h"
38 #include "tree-flow.h"
50 static struct gimplify_ctx
52 tree current_bind_expr
;
55 tree conditional_cleanups
;
59 varray_type case_labels
;
60 /* The formal temporary table. Should this be persistent? */
65 /* Formal (expression) temporary table handling: Multiple occurrences of
66 the same scalar expression are evaluated into the same temporary. */
68 typedef struct gimple_temp_hash_elt
71 tree temp
; /* Value */
74 /* Return a hash value for a formal temporary table entry. */
77 gimple_tree_hash (const void *p
)
79 tree t
= ((const elt_t
*)p
)->val
;
80 return iterative_hash_expr (t
, 0);
83 /* Compare two formal temporary table entries. */
86 gimple_tree_eq (const void *p1
, const void *p2
)
88 tree t1
= ((const elt_t
*)p1
)->val
;
89 tree t2
= ((const elt_t
*)p2
)->val
;
90 enum tree_code code
= TREE_CODE (t1
);
92 if (TREE_CODE (t2
) != code
93 || TREE_TYPE (t1
) != TREE_TYPE (t2
))
96 if (!operand_equal_p (t1
, t2
, 0))
99 /* Only allow them to compare equal if they also hash equal; otherwise
100 results are nondeterminate, and we fail bootstrap comparison. */
101 if (gimple_tree_hash (p1
) != gimple_tree_hash (p2
))
107 /* Set up a context for the gimplifier. */
110 push_gimplify_context (void)
115 = (struct gimplify_ctx
*) xcalloc (1, sizeof (struct gimplify_ctx
));
116 gimplify_ctxp
->temp_htab
117 = htab_create (1000, gimple_tree_hash
, gimple_tree_eq
, free
);
120 /* Tear down a context for the gimplifier. If BODY is non-null, then
121 put the temporaries into the outer BIND_EXPR. Otherwise, put them
122 in the unexpanded_var_list. */
125 pop_gimplify_context (tree body
)
127 if (!gimplify_ctxp
|| gimplify_ctxp
->current_bind_expr
)
131 declare_tmp_vars (gimplify_ctxp
->temps
, body
);
133 record_vars (gimplify_ctxp
->temps
);
137 fprintf (stderr
, " collisions: %f ",
138 htab_collisions (gimplify_ctxp
->temp_htab
));
141 htab_delete (gimplify_ctxp
->temp_htab
);
142 free (gimplify_ctxp
);
143 gimplify_ctxp
= NULL
;
147 gimple_push_bind_expr (tree bind
)
149 TREE_CHAIN (bind
) = gimplify_ctxp
->current_bind_expr
;
150 gimplify_ctxp
->current_bind_expr
= bind
;
154 gimple_pop_bind_expr (void)
156 gimplify_ctxp
->current_bind_expr
157 = TREE_CHAIN (gimplify_ctxp
->current_bind_expr
);
161 gimple_current_bind_expr (void)
163 return gimplify_ctxp
->current_bind_expr
;
166 /* Returns true iff there is a COND_EXPR between us and the innermost
167 CLEANUP_POINT_EXPR. This info is used by gimple_push_cleanup. */
170 gimple_conditional_context (void)
172 return gimplify_ctxp
->conditions
> 0;
175 /* Note that we've entered a COND_EXPR. */
178 gimple_push_condition (void)
180 ++(gimplify_ctxp
->conditions
);
183 /* Note that we've left a COND_EXPR. If we're back at unconditional scope
184 now, add any conditional cleanups we've seen to the prequeue. */
187 gimple_pop_condition (tree
*pre_p
)
189 int conds
= --(gimplify_ctxp
->conditions
);
192 append_to_statement_list (gimplify_ctxp
->conditional_cleanups
, pre_p
);
193 gimplify_ctxp
->conditional_cleanups
= NULL_TREE
;
199 /* A subroutine of append_to_statement_list{,_force}. */
202 append_to_statement_list_1 (tree t
, tree
*list_p
, bool side_effects
)
205 tree_stmt_iterator i
;
212 if (t
&& TREE_CODE (t
) == STATEMENT_LIST
)
217 *list_p
= list
= alloc_stmt_list ();
221 tsi_link_after (&i
, t
, TSI_CONTINUE_LINKING
);
224 /* Add T to the end of the list container pointed by LIST_P.
225 If T is an expression with no effects, it is ignored. */
228 append_to_statement_list (tree t
, tree
*list_p
)
230 append_to_statement_list_1 (t
, list_p
, t
? TREE_SIDE_EFFECTS (t
) : false);
233 /* Similar, but the statement is always added, regardless of side effects. */
236 append_to_statement_list_force (tree t
, tree
*list_p
)
238 append_to_statement_list_1 (t
, list_p
, t
!= NULL
);
241 /* Both gimplify the statement T and append it to LIST_P. */
244 gimplify_and_add (tree t
, tree
*list_p
)
247 append_to_statement_list (t
, list_p
);
250 /* Add T to the end of a COMPOUND_EXPR pointed by LIST_P. The type
251 of the result is the type of T. */
254 append_to_compound_expr (tree t
, tree
*list_p
)
261 *list_p
= build (COMPOUND_EXPR
, TREE_TYPE (t
), *list_p
, t
);
264 /* Strip off a legitimate source ending from the input string NAME of
265 length LEN. Rather than having to know the names used by all of
266 our front ends, we strip off an ending of a period followed by
267 up to five characters. (Java uses ".class".) */
270 remove_suffix (char *name
, int len
)
274 for (i
= 2; i
< 8 && len
> i
; i
++)
276 if (name
[len
- i
] == '.')
278 name
[len
- i
] = '\0';
284 /* Create a nameless artificial label and put it in the current function
285 context. Returns the newly created label. */
288 create_artificial_label (void)
290 tree lab
= build_decl (LABEL_DECL
, NULL_TREE
, void_type_node
);
291 DECL_ARTIFICIAL (lab
) = 1;
292 DECL_CONTEXT (lab
) = current_function_decl
;
296 /* Create a new temporary name with PREFIX. Returns an identifier. */
298 static GTY(()) unsigned int tmp_var_id_num
;
301 create_tmp_var_name (const char *prefix
)
307 char *preftmp
= ASTRDUP (prefix
);
308 remove_suffix (preftmp
, strlen (preftmp
));
312 ASM_FORMAT_PRIVATE_NAME (tmp_name
, prefix
? prefix
: "T", tmp_var_id_num
++);
313 return get_identifier (tmp_name
);
317 /* Create a new temporary variable declaration of type TYPE.
318 Does NOT push it into the current binding. */
321 create_tmp_var_raw (tree type
, const char *prefix
)
326 /* Make the type of the variable writable. */
327 new_type
= build_type_variant (type
, 0, 0);
328 TYPE_ATTRIBUTES (new_type
) = TYPE_ATTRIBUTES (type
);
330 tmp_var
= build_decl (VAR_DECL
, create_tmp_var_name (prefix
), type
);
332 /* The variable was declared by the compiler. */
333 DECL_ARTIFICIAL (tmp_var
) = 1;
334 /* And we don't want debug info for it. */
335 DECL_IGNORED_P (tmp_var
) = 1;
337 /* Make the variable writable. */
338 TREE_READONLY (tmp_var
) = 0;
340 DECL_EXTERNAL (tmp_var
) = 0;
341 TREE_STATIC (tmp_var
) = 0;
342 TREE_USED (tmp_var
) = 1;
347 /* Create a new temporary variable declaration of type TYPE. DOES push the
348 variable into the current binding. Further, assume that this is called
349 only from gimplification or optimization, at which point the creation of
350 certain types are bugs. */
353 create_tmp_var (tree type
, const char *prefix
)
357 #if defined ENABLE_CHECKING
358 /* If the type is an array or a type which must be created by the
359 frontend, something is wrong. */
360 if (TREE_CODE (type
) == ARRAY_TYPE
|| TREE_ADDRESSABLE (type
))
362 if (!COMPLETE_TYPE_P (type
))
364 /* Variable sized types require lots of machinery to create; the
365 optimizers shouldn't be doing anything of the sort. */
366 if (TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
)
370 tmp_var
= create_tmp_var_raw (type
, prefix
);
371 gimple_add_tmp_var (tmp_var
);
375 /* Given a tree, try to return a useful variable name that we can use
376 to prefix a temporary that is being assigned the value of the tree.
377 I.E. given <temp> = &A, return A. */
385 STRIP_NOPS (stripped_decl
);
386 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
387 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
390 switch (TREE_CODE (stripped_decl
))
393 return get_name (TREE_OPERAND (stripped_decl
, 0));
401 /* Create a temporary with a name derived from VAL. Subroutine of
402 lookup_tmp_var; nobody else should call this function. */
405 create_tmp_from_val (tree val
)
407 return create_tmp_var (TREE_TYPE (val
), get_name (val
));
410 /* Create a temporary to hold the value of VAL. If IS_FORMAL, try to reuse
411 an existing expression temporary. */
414 lookup_tmp_var (tree val
, bool is_formal
)
416 if (!is_formal
|| TREE_SIDE_EFFECTS (val
))
417 return create_tmp_from_val (val
);
424 slot
= htab_find_slot (gimplify_ctxp
->temp_htab
, (void *)&elt
, INSERT
);
427 elt_p
= xmalloc (sizeof (*elt_p
));
429 elt_p
->temp
= create_tmp_from_val (val
);
430 *slot
= (void *)elt_p
;
433 elt_p
= (elt_t
*) *slot
;
439 /* Returns a formal temporary variable initialized with VAL. PRE_P is as
440 in gimplify_expr. Only use this function if:
442 1) The value of the unfactored expression represented by VAL will not
443 change between the initialization and use of the temporary, and
444 2) The temporary will not be otherwise modified.
446 For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
447 and #2 means it is inappropriate for && temps.
449 For other cases, use get_initialized_tmp_var instead. */
452 internal_get_tmp_var (tree val
, tree
*pre_p
, tree
*post_p
, bool is_formal
)
457 gimplify_expr (&val
, pre_p
, post_p
, is_gimple_rhs
, fb_rvalue
);
459 t
= lookup_tmp_var (val
, is_formal
);
461 mod
= build (MODIFY_EXPR
, TREE_TYPE (t
), t
, val
);
463 class = TREE_CODE_CLASS (TREE_CODE (val
));
464 if (EXPR_LOCUS (val
))
465 SET_EXPR_LOCUS (mod
, EXPR_LOCUS (val
));
467 annotate_with_locus (mod
, input_location
);
468 /* gimplify_modify_expr might want to reduce this further. */
469 gimplify_stmt (&mod
);
470 append_to_statement_list (mod
, pre_p
);
476 get_formal_tmp_var (tree val
, tree
*pre_p
)
478 return internal_get_tmp_var (val
, pre_p
, NULL
, true);
481 /* Returns a temporary variable initialized with VAL. PRE_P and POST_P
482 are as in gimplify_expr. */
485 get_initialized_tmp_var (tree val
, tree
*pre_p
, tree
*post_p
)
487 return internal_get_tmp_var (val
, pre_p
, post_p
, false);
490 /* Returns true if T is a GIMPLE temporary variable, false otherwise. */
493 is_gimple_tmp_var (tree t
)
495 /* FIXME this could trigger for other local artificials, too. */
496 return (TREE_CODE (t
) == VAR_DECL
&& DECL_ARTIFICIAL (t
)
497 && !TREE_STATIC (t
) && !DECL_EXTERNAL (t
));
500 /* Declares all the variables in VARS in SCOPE. Returns the last
501 DECL_STMT emitted. */
504 declare_tmp_vars (tree vars
, tree scope
)
511 /* C99 mode puts the default 'return 0;' for main() outside the outer
512 braces. So drill down until we find an actual scope. */
513 while (TREE_CODE (scope
) == COMPOUND_EXPR
)
514 scope
= TREE_OPERAND (scope
, 0);
516 if (TREE_CODE (scope
) != BIND_EXPR
)
519 temps
= nreverse (last
);
520 TREE_CHAIN (last
) = BIND_EXPR_VARS (scope
);
521 BIND_EXPR_VARS (scope
) = temps
;
523 /* We don't add the temps to the block for this BIND_EXPR, as we're
524 not interested in debugging info for them. */
529 gimple_add_tmp_var (tree tmp
)
531 if (TREE_CHAIN (tmp
) || tmp
->decl
.seen_in_bind_expr
)
534 DECL_CONTEXT (tmp
) = current_function_decl
;
535 tmp
->decl
.seen_in_bind_expr
= 1;
539 TREE_CHAIN (tmp
) = gimplify_ctxp
->temps
;
540 gimplify_ctxp
->temps
= tmp
;
545 declare_tmp_vars (tmp
, DECL_SAVED_TREE (current_function_decl
));
548 /* Determines whether to assign a locus to the statement STMT. */
551 should_carry_locus_p (tree stmt
)
553 /* Don't emit a line note for a label. We particularly don't want to
554 emit one for the break label, since it doesn't actually correspond
555 to the beginning of the loop/switch. */
556 if (TREE_CODE (stmt
) == LABEL_EXPR
)
559 /* Do not annotate empty statements, since it confuses gcov. */
560 if (!TREE_SIDE_EFFECTS (stmt
))
567 annotate_one_with_locus (tree t
, location_t locus
)
569 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t
)))
570 && ! EXPR_HAS_LOCATION (t
)
571 && should_carry_locus_p (t
))
572 annotate_with_locus (t
, locus
);
576 annotate_all_with_locus (tree
*stmt_p
, location_t locus
)
578 tree_stmt_iterator i
;
583 for (i
= tsi_start (*stmt_p
); !tsi_end_p (i
); tsi_next (&i
))
585 tree t
= tsi_stmt (i
);
587 #ifdef ENABLE_CHECKING
588 /* Assuming we've already been gimplified, we shouldn't
589 see nested chaining constructs anymore. */
590 if (TREE_CODE (t
) == STATEMENT_LIST
591 || TREE_CODE (t
) == COMPOUND_EXPR
)
595 annotate_one_with_locus (t
, locus
);
599 /* Similar to copy_tree_r() but do not copy SAVE_EXPR or TARGET_EXPR nodes.
600 These nodes model computations that should only be done once. If we
601 were to unshare something like SAVE_EXPR(i++), the gimplification
602 process would create wrong code. */
605 mostly_copy_tree_r (tree
*tp
, int *walk_subtrees
, void *data
)
607 enum tree_code code
= TREE_CODE (*tp
);
608 /* Don't unshare types, decls, constants and SAVE_EXPR nodes. */
609 if (TREE_CODE_CLASS (code
) == 't'
610 || TREE_CODE_CLASS (code
) == 'd'
611 || TREE_CODE_CLASS (code
) == 'c'
612 || code
== SAVE_EXPR
|| code
== TARGET_EXPR
613 /* We can't do anything sensible with a BLOCK used as an expression,
614 but we also can't abort when we see it because of non-expression
615 uses. So just avert our eyes and cross our fingers. Silly Java. */
618 else if (code
== BIND_EXPR
)
621 copy_tree_r (tp
, walk_subtrees
, data
);
626 /* Mark all the _DECL nodes under *TP as volatile. FIXME: This must die
627 after VA_ARG_EXPRs are properly lowered. */
630 mark_decls_volatile_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
631 void *data ATTRIBUTE_UNUSED
)
634 TREE_THIS_VOLATILE (*tp
) = 1;
640 /* Callback for walk_tree to unshare most of the shared trees rooted at
641 *TP. If *TP has been visited already (i.e., TREE_VISITED (*TP) == 1),
642 then *TP is deep copied by calling copy_tree_r.
644 This unshares the same trees as copy_tree_r with the exception of
645 SAVE_EXPR nodes. These nodes model computations that should only be
646 done once. If we were to unshare something like SAVE_EXPR(i++), the
647 gimplification process would create wrong code. */
650 copy_if_shared_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
651 void *data ATTRIBUTE_UNUSED
)
654 enum tree_code code
= TREE_CODE (t
);
656 /* Skip types, decls, and constants. */
657 if (TREE_CODE_CLASS (code
) == 't'
658 || TREE_CODE_CLASS (code
) == 'd'
659 || TREE_CODE_CLASS (code
) == 'c')
662 /* Special-case BIND_EXPR. We should never be copying these, therefore
663 we can omit examining BIND_EXPR_VARS. Which also avoids problems with
664 double processing of the DECL_INITIAL, which could be seen via both
665 the BIND_EXPR_VARS and a DECL_STMT. */
666 else if (code
== BIND_EXPR
)
668 if (TREE_VISITED (t
))
670 TREE_VISITED (t
) = 1;
672 walk_tree (&BIND_EXPR_BODY (t
), copy_if_shared_r
, NULL
, NULL
);
675 /* If this node has been visited already, unshare it and don't look
677 else if (TREE_VISITED (t
))
679 walk_tree (tp
, mostly_copy_tree_r
, NULL
, NULL
);
683 /* Otherwise, mark the tree as visited and keep looking. */
686 TREE_VISITED (t
) = 1;
687 if (TREE_CODE (*tp
) == VA_ARG_EXPR
688 && targetm
.calls
.gimplify_va_arg_expr
== NULL
)
690 /* Mark any _DECL inside the operand as volatile to avoid
691 the optimizers messing around with it. We have to do this
692 early, otherwise we might mark a variable as volatile
693 after we gimplify other statements that use the variable
694 assuming it's not volatile. */
696 /* FIXME once most targets define the above hook, this should
697 go away (perhaps along with the #include "target.h"). */
698 walk_tree (&TREE_OPERAND (*tp
, 0), mark_decls_volatile_r
,
707 unmark_visited_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
708 void *data ATTRIBUTE_UNUSED
)
710 if (TREE_VISITED (*tp
))
711 TREE_VISITED (*tp
) = 0;
718 /* Unshare T and all the trees reached from T via TREE_CHAIN. */
721 unshare_all_trees (tree t
)
723 walk_tree (&t
, copy_if_shared_r
, NULL
, NULL
);
724 walk_tree (&t
, unmark_visited_r
, NULL
, NULL
);
727 /* Unconditionally make an unshared copy of EXPR. This is used when using
728 stored expressions which span multiple functions, such as BINFO_VTABLE,
729 as the normal unsharing process can't tell that they're shared. */
732 unshare_expr (tree expr
)
734 walk_tree (&expr
, mostly_copy_tree_r
, NULL
, NULL
);
738 /* A terser interface for building a representation of a exception
742 gimple_build_eh_filter (tree body
, tree allowed
, tree failure
)
746 /* FIXME should the allowed types go in TREE_TYPE? */
747 t
= build (EH_FILTER_EXPR
, void_type_node
, allowed
, NULL_TREE
);
748 append_to_statement_list (failure
, &EH_FILTER_FAILURE (t
));
750 t
= build (TRY_CATCH_EXPR
, void_type_node
, NULL_TREE
, t
);
751 append_to_statement_list (body
, &TREE_OPERAND (t
, 0));
757 /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
758 contain statements and have a value. Assign its value to a temporary
759 and give it void_type_node. Returns the temporary, or NULL_TREE if
760 WRAPPER was already void. */
763 voidify_wrapper_expr (tree wrapper
, tree temp
)
765 if (!VOID_TYPE_P (TREE_TYPE (wrapper
)))
767 tree
*p
, sub
= wrapper
;
770 /* Set p to point to the body of the wrapper. */
771 switch (TREE_CODE (sub
))
774 /* For a BIND_EXPR, the body is operand 1. */
775 p
= &BIND_EXPR_BODY (sub
);
779 p
= &TREE_OPERAND (sub
, 0);
783 /* Advance to the last statement. Set all container types to void. */
784 if (TREE_CODE (*p
) == STATEMENT_LIST
)
786 tree_stmt_iterator i
= tsi_last (*p
);
787 p
= tsi_end_p (i
) ? NULL
: tsi_stmt_ptr (i
);
791 for (; TREE_CODE (*p
) == COMPOUND_EXPR
; p
= &TREE_OPERAND (*p
, 1))
793 TREE_SIDE_EFFECTS (*p
) = 1;
794 TREE_TYPE (*p
) = void_type_node
;
798 if (p
== NULL
|| IS_EMPTY_STMT (*p
))
800 /* Look through exception handling. */
801 else if (TREE_CODE (*p
) == TRY_FINALLY_EXPR
802 || TREE_CODE (*p
) == TRY_CATCH_EXPR
)
807 /* The C++ frontend already did this for us. */
808 else if (TREE_CODE (*p
) == INIT_EXPR
)
809 temp
= TREE_OPERAND (*p
, 0);
810 /* If we're returning a dereference, move the dereference
811 outside the wrapper. */
812 else if (TREE_CODE (*p
) == INDIRECT_REF
)
814 tree ptr
= TREE_OPERAND (*p
, 0);
815 temp
= create_tmp_var (TREE_TYPE (ptr
), "retval");
816 *p
= build (MODIFY_EXPR
, TREE_TYPE (ptr
), temp
, ptr
);
817 temp
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (temp
)), temp
);
818 /* If this is a BIND_EXPR for a const inline function, it might not
819 have TREE_SIDE_EFFECTS set. That is no longer accurate. */
820 TREE_SIDE_EFFECTS (wrapper
) = 1;
825 temp
= create_tmp_var (TREE_TYPE (wrapper
), "retval");
826 *p
= build (MODIFY_EXPR
, TREE_TYPE (temp
), temp
, *p
);
827 TREE_SIDE_EFFECTS (wrapper
) = 1;
830 TREE_TYPE (wrapper
) = void_type_node
;
837 /* Prepare calls to builtins to SAVE and RESTORE the stack as well as
838 a temporary through which they communicate. */
841 build_stack_save_restore (tree
*save
, tree
*restore
)
843 tree save_call
, tmp_var
;
846 build_function_call_expr (implicit_built_in_decls
[BUILT_IN_STACK_SAVE
],
848 tmp_var
= create_tmp_var (ptr_type_node
, "saved_stack");
850 *save
= build (MODIFY_EXPR
, ptr_type_node
, tmp_var
, save_call
);
852 build_function_call_expr (implicit_built_in_decls
[BUILT_IN_STACK_RESTORE
],
853 tree_cons (NULL_TREE
, tmp_var
, NULL_TREE
));
856 /* Gimplify a BIND_EXPR. Just voidify and recurse. */
858 static enum gimplify_status
859 gimplify_bind_expr (tree
*expr_p
, tree temp
, tree
*pre_p
)
861 tree bind_expr
= *expr_p
;
862 bool old_save_stack
= gimplify_ctxp
->save_stack
;
865 temp
= voidify_wrapper_expr (bind_expr
, temp
);
867 /* Mark variables seen in this bind expr. */
868 for (t
= BIND_EXPR_VARS (bind_expr
); t
; t
= TREE_CHAIN (t
))
869 t
->decl
.seen_in_bind_expr
= 1;
871 gimple_push_bind_expr (bind_expr
);
872 gimplify_ctxp
->save_stack
= false;
874 gimplify_to_stmt_list (&BIND_EXPR_BODY (bind_expr
));
876 if (gimplify_ctxp
->save_stack
)
878 tree stack_save
, stack_restore
;
880 /* Save stack on entry and restore it on exit. Add a try_finally
881 block to achieve this. Note that mudflap depends on the
882 format of the emitted code: see mx_register_decls(). */
883 build_stack_save_restore (&stack_save
, &stack_restore
);
885 t
= build (TRY_FINALLY_EXPR
, void_type_node
,
886 BIND_EXPR_BODY (bind_expr
), NULL_TREE
);
887 append_to_statement_list (stack_restore
, &TREE_OPERAND (t
, 1));
889 BIND_EXPR_BODY (bind_expr
) = NULL_TREE
;
890 append_to_statement_list (stack_save
, &BIND_EXPR_BODY (bind_expr
));
891 append_to_statement_list (t
, &BIND_EXPR_BODY (bind_expr
));
894 gimplify_ctxp
->save_stack
= old_save_stack
;
895 gimple_pop_bind_expr ();
900 append_to_statement_list (bind_expr
, pre_p
);
907 /* Gimplify a RETURN_EXPR. If the expression to be returned is not a
908 GIMPLE value, it is assigned to a new temporary and the statement is
909 re-written to return the temporary.
911 PRE_P points to the list where side effects that must happen before
912 STMT should be stored. */
914 static enum gimplify_status
915 gimplify_return_expr (tree stmt
, tree
*pre_p
)
917 tree ret_expr
= TREE_OPERAND (stmt
, 0);
918 tree result_decl
, result
;
920 if (!ret_expr
|| TREE_CODE (ret_expr
) == RESULT_DECL
)
923 if (ret_expr
== error_mark_node
)
926 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl
))))
927 result_decl
= NULL_TREE
;
930 result_decl
= TREE_OPERAND (ret_expr
, 0);
931 #ifdef ENABLE_CHECKING
932 if ((TREE_CODE (ret_expr
) != MODIFY_EXPR
933 && TREE_CODE (ret_expr
) != INIT_EXPR
)
934 || TREE_CODE (result_decl
) != RESULT_DECL
)
939 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
940 Recall that aggregate_value_p is FALSE for any aggregate type that is
941 returned in registers. If we're returning values in registers, then
942 we don't want to extend the lifetime of the RESULT_DECL, particularly
943 across another call. In addition, for those aggregates for which
944 hard_function_value generates a PARALLEL, we'll abort during normal
945 expansion of structure assignments; there's special code in expand_return
946 to handle this case that does not exist in expand_expr. */
948 || aggregate_value_p (result_decl
, TREE_TYPE (current_function_decl
)))
949 result
= result_decl
;
950 else if (gimplify_ctxp
->return_temp
)
951 result
= gimplify_ctxp
->return_temp
;
954 result
= create_tmp_var (TREE_TYPE (result_decl
), NULL
);
956 /* ??? With complex control flow (usually involving abnormal edges),
957 we can wind up warning about an uninitialized value for this. Due
958 to how this variable is constructed and initialized, this is never
959 true. Give up and never warn. */
960 TREE_NO_WARNING (result
) = 1;
962 gimplify_ctxp
->return_temp
= result
;
965 /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
966 Then gimplify the whole thing. */
967 if (result
!= result_decl
)
968 TREE_OPERAND (ret_expr
, 0) = result
;
969 gimplify_stmt (&TREE_OPERAND (stmt
, 0));
970 append_to_statement_list (TREE_OPERAND (stmt
, 0), pre_p
);
972 /* If we didn't use a temporary, then the result is just the result_decl.
973 Otherwise we need a simple copy. This should already be gimple. */
974 if (result
== result_decl
)
977 ret_expr
= build (MODIFY_EXPR
, TREE_TYPE (result
), result_decl
, result
);
978 TREE_OPERAND (stmt
, 0) = ret_expr
;
983 /* Gimplify a LOOP_EXPR. Normally this just involves gimplifying the body
984 and replacing the LOOP_EXPR with goto, but if the loop contains an
985 EXIT_EXPR, we need to append a label for it to jump to. */
987 static enum gimplify_status
988 gimplify_loop_expr (tree
*expr_p
, tree
*pre_p
)
990 tree saved_label
= gimplify_ctxp
->exit_label
;
991 tree start_label
= build1 (LABEL_EXPR
, void_type_node
, NULL_TREE
);
992 tree jump_stmt
= build_and_jump (&LABEL_EXPR_LABEL (start_label
));
994 append_to_statement_list (start_label
, pre_p
);
996 gimplify_ctxp
->exit_label
= NULL_TREE
;
998 gimplify_stmt (&LOOP_EXPR_BODY (*expr_p
));
999 append_to_statement_list (LOOP_EXPR_BODY (*expr_p
), pre_p
);
1001 if (gimplify_ctxp
->exit_label
)
1003 append_to_statement_list (jump_stmt
, pre_p
);
1004 *expr_p
= build1 (LABEL_EXPR
, void_type_node
, gimplify_ctxp
->exit_label
);
1007 *expr_p
= jump_stmt
;
1009 gimplify_ctxp
->exit_label
= saved_label
;
1014 /* Compare two case labels. Because the front end should already have
1015 made sure that case ranges do not overlap, it is enough to only compare
1016 the CASE_LOW values of each case label. */
1019 compare_case_labels (const void *p1
, const void *p2
)
1021 tree case1
= *(tree
*)p1
;
1022 tree case2
= *(tree
*)p2
;
1024 return tree_int_cst_compare (CASE_LOW (case1
), CASE_LOW (case2
));
1027 /* Sort the case labels in LABEL_VEC in ascending order. */
1030 sort_case_labels (tree label_vec
)
1032 size_t len
= TREE_VEC_LENGTH (label_vec
);
1033 tree default_case
= TREE_VEC_ELT (label_vec
, len
- 1);
1035 if (CASE_LOW (default_case
))
1039 /* The last label in the vector should be the default case
1041 for (i
= 0; i
< len
; ++i
)
1043 tree t
= TREE_VEC_ELT (label_vec
, i
);
1047 TREE_VEC_ELT (label_vec
, i
) = TREE_VEC_ELT (label_vec
, len
- 1);
1048 TREE_VEC_ELT (label_vec
, len
- 1) = default_case
;
1054 qsort (&TREE_VEC_ELT (label_vec
, 0), len
- 1, sizeof (tree
),
1055 compare_case_labels
);
1058 /* Gimplify a SWITCH_EXPR, and collect a TREE_VEC of the labels it can
1061 static enum gimplify_status
1062 gimplify_switch_expr (tree
*expr_p
, tree
*pre_p
)
1064 tree switch_expr
= *expr_p
;
1065 enum gimplify_status ret
;
1067 ret
= gimplify_expr (&SWITCH_COND (switch_expr
), pre_p
, NULL
,
1068 is_gimple_val
, fb_rvalue
);
1070 if (SWITCH_BODY (switch_expr
))
1072 varray_type labels
, saved_labels
;
1073 tree label_vec
, default_case
= NULL_TREE
;
1076 /* If someone can be bothered to fill in the labels, they can
1077 be bothered to null out the body too. */
1078 if (SWITCH_LABELS (switch_expr
))
1081 saved_labels
= gimplify_ctxp
->case_labels
;
1082 VARRAY_TREE_INIT (gimplify_ctxp
->case_labels
, 8, "case_labels");
1084 gimplify_to_stmt_list (&SWITCH_BODY (switch_expr
));
1086 labels
= gimplify_ctxp
->case_labels
;
1087 gimplify_ctxp
->case_labels
= saved_labels
;
1089 len
= VARRAY_ACTIVE_SIZE (labels
);
1091 for (i
= 0; i
< len
; ++i
)
1093 tree t
= VARRAY_TREE (labels
, i
);
1096 /* The default case must be the last label in the list. */
1098 VARRAY_TREE (labels
, i
) = VARRAY_TREE (labels
, len
- 1);
1104 label_vec
= make_tree_vec (len
+ 1);
1105 SWITCH_LABELS (*expr_p
) = label_vec
;
1106 append_to_statement_list (switch_expr
, pre_p
);
1110 /* If the switch has no default label, add one, so that we jump
1111 around the switch body. */
1112 default_case
= build (CASE_LABEL_EXPR
, void_type_node
, NULL_TREE
,
1113 NULL_TREE
, create_artificial_label ());
1114 append_to_statement_list (SWITCH_BODY (switch_expr
), pre_p
);
1115 *expr_p
= build (LABEL_EXPR
, void_type_node
,
1116 CASE_LABEL (default_case
));
1119 *expr_p
= SWITCH_BODY (switch_expr
);
1121 for (i
= 0; i
< len
; ++i
)
1122 TREE_VEC_ELT (label_vec
, i
) = VARRAY_TREE (labels
, i
);
1123 TREE_VEC_ELT (label_vec
, len
) = default_case
;
1125 sort_case_labels (label_vec
);
1127 SWITCH_BODY (switch_expr
) = NULL
;
1129 else if (!SWITCH_LABELS (switch_expr
))
1135 static enum gimplify_status
1136 gimplify_case_label_expr (tree
*expr_p
)
1138 tree expr
= *expr_p
;
1139 if (gimplify_ctxp
->case_labels
)
1140 VARRAY_PUSH_TREE (gimplify_ctxp
->case_labels
, expr
);
1143 *expr_p
= build (LABEL_EXPR
, void_type_node
, CASE_LABEL (expr
));
1147 /* Gimplify a LABELED_BLOCK_EXPR into a LABEL_EXPR following
1148 a (possibly empty) body. */
1150 static enum gimplify_status
1151 gimplify_labeled_block_expr (tree
*expr_p
)
1153 tree body
= LABELED_BLOCK_BODY (*expr_p
);
1154 tree label
= LABELED_BLOCK_LABEL (*expr_p
);
1157 DECL_CONTEXT (label
) = current_function_decl
;
1158 t
= build (LABEL_EXPR
, void_type_node
, label
);
1159 if (body
!= NULL_TREE
)
1160 t
= build (COMPOUND_EXPR
, void_type_node
, body
, t
);
1166 /* Gimplify a EXIT_BLOCK_EXPR into a GOTO_EXPR. */
1168 static enum gimplify_status
1169 gimplify_exit_block_expr (tree
*expr_p
)
1171 tree labeled_block
= TREE_OPERAND (*expr_p
, 0);
1174 /* First operand must be a LABELED_BLOCK_EXPR, which should
1175 already be lowered (or partially lowered) when we get here. */
1176 #if defined ENABLE_CHECKING
1177 if (TREE_CODE (labeled_block
) != LABELED_BLOCK_EXPR
)
1181 label
= LABELED_BLOCK_LABEL (labeled_block
);
1182 *expr_p
= build1 (GOTO_EXPR
, void_type_node
, label
);
1187 /* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
1191 build_and_jump (tree
*label_p
)
1193 if (label_p
== NULL
)
1194 /* If there's nowhere to jump, just fall through. */
1195 return build_empty_stmt ();
1197 if (*label_p
== NULL_TREE
)
1199 tree label
= create_artificial_label ();
1203 return build1 (GOTO_EXPR
, void_type_node
, *label_p
);
1206 /* Gimplify an EXIT_EXPR by converting to a GOTO_EXPR inside a COND_EXPR.
1207 This also involves building a label to jump to and communicating it to
1208 gimplify_loop_expr through gimplify_ctxp->exit_label. */
1210 static enum gimplify_status
1211 gimplify_exit_expr (tree
*expr_p
)
1213 tree cond
= TREE_OPERAND (*expr_p
, 0);
1216 expr
= build_and_jump (&gimplify_ctxp
->exit_label
);
1217 expr
= build (COND_EXPR
, void_type_node
, cond
, expr
, build_empty_stmt ());
1223 /* A helper function to be called via walk_tree. Mark all labels under *TP
1224 as being forced. To be called for DECL_INITIAL of static variables. */
1227 force_labels_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1231 if (TREE_CODE (*tp
) == LABEL_DECL
)
1232 FORCED_LABEL (*tp
) = 1;
1237 /* Break out elements of a constructor used as an initializer into separate
1240 Note that we still need to clear any elements that don't have explicit
1241 initializers, so if not all elements are initialized we keep the
1242 original MODIFY_EXPR, we just remove all of the constructor elements. */
1244 static enum gimplify_status
1245 gimplify_init_constructor (tree
*expr_p
, tree
*pre_p
,
1246 tree
*post_p
, int want_value
)
1248 tree object
= TREE_OPERAND (*expr_p
, 0);
1249 tree ctor
= TREE_OPERAND (*expr_p
, 1);
1250 tree type
= TREE_TYPE (ctor
);
1251 enum gimplify_status ret
;
1254 if (TREE_CODE (ctor
) != CONSTRUCTOR
)
1255 return GS_UNHANDLED
;
1257 elt_list
= CONSTRUCTOR_ELTS (ctor
);
1260 switch (TREE_CODE (type
))
1264 case QUAL_UNION_TYPE
:
1267 HOST_WIDE_INT i
, num_elements
, num_nonzero_elements
;
1268 HOST_WIDE_INT num_nonconstant_elements
;
1271 /* Aggregate types must lower constructors to initialization of
1272 individual elements. The exception is that a CONSTRUCTOR node
1273 with no elements indicates zero-initialization of the whole. */
1274 if (elt_list
== NULL
)
1285 categorize_ctor_elements (ctor
, &num_nonzero_elements
,
1286 &num_nonconstant_elements
);
1287 num_elements
= count_type_elements (TREE_TYPE (ctor
));
1289 /* If a const aggregate variable is being initialized, then it
1290 should never be a lose to promote the variable to be static. */
1291 if (num_nonconstant_elements
== 0
1292 && TREE_READONLY (object
)
1293 && TREE_CODE (object
) == VAR_DECL
)
1295 DECL_INITIAL (object
) = ctor
;
1296 TREE_STATIC (object
) = 1;
1297 if (!DECL_NAME (object
))
1298 DECL_NAME (object
) = create_tmp_var_name ("C");
1299 walk_tree (&DECL_INITIAL (object
), force_labels_r
, NULL
, NULL
);
1301 /* ??? C++ doesn't automatically append a .<number> to the
1302 assembler name, and even when it does, it looks a FE private
1303 data structures to figure out what that number should be,
1304 which are not set for this variable. I suppose this is
1305 important for local statics for inline functions, which aren't
1306 "local" in the object file sense. So in order to get a unique
1307 TU-local symbol, we must invoke the lhd version now. */
1308 lhd_set_decl_assembler_name (object
);
1310 *expr_p
= build_empty_stmt ();
1314 /* If there are "lots" of initialized elements, and all of them
1315 are valid address constants, then the entire initializer can
1316 be dropped to memory, and then memcpy'd out. */
1317 if (num_nonconstant_elements
== 0)
1319 HOST_WIDE_INT size
= int_size_in_bytes (type
);
1322 /* ??? We can still get unbounded array types, at least
1323 from the C++ front end. This seems wrong, but attempt
1324 to work around it for now. */
1327 size
= int_size_in_bytes (TREE_TYPE (object
));
1329 TREE_TYPE (ctor
) = type
= TREE_TYPE (object
);
1332 /* Find the maximum alignment we can assume for the object. */
1333 /* ??? Make use of DECL_OFFSET_ALIGN. */
1334 if (DECL_P (object
))
1335 align
= DECL_ALIGN (object
);
1337 align
= TYPE_ALIGN (type
);
1339 if (size
> 0 && !can_move_by_pieces (size
, align
))
1341 tree
new = create_tmp_var_raw (type
, "C");
1342 gimple_add_tmp_var (new);
1343 TREE_STATIC (new) = 1;
1344 TREE_READONLY (new) = 1;
1345 DECL_INITIAL (new) = ctor
;
1346 if (align
> DECL_ALIGN (new))
1348 DECL_ALIGN (new) = align
;
1349 DECL_USER_ALIGN (new) = 1;
1351 walk_tree (&DECL_INITIAL (new), force_labels_r
, NULL
, NULL
);
1353 TREE_OPERAND (*expr_p
, 1) = new;
1358 /* If there are "lots" of initialized elements, even discounting
1359 those that are not address constants (and thus *must* be
1360 computed at runtime), then partition the constructor into
1361 constant and non-constant parts. Block copy the constant
1362 parts in, then generate code for the non-constant parts. */
1363 /* TODO. There's code in cp/typeck.c to do this. */
1365 /* If there are "lots" of zeros, then block clear the object first. */
1367 if (num_elements
- num_nonzero_elements
> CLEAR_RATIO
1368 && num_nonzero_elements
< num_elements
/4)
1371 /* ??? This bit ought not be needed. For any element not present
1372 in the initializer, we should simply set them to zero. Except
1373 we'd need to *find* the elements that are not present, and that
1374 requires trickery to avoid quadratic compile-time behavior in
1375 large cases or excessive memory use in small cases. */
1378 HOST_WIDE_INT len
= list_length (elt_list
);
1379 if (TREE_CODE (type
) == ARRAY_TYPE
)
1381 tree nelts
= array_type_nelts (type
);
1382 if (!host_integerp (nelts
, 1)
1383 || tree_low_cst (nelts
, 1) != len
)
1386 else if (len
!= fields_length (type
))
1392 CONSTRUCTOR_ELTS (ctor
) = NULL_TREE
;
1393 append_to_statement_list (*expr_p
, pre_p
);
1396 for (i
= 0; elt_list
; i
++, elt_list
= TREE_CHAIN (elt_list
))
1398 tree purpose
, value
, cref
, init
;
1400 purpose
= TREE_PURPOSE (elt_list
);
1401 value
= TREE_VALUE (elt_list
);
1403 if (cleared
&& initializer_zerop (value
))
1406 if (TREE_CODE (type
) == ARRAY_TYPE
)
1408 tree t
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (object
)));
1410 /* ??? Here's to hoping the front end fills in all of the
1411 indicies, so we don't have to figure out what's missing
1415 /* ??? Need to handle this. */
1416 if (TREE_CODE (purpose
) == RANGE_EXPR
)
1419 cref
= build (ARRAY_REF
, t
, object
, purpose
);
1423 cref
= build (COMPONENT_REF
, TREE_TYPE (purpose
),
1427 init
= build (MODIFY_EXPR
, TREE_TYPE (purpose
), cref
, value
);
1428 /* Each member initialization is a full-expression. */
1429 gimplify_stmt (&init
);
1430 append_to_statement_list (init
, pre_p
);
1433 *expr_p
= build_empty_stmt ();
1441 /* Extract the real and imaginary parts out of the ctor. */
1445 r
= TREE_VALUE (elt_list
);
1446 elt_list
= TREE_CHAIN (elt_list
);
1449 i
= TREE_VALUE (elt_list
);
1450 if (TREE_CHAIN (elt_list
))
1454 if (r
== NULL
|| i
== NULL
)
1456 tree zero
= convert (TREE_TYPE (type
), integer_zero_node
);
1463 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
1464 represent creation of a complex value. */
1465 if (TREE_CONSTANT (r
) && TREE_CONSTANT (i
))
1467 ctor
= build_complex (type
, r
, i
);
1468 TREE_OPERAND (*expr_p
, 1) = ctor
;
1472 ctor
= build (COMPLEX_EXPR
, type
, r
, i
);
1473 TREE_OPERAND (*expr_p
, 1) = ctor
;
1474 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
1475 is_gimple_rhs
, fb_rvalue
);
1481 /* Go ahead and simplify constant constructors to VECTOR_CST. */
1482 if (TREE_CONSTANT (ctor
))
1483 TREE_OPERAND (*expr_p
, 1) = build_vector (type
, elt_list
);
1486 /* Vector types use CONSTRUCTOR all the way through gimple
1487 compilation as a general initializer. */
1488 for (; elt_list
; elt_list
= TREE_CHAIN (elt_list
))
1490 enum gimplify_status tret
;
1491 tret
= gimplify_expr (&TREE_VALUE (elt_list
), pre_p
, post_p
,
1492 is_gimple_constructor_elt
, fb_rvalue
);
1493 if (tret
== GS_ERROR
)
1500 /* So how did we get a CONSTRUCTOR for a scalar type? */
1504 if (ret
== GS_ERROR
)
1506 else if (want_value
)
1508 append_to_statement_list (*expr_p
, pre_p
);
1516 /* *EXPR_P is a COMPONENT_REF being used as an rvalue. If its type is
1517 different from its canonical type, wrap the whole thing inside a
1518 NOP_EXPR and force the type of the COMPONENT_REF to be the canonical
1521 The canonical type of a COMPONENT_REF is the type of the field being
1522 referenced--unless the field is a bit-field which can be read directly
1523 in a smaller mode, in which case the canonical type is the
1524 sign-appropriate type corresponding to that mode. */
1527 canonicalize_component_ref (tree
*expr_p
)
1529 tree expr
= *expr_p
;
1532 if (TREE_CODE (expr
) != COMPONENT_REF
)
1535 if (INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
1536 type
= TREE_TYPE (get_unwidened (expr
, NULL_TREE
));
1538 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
1540 if (TREE_TYPE (expr
) != type
)
1542 tree old_type
= TREE_TYPE (expr
);
1544 /* Set the type of the COMPONENT_REF to the underlying type. */
1545 TREE_TYPE (expr
) = type
;
1547 /* And wrap the whole thing inside a NOP_EXPR. */
1548 expr
= build1 (NOP_EXPR
, old_type
, expr
);
1554 /* If a NOP conversion is changing a pointer to array of foo to a pointer
1555 to foo, embed that change in the ADDR_EXPR. Lest we perturb the type
1556 system too badly, we must take extra steps to ensure that the ADDR_EXPR
1557 and the addressed object continue to agree on types. */
1558 /* ??? We might could do better if we recognize
1566 canonicalize_addr_expr (tree
* expr_p
)
1568 tree expr
= *expr_p
;
1569 tree ctype
= TREE_TYPE (expr
);
1570 tree addr_expr
= TREE_OPERAND (expr
, 0);
1571 tree atype
= TREE_TYPE (addr_expr
);
1572 tree dctype
, datype
, ddatype
, otype
, obj_expr
;
1574 /* Both cast and addr_expr types should be pointers. */
1575 if (!POINTER_TYPE_P (ctype
) || !POINTER_TYPE_P (atype
))
1578 /* The addr_expr type should be a pointer to an array. */
1579 datype
= TREE_TYPE (atype
);
1580 if (TREE_CODE (datype
) != ARRAY_TYPE
)
1583 /* Both cast and addr_expr types should address the same object type. */
1584 dctype
= TREE_TYPE (ctype
);
1585 ddatype
= TREE_TYPE (datype
);
1586 if (!lang_hooks
.types_compatible_p (ddatype
, dctype
))
1589 /* The addr_expr and the object type should match. */
1590 obj_expr
= TREE_OPERAND (addr_expr
, 0);
1591 otype
= TREE_TYPE (obj_expr
);
1592 if (!lang_hooks
.types_compatible_p (otype
, datype
))
1595 /* All checks succeeded. Build a new node to merge the cast. */
1596 *expr_p
= build1 (ADDR_EXPR
, ctype
, obj_expr
);
1599 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions
1600 underneath as appropriate. */
1602 static enum gimplify_status
1603 gimplify_conversion (tree
*expr_p
)
1605 /* Strip away as many useless type conversions as possible
1607 STRIP_USELESS_TYPE_CONVERSION (*expr_p
);
1609 /* If we still have a conversion at the toplevel, then strip
1610 away all but the outermost conversion. */
1611 if (TREE_CODE (*expr_p
) == NOP_EXPR
|| TREE_CODE (*expr_p
) == CONVERT_EXPR
)
1613 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p
, 0));
1615 /* And remove the outermost conversion if it's useless. */
1616 if (tree_ssa_useless_type_conversion (*expr_p
))
1617 *expr_p
= TREE_OPERAND (*expr_p
, 0);
1620 /* If we still have a conversion at the toplevel,
1621 then canonicalize some constructs. */
1622 if (TREE_CODE (*expr_p
) == NOP_EXPR
|| TREE_CODE (*expr_p
) == CONVERT_EXPR
)
1624 tree sub
= TREE_OPERAND (*expr_p
, 0);
1626 /* If a NOP conversion is changing the type of a COMPONENT_REF
1627 expression, then canonicalize its type now in order to expose more
1628 redundant conversions. */
1629 if (TREE_CODE (sub
) == COMPONENT_REF
)
1630 canonicalize_component_ref (&TREE_OPERAND (*expr_p
, 0));
1632 /* If a NOP conversion is changing a pointer to array of foo
1633 to a pointer to foo, embed that change in the ADDR_EXPR. */
1634 else if (TREE_CODE (sub
) == ADDR_EXPR
)
1635 canonicalize_addr_expr (expr_p
);
1641 /* Reduce MIN/MAX_EXPR to a COND_EXPR for further gimplification. */
1643 static enum gimplify_status
1644 gimplify_minimax_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
1646 tree op1
= TREE_OPERAND (*expr_p
, 0);
1647 tree op2
= TREE_OPERAND (*expr_p
, 1);
1648 enum tree_code code
;
1649 enum gimplify_status r0
, r1
;
1651 if (TREE_CODE (*expr_p
) == MIN_EXPR
)
1656 r0
= gimplify_expr (&op1
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
1657 r1
= gimplify_expr (&op2
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
1659 *expr_p
= build (COND_EXPR
, TREE_TYPE (*expr_p
),
1660 build (code
, boolean_type_node
, op1
, op2
),
1663 if (r0
== GS_ERROR
|| r1
== GS_ERROR
)
1669 /* Subroutine of gimplify_compound_lval and gimplify_array_ref.
1670 Converts an ARRAY_REF to the equivalent *(&array + offset) form. */
1672 static enum gimplify_status
1673 gimplify_array_ref_to_plus (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
1675 tree array
= TREE_OPERAND (*expr_p
, 0);
1676 tree arrtype
= TREE_TYPE (array
);
1677 tree elttype
= TREE_TYPE (arrtype
);
1678 tree size
= size_in_bytes (elttype
);
1679 tree ptrtype
= build_pointer_type (elttype
);
1680 enum tree_code add_code
= PLUS_EXPR
;
1681 tree idx
= TREE_OPERAND (*expr_p
, 1);
1682 tree minidx
, offset
, addr
, result
;
1683 enum gimplify_status ret
;
1685 /* If the array domain does not start at zero, apply the offset. */
1686 minidx
= TYPE_DOMAIN (arrtype
);
1689 minidx
= TYPE_MIN_VALUE (minidx
);
1690 if (minidx
&& !integer_zerop (minidx
))
1692 idx
= convert (TREE_TYPE (minidx
), idx
);
1693 idx
= fold (build (MINUS_EXPR
, TREE_TYPE (minidx
), idx
, minidx
));
1697 /* If the index is negative -- a technically invalid situation now
1698 that we've biased the index back to zero -- then casting it to
1699 unsigned has ill effects. In particular, -1*4U/4U != -1.
1700 Represent this as a subtraction of a positive rather than addition
1701 of a negative. This will prevent any conversion back to ARRAY_REF
1702 from getting the wrong results from the division. */
1703 if (TREE_CODE (idx
) == INTEGER_CST
&& tree_int_cst_sgn (idx
) < 0)
1705 idx
= fold (build1 (NEGATE_EXPR
, TREE_TYPE (idx
), idx
));
1706 add_code
= MINUS_EXPR
;
1709 /* Pointer arithmetic must be done in sizetype. */
1710 idx
= convert (sizetype
, idx
);
1712 /* Convert the index to a byte offset. */
1713 offset
= size_binop (MULT_EXPR
, size
, idx
);
1715 ret
= gimplify_expr (&array
, pre_p
, post_p
, is_gimple_min_lval
, fb_lvalue
);
1716 if (ret
== GS_ERROR
)
1719 addr
= build_fold_addr_expr_with_type (array
, ptrtype
);
1720 result
= fold (build (add_code
, ptrtype
, addr
, offset
));
1721 *expr_p
= build1 (INDIRECT_REF
, elttype
, result
);
1726 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
1727 node pointed by EXPR_P.
1730 : min_lval '[' val ']'
1732 | compound_lval '[' val ']'
1733 | compound_lval '.' ID
1735 This is not part of the original SIMPLE definition, which separates
1736 array and member references, but it seems reasonable to handle them
1737 together. Also, this way we don't run into problems with union
1738 aliasing; gcc requires that for accesses through a union to alias, the
1739 union reference must be explicit, which was not always the case when we
1740 were splitting up array and member refs.
1742 PRE_P points to the list where side effects that must happen before
1743 *EXPR_P should be stored.
1745 POST_P points to the list where side effects that must happen after
1746 *EXPR_P should be stored. */
1748 static enum gimplify_status
1749 gimplify_compound_lval (tree
*expr_p
, tree
*pre_p
,
1750 tree
*post_p
, int want_lvalue
)
1753 enum tree_code code
;
1755 enum gimplify_status ret
;
1757 #if defined ENABLE_CHECKING
1758 if (TREE_CODE (*expr_p
) != ARRAY_REF
1759 && TREE_CODE (*expr_p
) != COMPONENT_REF
1760 && TREE_CODE (*expr_p
) != REALPART_EXPR
1761 && TREE_CODE (*expr_p
) != IMAGPART_EXPR
)
1765 code
= ERROR_MARK
; /* [GIMPLE] Avoid uninitialized use warning. */
1767 /* Create a stack of the subexpressions so later we can walk them in
1768 order from inner to outer. */
1769 VARRAY_TREE_INIT (stack
, 10, "stack");
1772 TREE_CODE (*p
) == ARRAY_REF
1773 || TREE_CODE (*p
) == COMPONENT_REF
1774 || TREE_CODE (*p
) == REALPART_EXPR
1775 || TREE_CODE (*p
) == IMAGPART_EXPR
;
1776 p
= &TREE_OPERAND (*p
, 0))
1778 code
= TREE_CODE (*p
);
1779 if (code
== ARRAY_REF
)
1781 tree elttype
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (*p
, 0)));
1782 if (!TREE_CONSTANT (TYPE_SIZE_UNIT (elttype
)))
1783 /* If the size of the array elements is not constant,
1784 computing the offset is non-trivial, so expose it. */
1787 VARRAY_PUSH_TREE (stack
, *p
);
1790 /* Now 'p' points to the first bit that isn't a ref, 'code' is the
1791 TREE_CODE of the last bit that was, and 'stack' is a stack of pointers
1792 to all the refs we've walked through.
1794 Gimplify the base, and then process each of the outer nodes from left
1796 ret
= gimplify_expr (p
, pre_p
, post_p
, is_gimple_min_lval
,
1797 code
!= ARRAY_REF
? fb_either
: fb_lvalue
);
1799 for (; VARRAY_ACTIVE_SIZE (stack
) > 0; )
1801 tree t
= VARRAY_TOP_TREE (stack
);
1802 if (TREE_CODE (t
) == ARRAY_REF
)
1804 /* Gimplify the dimension. */
1805 enum gimplify_status tret
;
1806 /* Temporary fix for gcc.c-torture/execute/20040313-1.c.
1807 Gimplify non-constant array indices into a temporary
1809 FIXME - The real fix is to gimplify post-modify
1810 expressions into a minimal gimple lvalue. However, that
1811 exposes bugs in alias analysis. The alias analyzer does
1812 not handle &PTR->FIELD very well. Will fix after the
1813 branch is merged into mainline (dnovillo 2004-05-03). */
1814 if (!is_gimple_min_invariant (TREE_OPERAND (t
, 1)))
1816 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), pre_p
, post_p
,
1817 is_gimple_tmp_var
, fb_rvalue
);
1818 if (tret
== GS_ERROR
)
1822 recalculate_side_effects (t
);
1826 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */
1827 if (!want_lvalue
&& TREE_CODE (*expr_p
) == COMPONENT_REF
)
1829 canonicalize_component_ref (expr_p
);
1830 ret
= MIN (ret
, GS_OK
);
1836 /* Re-write the ARRAY_REF node pointed by EXPR_P.
1838 PRE_P points to the list where side effects that must happen before
1839 *EXPR_P should be stored.
1841 POST_P points to the list where side effects that must happen after
1842 *EXPR_P should be stored.
1844 FIXME: ARRAY_REF currently doesn't accept a pointer as the array
1845 argument, so this gimplification uses an INDIRECT_REF of ARRAY_TYPE.
1846 ARRAY_REF should be extended. */
1848 static enum gimplify_status
1849 gimplify_array_ref (tree
*expr_p
, tree
*pre_p
,
1850 tree
*post_p
, int want_lvalue
)
1852 tree elttype
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (*expr_p
, 0)));
1853 if (!TREE_CONSTANT (TYPE_SIZE_UNIT (elttype
)))
1854 /* If the size of the array elements is not constant,
1855 computing the offset is non-trivial, so expose it. */
1856 return gimplify_array_ref_to_plus (expr_p
, pre_p
, post_p
);
1858 /* Handle array and member refs together for now. When alias analysis
1859 improves, we may want to go back to handling them separately. */
1860 return gimplify_compound_lval (expr_p
, pre_p
, post_p
, want_lvalue
);
1863 /* Gimplify the self modifying expression pointed by EXPR_P (++, --, +=, -=).
1865 PRE_P points to the list where side effects that must happen before
1866 *EXPR_P should be stored.
1868 POST_P points to the list where side effects that must happen after
1869 *EXPR_P should be stored.
1871 WANT_VALUE is nonzero iff we want to use the value of this expression
1872 in another expression. */
1874 static enum gimplify_status
1875 gimplify_self_mod_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
,
1878 enum tree_code code
;
1879 tree lhs
, lvalue
, rhs
, t1
;
1881 enum tree_code arith_code
;
1882 enum gimplify_status ret
;
1884 code
= TREE_CODE (*expr_p
);
1886 #if defined ENABLE_CHECKING
1887 if (code
!= POSTINCREMENT_EXPR
1888 && code
!= POSTDECREMENT_EXPR
1889 && code
!= PREINCREMENT_EXPR
1890 && code
!= PREDECREMENT_EXPR
)
1894 /* Prefix or postfix? */
1895 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1896 /* Faster to treat as prefix if result is not used. */
1897 postfix
= want_value
;
1901 /* Add or subtract? */
1902 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
1903 arith_code
= PLUS_EXPR
;
1905 arith_code
= MINUS_EXPR
;
1907 /* Gimplify the LHS into a GIMPLE lvalue. */
1908 lvalue
= TREE_OPERAND (*expr_p
, 0);
1909 ret
= gimplify_expr (&lvalue
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
1910 if (ret
== GS_ERROR
)
1913 /* Extract the operands to the arithmetic operation. */
1915 rhs
= TREE_OPERAND (*expr_p
, 1);
1917 /* For postfix operator, we evaluate the LHS to an rvalue and then use
1918 that as the result value and in the postqueue operation. */
1921 ret
= gimplify_expr (&lhs
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
1922 if (ret
== GS_ERROR
)
1926 t1
= build (arith_code
, TREE_TYPE (*expr_p
), lhs
, rhs
);
1927 t1
= build (MODIFY_EXPR
, TREE_TYPE (lvalue
), lvalue
, t1
);
1931 gimplify_stmt (&t1
);
1932 append_to_statement_list (t1
, post_p
);
1943 /* Gimplify the CALL_EXPR node pointed by EXPR_P.
1946 : ID '(' arglist ')'
1952 PRE_P points to the list where side effects that must happen before
1953 *EXPR_P should be stored. */
1955 static enum gimplify_status
1956 gimplify_call_expr (tree
*expr_p
, tree
*pre_p
, bool (*gimple_test_f
) (tree
))
1960 enum gimplify_status ret
;
1962 #if defined ENABLE_CHECKING
1963 if (TREE_CODE (*expr_p
) != CALL_EXPR
)
1967 /* For reliable diagnostics during inlining, it is necessary that
1968 every call_expr be annotated with file and line. */
1969 if (!EXPR_LOCUS (*expr_p
))
1970 annotate_with_locus (*expr_p
, input_location
);
1972 /* This may be a call to a builtin function.
1974 Builtin function calls may be transformed into different
1975 (and more efficient) builtin function calls under certain
1976 circumstances. Unfortunately, gimplification can muck things
1977 up enough that the builtin expanders are not aware that certain
1978 transformations are still valid.
1980 So we attempt transformation/gimplification of the call before
1981 we gimplify the CALL_EXPR. At this time we do not manage to
1982 transform all calls in the same manner as the expanders do, but
1983 we do transform most of them. */
1984 decl
= get_callee_fndecl (*expr_p
);
1985 if (decl
&& DECL_BUILT_IN (decl
))
1989 /* If it is allocation of stack, record the need to restore the memory
1990 when the enclosing bind_expr is exited. */
1991 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_STACK_ALLOC
)
1992 gimplify_ctxp
->save_stack
= true;
1994 /* If it is restore of the stack, reset it, since it means we are
1995 regimplifying the bind_expr. Note that we use the fact that
1996 for try_finally_expr, try part is processed first. */
1997 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_STACK_RESTORE
)
1998 gimplify_ctxp
->save_stack
= false;
2000 new = simplify_builtin (*expr_p
, gimple_test_f
== is_gimple_stmt
);
2002 if (new && new != *expr_p
)
2004 /* There was a transformation of this call which computes the
2005 same value, but in a more efficient way. Return and try
2012 /* There is a sequence point before the call, so any side effects in
2013 the calling expression must occur before the actual call. Force
2014 gimplify_expr to use an internal post queue. */
2015 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, NULL
,
2016 is_gimple_val
, fb_rvalue
);
2018 if (PUSH_ARGS_REVERSED
)
2019 TREE_OPERAND (*expr_p
, 1) = nreverse (TREE_OPERAND (*expr_p
, 1));
2020 for (arglist
= TREE_OPERAND (*expr_p
, 1); arglist
;
2021 arglist
= TREE_CHAIN (arglist
))
2023 enum gimplify_status t
;
2025 /* There is a sequence point before a function call. Side effects in
2026 the argument list must occur before the actual call. So, when
2027 gimplifying arguments, force gimplify_expr to use an internal
2028 post queue which is then appended to the end of PRE_P. */
2029 t
= gimplify_expr (&TREE_VALUE (arglist
), pre_p
, NULL
, is_gimple_val
,
2035 if (PUSH_ARGS_REVERSED
)
2036 TREE_OPERAND (*expr_p
, 1) = nreverse (TREE_OPERAND (*expr_p
, 1));
2038 /* Try this again in case gimplification exposed something. */
2039 if (ret
!= GS_ERROR
&& decl
&& DECL_BUILT_IN (decl
))
2041 tree
new = simplify_builtin (*expr_p
, gimple_test_f
== is_gimple_stmt
);
2043 if (new && new != *expr_p
)
2045 /* There was a transformation of this call which computes the
2046 same value, but in a more efficient way. Return and try
2053 /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
2054 decl. This allows us to eliminate redundant or useless
2055 calls to "const" functions. */
2056 if (TREE_CODE (*expr_p
) == CALL_EXPR
2057 && (call_expr_flags (*expr_p
) & (ECF_CONST
| ECF_PURE
)))
2058 TREE_SIDE_EFFECTS (*expr_p
) = 0;
2063 /* Handle shortcut semantics in the predicate operand of a COND_EXPR by
2064 rewriting it into multiple COND_EXPRs, and possibly GOTO_EXPRs.
2066 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
2067 condition is true or false, respectively. If null, we should generate
2068 our own to skip over the evaluation of this specific expression.
2070 This function is the tree equivalent of do_jump.
2072 shortcut_cond_r should only be called by shortcut_cond_expr. */
2075 shortcut_cond_r (tree pred
, tree
*true_label_p
, tree
*false_label_p
)
2077 tree local_label
= NULL_TREE
;
2078 tree t
, expr
= NULL
;
2080 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
2081 retain the shortcut semantics. Just insert the gotos here;
2082 shortcut_cond_expr will append the real blocks later. */
2083 if (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
2085 /* Turn if (a && b) into
2087 if (a); else goto no;
2088 if (b) goto yes; else goto no;
2091 if (false_label_p
== NULL
)
2092 false_label_p
= &local_label
;
2094 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), NULL
, false_label_p
);
2095 append_to_statement_list (t
, &expr
);
2097 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
,
2099 append_to_statement_list (t
, &expr
);
2101 else if (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
2103 /* Turn if (a || b) into
2106 if (b) goto yes; else goto no;
2109 if (true_label_p
== NULL
)
2110 true_label_p
= &local_label
;
2112 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), true_label_p
, NULL
);
2113 append_to_statement_list (t
, &expr
);
2115 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
,
2117 append_to_statement_list (t
, &expr
);
2119 else if (TREE_CODE (pred
) == COND_EXPR
)
2121 /* As long as we're messing with gotos, turn if (a ? b : c) into
2123 if (b) goto yes; else goto no;
2125 if (c) goto yes; else goto no; */
2126 expr
= build (COND_EXPR
, void_type_node
, TREE_OPERAND (pred
, 0),
2127 shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
,
2129 shortcut_cond_r (TREE_OPERAND (pred
, 2), true_label_p
,
2134 expr
= build (COND_EXPR
, void_type_node
, pred
,
2135 build_and_jump (true_label_p
),
2136 build_and_jump (false_label_p
));
2141 t
= build1 (LABEL_EXPR
, void_type_node
, local_label
);
2142 append_to_statement_list (t
, &expr
);
2149 shortcut_cond_expr (tree expr
)
2151 tree pred
= TREE_OPERAND (expr
, 0);
2152 tree then_
= TREE_OPERAND (expr
, 1);
2153 tree else_
= TREE_OPERAND (expr
, 2);
2154 tree true_label
, false_label
, end_label
, t
;
2156 tree
*false_label_p
;
2157 bool emit_end
, emit_false
;
2159 /* First do simple transformations. */
2160 if (!TREE_SIDE_EFFECTS (else_
))
2162 /* If there is no 'else', turn (a && b) into if (a) if (b). */
2163 while (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
2165 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
2166 then_
= shortcut_cond_expr (expr
);
2167 pred
= TREE_OPERAND (pred
, 0);
2168 expr
= build (COND_EXPR
, void_type_node
, pred
, then_
,
2169 build_empty_stmt ());
2172 if (!TREE_SIDE_EFFECTS (then_
))
2174 /* If there is no 'then', turn
2177 if (a); else if (b); else d. */
2178 while (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
2180 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
2181 else_
= shortcut_cond_expr (expr
);
2182 pred
= TREE_OPERAND (pred
, 0);
2183 expr
= build (COND_EXPR
, void_type_node
, pred
,
2184 build_empty_stmt (), else_
);
2188 /* If we're done, great. */
2189 if (TREE_CODE (pred
) != TRUTH_ANDIF_EXPR
2190 && TREE_CODE (pred
) != TRUTH_ORIF_EXPR
)
2193 /* Otherwise we need to mess with gotos. Change
2196 if (a); else goto no;
2199 and recursively gimplify the condition. */
2201 true_label
= false_label
= end_label
= NULL_TREE
;
2203 /* If our arms just jump somewhere, hijack those labels so we don't
2204 generate jumps to jumps. */
2206 if (TREE_CODE (then_
) == GOTO_EXPR
2207 && TREE_CODE (GOTO_DESTINATION (then_
)) == LABEL_DECL
)
2209 true_label
= GOTO_DESTINATION (then_
);
2210 then_
= build_empty_stmt ();
2213 if (TREE_CODE (else_
) == GOTO_EXPR
2214 && TREE_CODE (GOTO_DESTINATION (else_
)) == LABEL_DECL
)
2216 false_label
= GOTO_DESTINATION (else_
);
2217 else_
= build_empty_stmt ();
2220 /* If we aren't hijacking a label for the 'then' branch, it falls through. */
2222 true_label_p
= &true_label
;
2224 true_label_p
= NULL
;
2226 /* The 'else' branch also needs a label if it contains interesting code. */
2227 if (false_label
|| TREE_SIDE_EFFECTS (else_
))
2228 false_label_p
= &false_label
;
2230 false_label_p
= NULL
;
2232 /* If there was nothing else in our arms, just forward the label(s). */
2233 if (!TREE_SIDE_EFFECTS (then_
) && !TREE_SIDE_EFFECTS (else_
))
2234 return shortcut_cond_r (pred
, true_label_p
, false_label_p
);
2236 /* If our last subexpression already has a terminal label, reuse it. */
2237 if (TREE_SIDE_EFFECTS (else_
))
2238 expr
= expr_last (else_
);
2240 expr
= expr_last (then_
);
2241 if (TREE_CODE (expr
) == LABEL_EXPR
)
2242 end_label
= LABEL_EXPR_LABEL (expr
);
2244 /* If we don't care about jumping to the 'else' branch, jump to the end
2245 if the condition is false. */
2247 false_label_p
= &end_label
;
2249 /* We only want to emit these labels if we aren't hijacking them. */
2250 emit_end
= (end_label
== NULL_TREE
);
2251 emit_false
= (false_label
== NULL_TREE
);
2253 pred
= shortcut_cond_r (pred
, true_label_p
, false_label_p
);
2256 append_to_statement_list (pred
, &expr
);
2258 append_to_statement_list (then_
, &expr
);
2259 if (TREE_SIDE_EFFECTS (else_
))
2261 t
= build_and_jump (&end_label
);
2262 append_to_statement_list (t
, &expr
);
2265 t
= build1 (LABEL_EXPR
, void_type_node
, false_label
);
2266 append_to_statement_list (t
, &expr
);
2268 append_to_statement_list (else_
, &expr
);
2270 if (emit_end
&& end_label
)
2272 t
= build1 (LABEL_EXPR
, void_type_node
, end_label
);
2273 append_to_statement_list (t
, &expr
);
2279 /* EXPR is used in a boolean context; make sure it has BOOLEAN_TYPE. */
2282 gimple_boolify (tree expr
)
2284 tree type
= TREE_TYPE (expr
);
2286 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
2289 /* If this is the predicate of a COND_EXPR, it might not even be a
2291 expr
= lang_hooks
.truthvalue_conversion (expr
);
2293 switch (TREE_CODE (expr
))
2295 case TRUTH_AND_EXPR
:
2297 case TRUTH_XOR_EXPR
:
2298 case TRUTH_ANDIF_EXPR
:
2299 case TRUTH_ORIF_EXPR
:
2300 /* Also boolify the arguments of truth exprs. */
2301 TREE_OPERAND (expr
, 1) = gimple_boolify (TREE_OPERAND (expr
, 1));
2304 case TRUTH_NOT_EXPR
:
2305 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
2308 case EQ_EXPR
: case NE_EXPR
:
2309 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
2310 /* These expressions always produce boolean results. */
2311 TREE_TYPE (expr
) = boolean_type_node
;
2315 /* Other expressions that get here must have boolean values, but
2316 might need to be converted to the appropriate mode. */
2317 return convert (boolean_type_node
, expr
);
2321 /* Convert the conditional expression pointed by EXPR_P '(p) ? a : b;'
2330 The second form is used when *EXPR_P is of type void.
2332 PRE_P points to the list where side effects that must happen before
2333 *EXPR_P should be stored. */
2335 static enum gimplify_status
2336 gimplify_cond_expr (tree
*expr_p
, tree
*pre_p
, tree target
)
2338 tree expr
= *expr_p
;
2340 enum gimplify_status ret
;
2342 /* If this COND_EXPR has a value, copy the values into a temporary within
2344 if (! VOID_TYPE_P (TREE_TYPE (expr
)))
2353 tmp
= create_tmp_var (TREE_TYPE (expr
), "iftmp");
2357 /* Build the then clause, 't1 = a;'. But don't build an assignment
2358 if this branch is void; in C++ it can be, if it's a throw. */
2359 if (TREE_TYPE (TREE_OPERAND (expr
, 1)) != void_type_node
)
2360 TREE_OPERAND (expr
, 1)
2361 = build (MODIFY_EXPR
, void_type_node
, tmp
, TREE_OPERAND (expr
, 1));
2363 /* Build the else clause, 't1 = b;'. */
2364 if (TREE_TYPE (TREE_OPERAND (expr
, 2)) != void_type_node
)
2365 TREE_OPERAND (expr
, 2)
2366 = build (MODIFY_EXPR
, void_type_node
, tmp
, TREE_OPERAND (expr
, 2));
2368 TREE_TYPE (expr
) = void_type_node
;
2369 recalculate_side_effects (expr
);
2371 /* Move the COND_EXPR to the prequeue and use the temp in its place. */
2372 gimplify_stmt (&expr
);
2373 append_to_statement_list (expr
, pre_p
);
2379 /* Make sure the condition has BOOLEAN_TYPE. */
2380 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
2382 /* Break apart && and || conditions. */
2383 if (TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ANDIF_EXPR
2384 || TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ORIF_EXPR
)
2386 expr
= shortcut_cond_expr (expr
);
2388 if (expr
!= *expr_p
)
2392 /* We can't rely on gimplify_expr to re-gimplify the expanded
2393 form properly, as cleanups might cause the target labels to be
2394 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to
2395 set up a conditional context. */
2396 gimple_push_condition ();
2397 gimplify_stmt (expr_p
);
2398 gimple_pop_condition (pre_p
);
2404 /* Now do the normal gimplification. */
2405 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, NULL
,
2406 is_gimple_condexpr
, fb_rvalue
);
2408 gimple_push_condition ();
2410 gimplify_to_stmt_list (&TREE_OPERAND (expr
, 1));
2411 gimplify_to_stmt_list (&TREE_OPERAND (expr
, 2));
2412 recalculate_side_effects (expr
);
2414 gimple_pop_condition (pre_p
);
2416 if (ret
== GS_ERROR
)
2418 else if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
2420 else if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 2)))
2421 /* Rewrite "if (a); else b" to "if (!a) b" */
2423 TREE_OPERAND (expr
, 0) = invert_truthvalue (TREE_OPERAND (expr
, 0));
2424 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, NULL
,
2425 is_gimple_condexpr
, fb_rvalue
);
2427 tmp
= TREE_OPERAND (expr
, 1);
2428 TREE_OPERAND (expr
, 1) = TREE_OPERAND (expr
, 2);
2429 TREE_OPERAND (expr
, 2) = tmp
;
2432 /* Both arms are empty; replace the COND_EXPR with its predicate. */
2433 expr
= TREE_OPERAND (expr
, 0);
2439 /* Gimplify the MODIFY_EXPR node pointed by EXPR_P.
2445 PRE_P points to the list where side effects that must happen before
2446 *EXPR_P should be stored.
2448 POST_P points to the list where side effects that must happen after
2449 *EXPR_P should be stored.
2451 WANT_VALUE is nonzero iff we want to use the value of this expression
2452 in another expression. */
2454 static enum gimplify_status
2455 gimplify_modify_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
, bool want_value
)
2457 tree
*from_p
= &TREE_OPERAND (*expr_p
, 1);
2458 tree
*to_p
= &TREE_OPERAND (*expr_p
, 0);
2459 enum gimplify_status ret
;
2461 #if defined ENABLE_CHECKING
2462 if (TREE_CODE (*expr_p
) != MODIFY_EXPR
&& TREE_CODE (*expr_p
) != INIT_EXPR
)
2466 /* The distinction between MODIFY_EXPR and INIT_EXPR is no longer useful. */
2467 if (TREE_CODE (*expr_p
) == INIT_EXPR
)
2468 TREE_SET_CODE (*expr_p
, MODIFY_EXPR
);
2470 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
2471 if (ret
== GS_ERROR
)
2474 /* If we are initializing something from a TARGET_EXPR, strip the
2475 TARGET_EXPR and initialize it directly, if possible. This can't
2476 be done if the initializer is void, since that implies that the
2477 temporary is set in some non-trivial way. */
2478 /* What about code that pulls out the temp and uses it elsewhere? I
2479 think that such code never uses the TARGET_EXPR as an initializer. If
2480 I'm wrong, we'll abort because the temp won't have any RTL. In that
2481 case, I guess we'll need to replace references somehow. */
2482 if (TREE_CODE (*from_p
) == TARGET_EXPR
)
2484 tree init
= TARGET_EXPR_INITIAL (*from_p
);
2485 if (!VOID_TYPE_P (TREE_TYPE (init
)))
2489 /* If we're assigning from a ?: expression with ADDRESSABLE type, push
2490 the assignment down into the branches, since we can't generate a
2491 temporary of such a type. */
2492 if (TREE_CODE (*from_p
) == COND_EXPR
2493 && TREE_ADDRESSABLE (TREE_TYPE (*from_p
)))
2496 return gimplify_cond_expr (expr_p
, pre_p
, *to_p
);
2499 ret
= gimplify_expr (from_p
, pre_p
, post_p
, is_gimple_rhs
, fb_rvalue
);
2500 if (ret
== GS_ERROR
)
2503 ret
= gimplify_init_constructor (expr_p
, pre_p
, post_p
, want_value
);
2504 if (ret
!= GS_UNHANDLED
)
2507 /* If the destination is already simple, nothing else needed. */
2508 if (is_gimple_tmp_var (*to_p
))
2512 /* If the RHS of the MODIFY_EXPR may throw or make a nonlocal goto and
2513 the LHS is a user variable, then we need to introduce a temporary.
2514 ie temp = RHS; LHS = temp.
2516 This way the optimizers can determine that the user variable is
2517 only modified if evaluation of the RHS does not throw.
2519 FIXME this should be handled by the is_gimple_rhs predicate. */
2521 if (aggregate_value_p (TREE_TYPE (*from_p
), NULL_TREE
))
2522 /* Don't force a temp of a large aggregate type; the copy could be
2523 arbitrarily expensive. Instead we will generate a V_MAY_DEF for
2525 else if (TREE_CODE (*from_p
) == CALL_EXPR
2526 || (flag_non_call_exceptions
&& tree_could_trap_p (*from_p
))
2527 /* If we're dealing with a renamable type, either source or dest
2528 must be a renamed variable. */
2529 || (is_gimple_reg_type (TREE_TYPE (*from_p
))
2530 && !is_gimple_reg (*to_p
)))
2531 gimplify_expr (from_p
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
2533 /* If the value being copied is of variable width, expose the length
2534 if the copy by converting the whole thing to a memcpy. */
2535 /* ??? Except that we can't manage this with VA_ARG_EXPR. Yes, this
2536 does leave us with an edge condition that doesn't work. The only
2537 way out is to rearrange how VA_ARG_EXPR works. */
2538 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p
))) != INTEGER_CST
2539 && TREE_CODE (*from_p
) != VA_ARG_EXPR
)
2543 t
= TYPE_SIZE_UNIT (TREE_TYPE (*to_p
));
2544 t
= unshare_expr (t
);
2545 args
= tree_cons (NULL
, t
, NULL
);
2546 t
= build_fold_addr_expr (*from_p
);
2547 args
= tree_cons (NULL
, t
, args
);
2548 dest
= build_fold_addr_expr (*to_p
);
2549 args
= tree_cons (NULL
, dest
, args
);
2550 t
= implicit_built_in_decls
[BUILT_IN_MEMCPY
];
2551 t
= build_function_call_expr (t
, args
);
2554 t
= build1 (NOP_EXPR
, TREE_TYPE (dest
), t
);
2555 t
= build1 (INDIRECT_REF
, TREE_TYPE (*to_p
), t
);
2562 ret
= want_value
? GS_OK
: GS_ALL_DONE
;
2567 append_to_statement_list (*expr_p
, pre_p
);
2574 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P
2575 points to the expression to gimplify.
2577 Expressions of the form 'a && b' are gimplified to:
2579 a && b ? true : false
2581 gimplify_cond_expr will do the rest.
2583 PRE_P points to the list where side effects that must happen before
2584 *EXPR_P should be stored. */
2586 static enum gimplify_status
2587 gimplify_boolean_expr (tree
*expr_p
)
2589 /* Preserve the original type of the expression. */
2590 tree type
= TREE_TYPE (*expr_p
);
2592 *expr_p
= build (COND_EXPR
, type
, *expr_p
,
2593 convert (type
, boolean_true_node
),
2594 convert (type
, boolean_false_node
));
2599 /* Gimplifies an expression sequence. This function gimplifies each
2600 expression and re-writes the original expression with the last
2601 expression of the sequence in GIMPLE form.
2603 PRE_P points to the list where the side effects for all the
2604 expressions in the sequence will be emitted.
2606 WANT_VALUE is true when the result of the last COMPOUND_EXPR is used. */
2607 /* ??? Should rearrange to share the pre-queue with all the indirect
2608 invocations of gimplify_expr. Would probably save on creations
2609 of statement_list nodes. */
2611 static enum gimplify_status
2612 gimplify_compound_expr (tree
*expr_p
, tree
*pre_p
, bool want_value
)
2618 tree
*sub_p
= &TREE_OPERAND (t
, 0);
2620 if (TREE_CODE (*sub_p
) == COMPOUND_EXPR
)
2621 gimplify_compound_expr (sub_p
, pre_p
, false);
2623 gimplify_stmt (sub_p
);
2624 append_to_statement_list (*sub_p
, pre_p
);
2626 t
= TREE_OPERAND (t
, 1);
2628 while (TREE_CODE (t
) == COMPOUND_EXPR
);
2635 gimplify_stmt (expr_p
);
2640 /* Gimplifies a statement list. These may be created either by an
2641 enlightened front-end, or by shortcut_cond_expr. */
2643 static enum gimplify_status
2644 gimplify_statement_list (tree
*expr_p
)
2646 tree_stmt_iterator i
= tsi_start (*expr_p
);
2648 while (!tsi_end_p (i
))
2652 gimplify_stmt (tsi_stmt_ptr (i
));
2655 if (TREE_CODE (t
) == STATEMENT_LIST
)
2657 tsi_link_before (&i
, t
, TSI_SAME_STMT
);
2667 /* Gimplify a SAVE_EXPR node. EXPR_P points to the expression to
2668 gimplify. After gimplification, EXPR_P will point to a new temporary
2669 that holds the original value of the SAVE_EXPR node.
2671 PRE_P points to the list where side effects that must happen before
2672 *EXPR_P should be stored. */
2674 static enum gimplify_status
2675 gimplify_save_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
2677 enum gimplify_status ret
= GS_ALL_DONE
;
2680 #if defined ENABLE_CHECKING
2681 if (TREE_CODE (*expr_p
) != SAVE_EXPR
)
2685 val
= TREE_OPERAND (*expr_p
, 0);
2687 /* If the operand is already a GIMPLE temporary, just re-write the
2689 if (is_gimple_tmp_var (val
))
2691 /* The operand may be a void-valued expression such as SAVE_EXPRs
2692 generated by the Java frontend for class initialization. It is
2693 being executed only for its side-effects. */
2694 else if (TREE_TYPE (val
) == void_type_node
)
2696 tree body
= TREE_OPERAND (*expr_p
, 0);
2697 ret
= gimplify_expr (& body
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
2698 append_to_statement_list (body
, pre_p
);
2699 *expr_p
= build_empty_stmt ();
2702 *expr_p
= TREE_OPERAND (*expr_p
, 0)
2703 = get_initialized_tmp_var (val
, pre_p
, post_p
);
2708 /* Re-write the ADDR_EXPR node pointed by EXPR_P
2715 PRE_P points to the list where side effects that must happen before
2716 *EXPR_P should be stored.
2718 POST_P points to the list where side effects that must happen after
2719 *EXPR_P should be stored. */
2721 static enum gimplify_status
2722 gimplify_addr_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
2724 tree expr
= *expr_p
;
2725 tree op0
= TREE_OPERAND (expr
, 0);
2726 enum gimplify_status ret
;
2728 switch (TREE_CODE (op0
))
2731 /* Check if we are dealing with an expression of the form '&*ptr'.
2732 While the front end folds away '&*ptr' into 'ptr', these
2733 expressions may be generated internally by the compiler (e.g.,
2734 builtins like __builtin_va_end). */
2735 *expr_p
= TREE_OPERAND (op0
, 0);
2740 /* Fold &a[6] to (&a + 6). */
2741 ret
= gimplify_array_ref_to_plus (&TREE_OPERAND (expr
, 0),
2744 /* This added an INDIRECT_REF. Fold it away. */
2745 op0
= TREE_OPERAND (TREE_OPERAND (expr
, 0), 0);
2751 /* We use fb_either here because the C frontend sometimes takes
2752 the address of a call that returns a struct. */
2753 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, post_p
,
2754 is_gimple_addr_expr_arg
, fb_either
);
2755 if (ret
!= GS_ERROR
)
2757 /* At this point, the argument of the ADDR_EXPR should be
2758 sufficiently simple that there are never side effects. */
2759 /* ??? Could split out the decision code from build1 to verify. */
2760 TREE_SIDE_EFFECTS (expr
) = 0;
2762 /* Make sure TREE_INVARIANT/TREE_CONSTANT is set properly. */
2763 recompute_tree_invarant_for_addr_expr (expr
);
2765 /* Mark the RHS addressable. */
2766 lang_hooks
.mark_addressable (TREE_OPERAND (expr
, 0));
2771 /* If the operand is gimplified into a _DECL, mark the address expression
2772 as TREE_INVARIANT. */
2773 if (DECL_P (TREE_OPERAND (expr
, 0)))
2774 TREE_INVARIANT (expr
) = 1;
2779 /* Gimplify the operands of an ASM_EXPR. Input operands should be a gimple
2780 value; output operands should be a gimple lvalue. */
2782 static enum gimplify_status
2783 gimplify_asm_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
2785 tree expr
= *expr_p
;
2786 int noutputs
= list_length (ASM_OUTPUTS (expr
));
2787 const char **oconstraints
2788 = (const char **) alloca ((noutputs
) * sizeof (const char *));
2791 const char *constraint
;
2792 bool allows_mem
, allows_reg
, is_inout
;
2793 enum gimplify_status ret
, tret
;
2796 = resolve_asm_operand_names (ASM_STRING (expr
), ASM_OUTPUTS (expr
),
2800 for (i
= 0, link
= ASM_OUTPUTS (expr
); link
; ++i
, link
= TREE_CHAIN (link
))
2802 oconstraints
[i
] = constraint
2803 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
2805 parse_output_constraint (&constraint
, i
, 0, 0,
2806 &allows_mem
, &allows_reg
, &is_inout
);
2808 if (!allows_reg
&& allows_mem
)
2809 lang_hooks
.mark_addressable (TREE_VALUE (link
));
2811 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
2812 is_inout
? is_gimple_min_lval
: is_gimple_lvalue
,
2813 fb_lvalue
| fb_mayfail
);
2814 if (tret
== GS_ERROR
)
2816 error ("invalid lvalue in asm output %d", i
);
2822 /* An input/output operand. To give the optimizers more
2823 flexibility, split it into separate input and output
2827 size_t constraint_len
= strlen (constraint
);
2829 /* Turn the in/out constraint into an output constraint. */
2830 char *p
= xstrdup (constraint
);
2832 TREE_VALUE (TREE_PURPOSE (link
)) = build_string (constraint_len
, p
);
2835 /* And add a matching input constraint. */
2838 sprintf (buf
, "%d", i
);
2839 input
= build_string (strlen (buf
), buf
);
2842 input
= build_string (constraint_len
- 1, constraint
+ 1);
2843 input
= build_tree_list (build_tree_list (NULL_TREE
, input
),
2844 unshare_expr (TREE_VALUE (link
)));
2845 ASM_INPUTS (expr
) = chainon (ASM_INPUTS (expr
), input
);
2849 for (link
= ASM_INPUTS (expr
); link
; ++i
, link
= TREE_CHAIN (link
))
2852 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
2853 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
2854 oconstraints
, &allows_mem
, &allows_reg
);
2856 /* If the operand is a memory input, it should be an lvalue. */
2857 if (!allows_reg
&& allows_mem
)
2859 lang_hooks
.mark_addressable (TREE_VALUE (link
));
2860 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
2861 is_gimple_lvalue
, fb_lvalue
| fb_mayfail
);
2862 if (tret
== GS_ERROR
)
2864 error ("memory input %d is not directly addressable", i
);
2870 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
2871 is_gimple_val
, fb_rvalue
);
2872 if (tret
== GS_ERROR
)
2880 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding
2881 WITH_CLEANUP_EXPRs to the prequeue as we encounter cleanups while
2882 gimplifying the body, and converting them to TRY_FINALLY_EXPRs when we
2883 return to this function.
2885 FIXME should we complexify the prequeue handling instead? Or use flags
2886 for all the cleanups and let the optimizer tighten them up? The current
2887 code seems pretty fragile; it will break on a cleanup within any
2888 non-conditional nesting. But any such nesting would be broken, anyway;
2889 we can't write a TRY_FINALLY_EXPR that starts inside a nesting construct
2890 and continues out of it. We can do that at the RTL level, though, so
2891 having an optimizer to tighten up try/finally regions would be a Good
2894 static enum gimplify_status
2895 gimplify_cleanup_point_expr (tree
*expr_p
, tree
*pre_p
)
2897 tree_stmt_iterator iter
;
2900 tree temp
= voidify_wrapper_expr (*expr_p
, NULL
);
2902 /* We only care about the number of conditions between the innermost
2903 CLEANUP_POINT_EXPR and the cleanup. So save and reset the count. */
2904 int old_conds
= gimplify_ctxp
->conditions
;
2905 gimplify_ctxp
->conditions
= 0;
2907 body
= TREE_OPERAND (*expr_p
, 0);
2908 gimplify_to_stmt_list (&body
);
2910 gimplify_ctxp
->conditions
= old_conds
;
2912 for (iter
= tsi_start (body
); !tsi_end_p (iter
); )
2914 tree
*wce_p
= tsi_stmt_ptr (iter
);
2917 if (TREE_CODE (wce
) == WITH_CLEANUP_EXPR
)
2919 if (tsi_one_before_end_p (iter
))
2921 tsi_link_before (&iter
, TREE_OPERAND (wce
, 1), TSI_SAME_STMT
);
2929 sl
= tsi_split_statement_list_after (&iter
);
2930 tfe
= build (TRY_FINALLY_EXPR
, void_type_node
, sl
, NULL_TREE
);
2931 append_to_statement_list (TREE_OPERAND (wce
, 1),
2932 &TREE_OPERAND (tfe
, 1));
2934 iter
= tsi_start (sl
);
2944 append_to_statement_list (body
, pre_p
);
2954 /* Insert a cleanup marker for gimplify_cleanup_point_expr. CLEANUP
2955 is the cleanup action required. */
2958 gimple_push_cleanup (tree var
, tree cleanup
, tree
*pre_p
)
2962 /* Errors can result in improperly nested cleanups. Which results in
2963 confusion when trying to resolve the WITH_CLEANUP_EXPR. */
2964 if (errorcount
|| sorrycount
)
2967 if (gimple_conditional_context ())
2969 /* If we're in a conditional context, this is more complex. We only
2970 want to run the cleanup if we actually ran the initialization that
2971 necessitates it, but we want to run it after the end of the
2972 conditional context. So we wrap the try/finally around the
2973 condition and use a flag to determine whether or not to actually
2974 run the destructor. Thus
2978 becomes (approximately)
2982 if (test) { A::A(temp); flag = 1; val = f(temp); }
2985 if (flag) A::~A(temp);
2990 tree flag
= create_tmp_var (boolean_type_node
, "cleanup");
2991 tree ffalse
= build (MODIFY_EXPR
, void_type_node
, flag
,
2992 boolean_false_node
);
2993 tree ftrue
= build (MODIFY_EXPR
, void_type_node
, flag
,
2995 cleanup
= build (COND_EXPR
, void_type_node
, flag
, cleanup
,
2996 build_empty_stmt ());
2997 wce
= build (WITH_CLEANUP_EXPR
, void_type_node
, NULL_TREE
,
2998 cleanup
, NULL_TREE
);
2999 append_to_statement_list (ffalse
, &gimplify_ctxp
->conditional_cleanups
);
3000 append_to_statement_list (wce
, &gimplify_ctxp
->conditional_cleanups
);
3001 append_to_statement_list (ftrue
, pre_p
);
3003 /* Because of this manipulation, and the EH edges that jump
3004 threading cannot redirect, the temporary (VAR) will appear
3005 to be used uninitialized. Don't warn. */
3006 TREE_NO_WARNING (var
) = 1;
3010 wce
= build (WITH_CLEANUP_EXPR
, void_type_node
, NULL_TREE
,
3011 cleanup
, NULL_TREE
);
3012 append_to_statement_list (wce
, pre_p
);
3015 gimplify_stmt (&TREE_OPERAND (wce
, 1));
3018 /* Gimplify a TARGET_EXPR which doesn't appear on the rhs of an INIT_EXPR. */
3020 static enum gimplify_status
3021 gimplify_target_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
)
3023 tree targ
= *expr_p
;
3024 tree temp
= TARGET_EXPR_SLOT (targ
);
3025 tree init
= TARGET_EXPR_INITIAL (targ
);
3026 enum gimplify_status ret
;
3030 /* TARGET_EXPR temps aren't part of the enclosing block, so add it
3031 to the temps list. */
3032 gimple_add_tmp_var (temp
);
3034 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
3035 expression is supposed to initialize the slot. */
3036 if (VOID_TYPE_P (TREE_TYPE (init
)))
3037 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
3040 /* Special handling for BIND_EXPR can result in fewer temps. */
3042 if (TREE_CODE (init
) == BIND_EXPR
)
3043 gimplify_bind_expr (&init
, temp
, pre_p
);
3046 init
= build (MODIFY_EXPR
, void_type_node
, temp
, init
);
3047 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
,
3051 if (ret
== GS_ERROR
)
3053 append_to_statement_list (init
, pre_p
);
3055 /* If needed, push the cleanup for the temp. */
3056 if (TARGET_EXPR_CLEANUP (targ
))
3058 gimplify_stmt (&TARGET_EXPR_CLEANUP (targ
));
3059 gimple_push_cleanup (temp
, TARGET_EXPR_CLEANUP (targ
), pre_p
);
3062 /* Only expand this once. */
3063 TREE_OPERAND (targ
, 3) = init
;
3064 TARGET_EXPR_INITIAL (targ
) = NULL_TREE
;
3066 else if (!temp
->decl
.seen_in_bind_expr
)
3067 /* We should have expanded this before. */
3074 /* Gimplification of expression trees. */
3076 /* Gimplify an expression which appears at statement context; usually, this
3077 means replacing it with a suitably gimple STATEMENT_LIST. */
3080 gimplify_stmt (tree
*stmt_p
)
3082 gimplify_expr (stmt_p
, NULL
, NULL
, is_gimple_stmt
, fb_none
);
3084 *stmt_p
= alloc_stmt_list ();
3087 /* Similarly, but force the result to be a STATEMENT_LIST. */
3090 gimplify_to_stmt_list (tree
*stmt_p
)
3092 gimplify_stmt (stmt_p
);
3093 if (TREE_CODE (*stmt_p
) != STATEMENT_LIST
)
3096 *stmt_p
= alloc_stmt_list ();
3097 append_to_statement_list (t
, stmt_p
);
3102 /* Gimplifies the expression tree pointed by EXPR_P. Return 0 if
3103 gimplification failed.
3105 PRE_P points to the list where side effects that must happen before
3106 EXPR should be stored.
3108 POST_P points to the list where side effects that must happen after
3109 EXPR should be stored, or NULL if there is no suitable list. In
3110 that case, we copy the result to a temporary, emit the
3111 post-effects, and then return the temporary.
3113 GIMPLE_TEST_F points to a function that takes a tree T and
3114 returns nonzero if T is in the GIMPLE form requested by the
3115 caller. The GIMPLE predicates are in tree-gimple.c.
3117 This test is used twice. Before gimplification, the test is
3118 invoked to determine whether *EXPR_P is already gimple enough. If
3119 that fails, *EXPR_P is gimplified according to its code and
3120 GIMPLE_TEST_F is called again. If the test still fails, then a new
3121 temporary variable is created and assigned the value of the
3122 gimplified expression.
3124 FALLBACK tells the function what sort of a temporary we want. If the 1
3125 bit is set, an rvalue is OK. If the 2 bit is set, an lvalue is OK.
3126 If both are set, either is OK, but an lvalue is preferable.
3128 The return value is either GS_ERROR or GS_ALL_DONE, since this function
3129 iterates until solution. */
3131 enum gimplify_status
3132 gimplify_expr (tree
*expr_p
, tree
*pre_p
, tree
*post_p
,
3133 bool (* gimple_test_f
) (tree
), fallback_t fallback
)
3136 tree internal_pre
= NULL_TREE
;
3137 tree internal_post
= NULL_TREE
;
3139 int is_statement
= (pre_p
== NULL
);
3141 location_t saved_location
;
3142 enum gimplify_status ret
;
3144 save_expr
= *expr_p
;
3145 if (save_expr
== NULL_TREE
)
3148 /* We used to check the predicate here and return immediately if it
3149 succeeds. This is wrong; the design is for gimplification to be
3150 idempotent, and for the predicates to only test for valid forms, not
3151 whether they are fully simplified. */
3153 /* Set up our internal queues if needed. */
3155 pre_p
= &internal_pre
;
3157 post_p
= &internal_post
;
3159 saved_location
= input_location
;
3160 if (save_expr
== error_mark_node
)
3163 locus
= EXPR_LOCUS (save_expr
);
3165 input_location
= *locus
;
3167 /* Loop over the specific gimplifiers until the toplevel node
3168 remains the same. */
3171 /* Strip any uselessness. */
3172 STRIP_MAIN_TYPE_NOPS (*expr_p
);
3174 /* Remember the expr. */
3175 save_expr
= *expr_p
;
3177 /* Die, die, die, my darling. */
3178 if (save_expr
== error_mark_node
3179 || TREE_TYPE (save_expr
) == error_mark_node
)
3185 /* Do any language-specific gimplification. */
3186 ret
= lang_hooks
.gimplify_expr (expr_p
, pre_p
, post_p
);
3189 if (*expr_p
== NULL_TREE
)
3191 if (*expr_p
!= save_expr
)
3194 else if (ret
!= GS_UNHANDLED
)
3198 switch (TREE_CODE (*expr_p
))
3200 /* First deal with the special cases. */
3202 case POSTINCREMENT_EXPR
:
3203 case POSTDECREMENT_EXPR
:
3204 case PREINCREMENT_EXPR
:
3205 case PREDECREMENT_EXPR
:
3206 ret
= gimplify_self_mod_expr (expr_p
, pre_p
, post_p
,
3207 fallback
!= fb_none
);
3211 ret
= gimplify_array_ref (expr_p
, pre_p
, post_p
,
3212 fallback
& fb_lvalue
);
3216 ret
= gimplify_compound_lval (expr_p
, pre_p
, post_p
,
3217 fallback
& fb_lvalue
);
3221 ret
= gimplify_cond_expr (expr_p
, pre_p
, NULL_TREE
);
3225 ret
= gimplify_call_expr (expr_p
, pre_p
, gimple_test_f
);
3232 ret
= gimplify_compound_expr (expr_p
, pre_p
, fallback
!= fb_none
);
3237 ret
= gimplify_compound_lval (expr_p
, pre_p
, post_p
,
3238 fallback
& fb_lvalue
);
3243 ret
= gimplify_modify_expr (expr_p
, pre_p
, post_p
,
3244 fallback
!= fb_none
);
3247 case TRUTH_ANDIF_EXPR
:
3248 case TRUTH_ORIF_EXPR
:
3249 ret
= gimplify_boolean_expr (expr_p
);
3252 case TRUTH_NOT_EXPR
:
3253 TREE_OPERAND (*expr_p
, 0)
3254 = gimple_boolify (TREE_OPERAND (*expr_p
, 0));
3255 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
3256 is_gimple_val
, fb_rvalue
);
3257 recalculate_side_effects (*expr_p
);
3261 ret
= gimplify_addr_expr (expr_p
, pre_p
, post_p
);
3265 ret
= gimplify_va_arg_expr (expr_p
, pre_p
, post_p
);
3270 if (IS_EMPTY_STMT (*expr_p
))
3276 if (VOID_TYPE_P (TREE_TYPE (*expr_p
))
3277 || fallback
== fb_none
)
3279 /* Just strip a conversion to void (or in void context) and
3281 *expr_p
= TREE_OPERAND (*expr_p
, 0);
3285 ret
= gimplify_conversion (expr_p
);
3286 if (ret
== GS_ERROR
)
3288 if (*expr_p
!= save_expr
)
3292 case FIX_TRUNC_EXPR
:
3294 case FIX_FLOOR_EXPR
:
3295 case FIX_ROUND_EXPR
:
3296 /* unary_expr: ... | '(' cast ')' val | ... */
3297 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
3298 is_gimple_val
, fb_rvalue
);
3299 recalculate_side_effects (*expr_p
);
3303 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
3304 is_gimple_reg
, fb_rvalue
);
3305 recalculate_side_effects (*expr_p
);
3308 /* Constants need not be gimplified. */
3318 *expr_p
= DECL_INITIAL (*expr_p
);
3322 /* FIXME make this a decl. */
3327 ret
= gimplify_bind_expr (expr_p
, NULL
, pre_p
);
3331 ret
= gimplify_loop_expr (expr_p
, pre_p
);
3335 ret
= gimplify_switch_expr (expr_p
, pre_p
);
3338 case LABELED_BLOCK_EXPR
:
3339 ret
= gimplify_labeled_block_expr (expr_p
);
3342 case EXIT_BLOCK_EXPR
:
3343 ret
= gimplify_exit_block_expr (expr_p
);
3347 ret
= gimplify_exit_expr (expr_p
);
3351 /* If the target is not LABEL, then it is a computed jump
3352 and the target needs to be gimplified. */
3353 if (TREE_CODE (GOTO_DESTINATION (*expr_p
)) != LABEL_DECL
)
3354 ret
= gimplify_expr (&GOTO_DESTINATION (*expr_p
), pre_p
,
3355 NULL
, is_gimple_val
, fb_rvalue
);
3360 #ifdef ENABLE_CHECKING
3361 if (decl_function_context (LABEL_EXPR_LABEL (*expr_p
)) != current_function_decl
)
3366 case CASE_LABEL_EXPR
:
3367 ret
= gimplify_case_label_expr (expr_p
);
3371 ret
= gimplify_return_expr (*expr_p
, pre_p
);
3375 /* Don't reduce this in place; let gimplify_init_constructor work
3380 /* The following are special cases that are not handled by the
3381 original GIMPLE grammar. */
3383 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
3386 ret
= gimplify_save_expr (expr_p
, pre_p
, post_p
);
3391 enum gimplify_status r0
, r1
, r2
;
3393 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
3394 is_gimple_min_lval
, fb_either
);
3395 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
3396 is_gimple_val
, fb_rvalue
);
3397 r2
= gimplify_expr (&TREE_OPERAND (*expr_p
, 2), pre_p
, post_p
,
3398 is_gimple_val
, fb_rvalue
);
3399 recalculate_side_effects (*expr_p
);
3401 ret
= MIN (r0
, MIN (r1
, r2
));
3405 case NON_LVALUE_EXPR
:
3406 /* This should have been stripped above. */
3411 ret
= gimplify_asm_expr (expr_p
, pre_p
, post_p
);
3414 case TRY_FINALLY_EXPR
:
3415 case TRY_CATCH_EXPR
:
3416 gimplify_to_stmt_list (&TREE_OPERAND (*expr_p
, 0));
3417 gimplify_to_stmt_list (&TREE_OPERAND (*expr_p
, 1));
3421 case CLEANUP_POINT_EXPR
:
3422 ret
= gimplify_cleanup_point_expr (expr_p
, pre_p
);
3426 ret
= gimplify_target_expr (expr_p
, pre_p
, post_p
);
3430 gimplify_to_stmt_list (&CATCH_BODY (*expr_p
));
3434 case EH_FILTER_EXPR
:
3435 gimplify_to_stmt_list (&EH_FILTER_FAILURE (*expr_p
));
3440 /* This moves much of the actual computation out of the
3441 VTABLE_REF. Perhaps this should be revisited once we want to
3442 do clever things with VTABLE_REFs. */
3443 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
3444 is_gimple_min_lval
, fb_lvalue
);
3449 ret
= gimplify_minimax_expr (expr_p
, pre_p
, post_p
);
3453 /* We get here when taking the address of a label. We mark
3454 the label as "forced"; meaning it can never be removed and
3455 it is a potential target for any computed goto. */
3456 FORCED_LABEL (*expr_p
) = 1;
3460 case STATEMENT_LIST
:
3461 ret
= gimplify_statement_list (expr_p
);
3465 /* ??? If this is a local variable, and it has not been seen in any
3466 outer BIND_EXPR, then it's probably the result of a duplicate
3467 declaration, for which we've already issued an error. It would
3468 be really nice if the front end wouldn't leak these at all.
3469 Currently the only known culprit is C++ destructors, as seen
3470 in g++.old-deja/g++.jason/binding.C. */
3472 if (!TREE_STATIC (tmp
) && !DECL_EXTERNAL (tmp
)
3473 && decl_function_context (tmp
) == current_function_decl
3474 && !tmp
->decl
.seen_in_bind_expr
)
3476 #ifdef ENABLE_CHECKING
3477 if (!errorcount
&& !sorrycount
)
3487 /* If *EXPR_P does not need to be special-cased, handle it
3488 according to its class. */
3489 if (TREE_CODE_CLASS (TREE_CODE (*expr_p
)) == '1')
3490 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
3491 post_p
, is_gimple_val
, fb_rvalue
);
3492 else if (TREE_CODE_CLASS (TREE_CODE (*expr_p
)) == '2'
3493 || TREE_CODE_CLASS (TREE_CODE (*expr_p
)) == '<'
3494 || TREE_CODE (*expr_p
) == TRUTH_AND_EXPR
3495 || TREE_CODE (*expr_p
) == TRUTH_OR_EXPR
3496 || TREE_CODE (*expr_p
) == TRUTH_XOR_EXPR
)
3498 enum gimplify_status r0
, r1
;
3500 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
3501 post_p
, is_gimple_val
, fb_rvalue
);
3502 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
3503 post_p
, is_gimple_val
, fb_rvalue
);
3507 else if (TREE_CODE_CLASS (TREE_CODE (*expr_p
)) == 'd'
3508 || TREE_CODE_CLASS (TREE_CODE (*expr_p
)) == 'c')
3514 /* Fail if we don't know how to handle this tree code. */
3517 recalculate_side_effects (*expr_p
);
3521 /* If we replaced *expr_p, gimplify again. */
3522 if (ret
== GS_OK
&& (*expr_p
== NULL
|| *expr_p
== save_expr
))
3525 while (ret
== GS_OK
);
3527 /* If we encountered an error_mark somewhere nested inside, either
3528 stub out the statement or propagate the error back out. */
3529 if (ret
== GS_ERROR
)
3532 *expr_p
= build_empty_stmt ();
3536 #ifdef ENABLE_CHECKING
3537 /* This was only valid as a return value from the langhook, which
3538 we handled. Make sure it doesn't escape from any other context. */
3539 if (ret
== GS_UNHANDLED
)
3544 *expr_p
= build_empty_stmt ();
3545 if (fallback
== fb_none
&& !is_gimple_stmt (*expr_p
))
3547 /* We aren't looking for a value, and we don't have a valid
3548 statement. If it doesn't have side-effects, throw it away. */
3549 if (!TREE_SIDE_EFFECTS (*expr_p
))
3550 *expr_p
= build_empty_stmt ();
3551 else if (!TREE_THIS_VOLATILE (*expr_p
))
3552 /* We only handle volatiles here; anything else with side-effects
3553 must be converted to a valid statement before we get here. */
3555 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p
)))
3557 /* Historically, the compiler has treated a bare
3558 reference to a volatile lvalue as forcing a load. */
3559 tree tmp
= create_tmp_var (TREE_TYPE (*expr_p
), "vol");
3560 *expr_p
= build (MODIFY_EXPR
, TREE_TYPE (tmp
), tmp
, *expr_p
);
3563 /* We can't do anything useful with a volatile reference to
3564 incomplete type, so just throw it away. */
3565 *expr_p
= build_empty_stmt ();
3568 /* If we are gimplifying at the statement level, we're done. Tack
3569 everything together and replace the original statement with the
3571 if (fallback
== fb_none
|| is_statement
)
3573 if (internal_pre
|| internal_post
)
3575 append_to_statement_list (*expr_p
, &internal_pre
);
3576 append_to_statement_list (internal_post
, &internal_pre
);
3577 annotate_all_with_locus (&internal_pre
, input_location
);
3578 *expr_p
= internal_pre
;
3580 else if (TREE_CODE (*expr_p
) == STATEMENT_LIST
)
3581 annotate_all_with_locus (expr_p
, input_location
);
3583 annotate_one_with_locus (*expr_p
, input_location
);
3587 /* Otherwise we're gimplifying a subexpression, so the resulting value is
3590 /* If it's sufficiently simple already, we're done. Unless we are
3591 handling some post-effects internally; if that's the case, we need to
3592 copy into a temp before adding the post-effects to the tree. */
3593 if (!internal_post
&& (*gimple_test_f
) (*expr_p
))
3596 /* Otherwise, we need to create a new temporary for the gimplified
3599 /* We can't return an lvalue if we have an internal postqueue. The
3600 object the lvalue refers to would (probably) be modified by the
3601 postqueue; we need to copy the value out first, which means an
3603 if ((fallback
& fb_lvalue
) && !internal_post
3604 && is_gimple_addr_expr_arg (*expr_p
))
3606 /* An lvalue will do. Take the address of the expression, store it
3607 in a temporary, and replace the expression with an INDIRECT_REF of
3609 tmp
= build_fold_addr_expr (*expr_p
);
3610 gimplify_expr (&tmp
, pre_p
, post_p
, is_gimple_reg
, fb_rvalue
);
3611 *expr_p
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (tmp
)), tmp
);
3613 else if ((fallback
& fb_rvalue
) && is_gimple_rhs (*expr_p
))
3615 #if defined ENABLE_CHECKING
3616 if (VOID_TYPE_P (TREE_TYPE (*expr_p
)))
3620 /* An rvalue will do. Assign the gimplified expression into a new
3621 temporary TMP and replace the original expression with TMP. */
3623 if (internal_post
|| (fallback
& fb_lvalue
))
3624 /* The postqueue might change the value of the expression between
3625 the initialization and use of the temporary, so we can't use a
3626 formal temp. FIXME do we care? */
3627 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
);
3629 *expr_p
= get_formal_tmp_var (*expr_p
, pre_p
);
3631 else if (fallback
& fb_mayfail
)
3633 /* If this is an asm statement, and the user asked for the impossible,
3634 don't abort. Fail and let gimplify_asm_expr issue an error. */
3640 fprintf (stderr
, "gimplification failed:\n");
3641 print_generic_expr (stderr
, *expr_p
, 0);
3642 debug_tree (*expr_p
);
3646 #if defined ENABLE_CHECKING
3647 /* Make sure the temporary matches our predicate. */
3648 if (!(*gimple_test_f
) (*expr_p
))
3654 annotate_all_with_locus (&internal_post
, input_location
);
3655 append_to_statement_list (internal_post
, pre_p
);
3659 input_location
= saved_location
;
3663 #ifdef ENABLE_CHECKING
3664 /* Compare types A and B for a "close enough" match. */
3667 cpt_same_type (tree a
, tree b
)
3669 if (lang_hooks
.types_compatible_p (a
, b
))
3672 /* ??? The C++ FE decomposes METHOD_TYPES to FUNCTION_TYPES and doesn't
3673 link them together. This routine is intended to catch type errors
3674 that will affect the optimizers, and the optimizers don't add new
3675 dereferences of function pointers, so ignore it. */
3676 if ((TREE_CODE (a
) == FUNCTION_TYPE
|| TREE_CODE (a
) == METHOD_TYPE
)
3677 && (TREE_CODE (b
) == FUNCTION_TYPE
|| TREE_CODE (b
) == METHOD_TYPE
))
3680 /* ??? The C FE pushes type qualifiers after the fact into the type of
3681 the element from the type of the array. See build_unary_op's handling
3682 of ADDR_EXPR. This seems wrong -- if we were going to do this, we
3683 should have done it when creating the variable in the first place.
3684 Alternately, why aren't the two array types made variants? */
3685 if (TREE_CODE (a
) == ARRAY_TYPE
&& TREE_CODE (b
) == ARRAY_TYPE
)
3686 return cpt_same_type (TREE_TYPE (a
), TREE_TYPE (b
));
3688 /* And because of those, we have to recurse down through pointers. */
3689 if (POINTER_TYPE_P (a
) && POINTER_TYPE_P (b
))
3690 return cpt_same_type (TREE_TYPE (a
), TREE_TYPE (b
));
3695 /* Check for some cases of the front end missing cast expressions.
3696 The type of a dereference should correspond to the pointer type;
3697 similarly the type of an address should match its object. */
3700 check_pointer_types_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
3701 void *data ATTRIBUTE_UNUSED
)
3704 tree ptype
, otype
, dtype
;
3706 switch (TREE_CODE (t
))
3710 otype
= TREE_TYPE (t
);
3711 ptype
= TREE_TYPE (TREE_OPERAND (t
, 0));
3712 dtype
= TREE_TYPE (ptype
);
3713 if (!cpt_same_type (otype
, dtype
))
3718 ptype
= TREE_TYPE (t
);
3719 otype
= TREE_TYPE (TREE_OPERAND (t
, 0));
3720 dtype
= TREE_TYPE (ptype
);
3721 if (!cpt_same_type (otype
, dtype
))
3723 /* &array is allowed to produce a pointer to the element,
3724 rather than a pointer to the array type. */
3725 if (TREE_CODE (otype
) == ARRAY_TYPE
3726 && POINTER_TYPE_P (ptype
)
3727 && cpt_same_type (TREE_TYPE (otype
), dtype
))
3742 /* Gimplify the body of statements pointed by BODY_P. FNDECL is the
3743 function decl containing BODY. */
3746 gimplify_body (tree
*body_p
, tree fndecl
)
3748 location_t saved_location
= input_location
;
3751 timevar_push (TV_TREE_GIMPLIFY
);
3752 push_gimplify_context ();
3754 /* Unshare most shared trees in the body. */
3755 unshare_all_trees (*body_p
);
3757 /* Make sure input_location isn't set to something wierd. */
3758 input_location
= DECL_SOURCE_LOCATION (fndecl
);
3760 /* Gimplify the function's body. */
3761 gimplify_stmt (body_p
);
3764 /* Unshare again, in case gimplification was sloppy. */
3765 unshare_all_trees (body
);
3767 /* If there isn't an outer BIND_EXPR, add one. */
3768 if (TREE_CODE (body
) == STATEMENT_LIST
)
3770 tree t
= expr_only (*body_p
);
3774 if (TREE_CODE (body
) != BIND_EXPR
)
3776 tree b
= build (BIND_EXPR
, void_type_node
, NULL_TREE
,
3777 NULL_TREE
, NULL_TREE
);
3778 TREE_SIDE_EFFECTS (b
) = 1;
3779 append_to_statement_list_force (body
, &BIND_EXPR_BODY (b
));
3784 pop_gimplify_context (body
);
3786 #ifdef ENABLE_CHECKING
3787 walk_tree (body_p
, check_pointer_types_r
, NULL
, NULL
);
3790 timevar_pop (TV_TREE_GIMPLIFY
);
3791 input_location
= saved_location
;
3794 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL
3795 node for the function we want to gimplify. */
3798 gimplify_function_tree (tree fndecl
)
3802 oldfn
= current_function_decl
;
3803 current_function_decl
= fndecl
;
3805 gimplify_body (&DECL_SAVED_TREE (fndecl
), fndecl
);
3807 /* If we're instrumenting function entry/exit, then prepend the call to
3808 the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
3809 catch the exit hook. */
3810 /* ??? Add some way to ignore exceptions for this TFE. */
3811 if (flag_instrument_function_entry_exit
3812 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl
))
3816 tf
= build (TRY_FINALLY_EXPR
, void_type_node
, NULL
, NULL
);
3817 TREE_SIDE_EFFECTS (tf
) = 1;
3818 x
= DECL_SAVED_TREE (fndecl
);
3819 append_to_statement_list (x
, &TREE_OPERAND (tf
, 0));
3820 x
= implicit_built_in_decls
[BUILT_IN_PROFILE_FUNC_EXIT
];
3821 x
= build_function_call_expr (x
, NULL
);
3822 append_to_statement_list (x
, &TREE_OPERAND (tf
, 1));
3824 bind
= build (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
3825 TREE_SIDE_EFFECTS (bind
) = 1;
3826 x
= implicit_built_in_decls
[BUILT_IN_PROFILE_FUNC_ENTER
];
3827 x
= build_function_call_expr (x
, NULL
);
3828 append_to_statement_list (x
, &BIND_EXPR_BODY (bind
));
3829 append_to_statement_list (tf
, &BIND_EXPR_BODY (bind
));
3831 DECL_SAVED_TREE (fndecl
) = bind
;
3834 current_function_decl
= oldfn
;
3837 #include "gt-gimplify.h"