1 /* Tree lowering pass. This pass converts the GENERIC functions-as-trees
2 tree representation into the GIMPLE form.
3 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 Major work done by Sebastian Pop <s.pop@laposte.net>,
5 Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "coretypes.h"
32 #include "tree-gimple.h"
33 #include "tree-inline.h"
34 #include "diagnostic.h"
35 #include "langhooks.h"
36 #include "langhooks-def.h"
37 #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 /* Forward declarations. */
75 static enum gimplify_status gimplify_modify_expr_rhs (tree *, tree *, tree *,
76 tree *, tree *, bool);
77 static enum gimplify_status gimplify_compound_expr (tree *, tree *, bool);
80 /* Return a hash value for a formal temporary table entry. */
83 gimple_tree_hash (const void *p)
85 tree t = ((const elt_t *) p)->val;
86 return iterative_hash_expr (t, 0);
89 /* Compare two formal temporary table entries. */
92 gimple_tree_eq (const void *p1, const void *p2)
94 tree t1 = ((const elt_t *) p1)->val;
95 tree t2 = ((const elt_t *) p2)->val;
96 enum tree_code code = TREE_CODE (t1);
98 if (TREE_CODE (t2) != code
99 || TREE_TYPE (t1) != TREE_TYPE (t2))
102 if (!operand_equal_p (t1, t2, 0))
105 /* Only allow them to compare equal if they also hash equal; otherwise
106 results are nondeterminate, and we fail bootstrap comparison. */
107 if (gimple_tree_hash (p1) != gimple_tree_hash (p2))
113 /* Set up a context for the gimplifier. */
116 push_gimplify_context (void)
121 = (struct gimplify_ctx *) xcalloc (1, sizeof (struct gimplify_ctx));
122 gimplify_ctxp->temp_htab
123 = htab_create (1000, gimple_tree_hash, gimple_tree_eq, free);
126 /* Tear down a context for the gimplifier. If BODY is non-null, then
127 put the temporaries into the outer BIND_EXPR. Otherwise, put them
128 in the unexpanded_var_list. */
131 pop_gimplify_context (tree body)
133 if (!gimplify_ctxp || gimplify_ctxp->current_bind_expr)
137 declare_tmp_vars (gimplify_ctxp->temps, body);
139 record_vars (gimplify_ctxp->temps);
143 fprintf (stderr, " collisions: %f ",
144 htab_collisions (gimplify_ctxp->temp_htab));
147 htab_delete (gimplify_ctxp->temp_htab);
148 free (gimplify_ctxp);
149 gimplify_ctxp = NULL;
153 gimple_push_bind_expr (tree bind)
155 TREE_CHAIN (bind) = gimplify_ctxp->current_bind_expr;
156 gimplify_ctxp->current_bind_expr = bind;
160 gimple_pop_bind_expr (void)
162 gimplify_ctxp->current_bind_expr
163 = TREE_CHAIN (gimplify_ctxp->current_bind_expr);
167 gimple_current_bind_expr (void)
169 return gimplify_ctxp->current_bind_expr;
172 /* Returns true iff there is a COND_EXPR between us and the innermost
173 CLEANUP_POINT_EXPR. This info is used by gimple_push_cleanup. */
176 gimple_conditional_context (void)
178 return gimplify_ctxp->conditions > 0;
181 /* Note that we've entered a COND_EXPR. */
184 gimple_push_condition (void)
186 ++(gimplify_ctxp->conditions);
189 /* Note that we've left a COND_EXPR. If we're back at unconditional scope
190 now, add any conditional cleanups we've seen to the prequeue. */
193 gimple_pop_condition (tree *pre_p)
195 int conds = --(gimplify_ctxp->conditions);
199 append_to_statement_list (gimplify_ctxp->conditional_cleanups, pre_p);
200 gimplify_ctxp->conditional_cleanups = NULL_TREE;
206 /* A subroutine of append_to_statement_list{,_force}. */
209 append_to_statement_list_1 (tree t, tree *list_p, bool side_effects)
212 tree_stmt_iterator i;
219 if (t && TREE_CODE (t) == STATEMENT_LIST)
224 *list_p = list = alloc_stmt_list ();
228 tsi_link_after (&i, t, TSI_CONTINUE_LINKING);
231 /* Add T to the end of the list container pointed by LIST_P.
232 If T is an expression with no effects, it is ignored. */
235 append_to_statement_list (tree t, tree *list_p)
237 append_to_statement_list_1 (t, list_p, t ? TREE_SIDE_EFFECTS (t) : false);
240 /* Similar, but the statement is always added, regardless of side effects. */
243 append_to_statement_list_force (tree t, tree *list_p)
245 append_to_statement_list_1 (t, list_p, t != NULL);
248 /* Both gimplify the statement T and append it to LIST_P. */
251 gimplify_and_add (tree t, tree *list_p)
254 append_to_statement_list (t, list_p);
257 /* Strip off a legitimate source ending from the input string NAME of
258 length LEN. Rather than having to know the names used by all of
259 our front ends, we strip off an ending of a period followed by
260 up to five characters. (Java uses ".class".) */
263 remove_suffix (char *name, int len)
267 for (i = 2; i < 8 && len > i; i++)
269 if (name[len - i] == '.')
271 name[len - i] = '\0';
277 /* Create a nameless artificial label and put it in the current function
278 context. Returns the newly created label. */
281 create_artificial_label (void)
283 tree lab = build_decl (LABEL_DECL, NULL_TREE, void_type_node);
285 DECL_ARTIFICIAL (lab) = 1;
286 DECL_CONTEXT (lab) = current_function_decl;
290 /* Create a new temporary name with PREFIX. Returns an identifier. */
292 static GTY(()) unsigned int tmp_var_id_num;
295 create_tmp_var_name (const char *prefix)
301 char *preftmp = ASTRDUP (prefix);
303 remove_suffix (preftmp, strlen (preftmp));
307 ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix ? prefix : "T", tmp_var_id_num++);
308 return get_identifier (tmp_name);
312 /* Create a new temporary variable declaration of type TYPE.
313 Does NOT push it into the current binding. */
316 create_tmp_var_raw (tree type, const char *prefix)
321 /* Make the type of the variable writable. */
322 new_type = build_type_variant (type, 0, 0);
323 TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type);
325 tmp_var = build_decl (VAR_DECL, create_tmp_var_name (prefix), type);
327 /* The variable was declared by the compiler. */
328 DECL_ARTIFICIAL (tmp_var) = 1;
329 /* And we don't want debug info for it. */
330 DECL_IGNORED_P (tmp_var) = 1;
332 /* Make the variable writable. */
333 TREE_READONLY (tmp_var) = 0;
335 DECL_EXTERNAL (tmp_var) = 0;
336 TREE_STATIC (tmp_var) = 0;
337 TREE_USED (tmp_var) = 1;
342 /* Create a new temporary variable declaration of type TYPE. DOES push the
343 variable into the current binding. Further, assume that this is called
344 only from gimplification or optimization, at which point the creation of
345 certain types are bugs. */
348 create_tmp_var (tree type, const char *prefix)
352 #if defined ENABLE_CHECKING
353 /* We don't allow types that are addressable (meaning we can't make copies),
354 incomplete, or of variable size. */
355 if (TREE_ADDRESSABLE (type)
356 || !COMPLETE_TYPE_P (type)
357 || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
361 tmp_var = create_tmp_var_raw (type, prefix);
362 gimple_add_tmp_var (tmp_var);
366 /* Given a tree, try to return a useful variable name that we can use
367 to prefix a temporary that is being assigned the value of the tree.
368 I.E. given <temp> = &A, return A. */
376 STRIP_NOPS (stripped_decl);
377 if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
378 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
381 switch (TREE_CODE (stripped_decl))
384 return get_name (TREE_OPERAND (stripped_decl, 0));
392 /* Create a temporary with a name derived from VAL. Subroutine of
393 lookup_tmp_var; nobody else should call this function. */
396 create_tmp_from_val (tree val)
398 return create_tmp_var (TREE_TYPE (val), get_name (val));
401 /* Create a temporary to hold the value of VAL. If IS_FORMAL, try to reuse
402 an existing expression temporary. */
405 lookup_tmp_var (tree val, bool is_formal)
407 if (!is_formal || TREE_SIDE_EFFECTS (val))
408 return create_tmp_from_val (val);
415 slot = htab_find_slot (gimplify_ctxp->temp_htab, (void *)&elt, INSERT);
418 elt_p = xmalloc (sizeof (*elt_p));
420 elt_p->temp = create_tmp_from_val (val);
421 TREE_READONLY (elt_p->temp) = 1;
422 *slot = (void *) elt_p;
425 elt_p = (elt_t *) *slot;
431 /* Returns a formal temporary variable initialized with VAL. PRE_P is as
432 in gimplify_expr. Only use this function if:
434 1) The value of the unfactored expression represented by VAL will not
435 change between the initialization and use of the temporary, and
436 2) The temporary will not be otherwise modified.
438 For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
439 and #2 means it is inappropriate for && temps.
441 For other cases, use get_initialized_tmp_var instead. */
444 internal_get_tmp_var (tree val, tree *pre_p, tree *post_p, bool is_formal)
449 gimplify_expr (&val, pre_p, post_p, is_gimple_rhs, fb_rvalue);
451 t = lookup_tmp_var (val, is_formal);
453 mod = build (MODIFY_EXPR, TREE_TYPE (t), t, val);
455 class = TREE_CODE_CLASS (TREE_CODE (val));
456 if (EXPR_LOCUS (val))
457 SET_EXPR_LOCUS (mod, EXPR_LOCUS (val));
459 annotate_with_locus (mod, input_location);
461 /* gimplify_modify_expr might want to reduce this further. */
462 gimplify_and_add (mod, pre_p);
467 get_formal_tmp_var (tree val, tree *pre_p)
469 return internal_get_tmp_var (val, pre_p, NULL, true);
472 /* Returns a temporary variable initialized with VAL. PRE_P and POST_P
473 are as in gimplify_expr. */
476 get_initialized_tmp_var (tree val, tree *pre_p, tree *post_p)
478 return internal_get_tmp_var (val, pre_p, post_p, false);
481 /* Returns true if T is a GIMPLE temporary variable, false otherwise. */
484 is_gimple_tmp_var (tree t)
486 /* FIXME this could trigger for other local artificials, too. */
487 return (TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t)
488 && !TREE_STATIC (t) && !DECL_EXTERNAL (t));
491 /* Declares all the variables in VARS in SCOPE. */
494 declare_tmp_vars (tree vars, tree scope)
501 /* C99 mode puts the default 'return 0;' for main outside the outer
502 braces. So drill down until we find an actual scope. */
503 while (TREE_CODE (scope) == COMPOUND_EXPR)
504 scope = TREE_OPERAND (scope, 0);
506 if (TREE_CODE (scope) != BIND_EXPR)
509 temps = nreverse (last);
510 TREE_CHAIN (last) = BIND_EXPR_VARS (scope);
511 BIND_EXPR_VARS (scope) = temps;
513 /* We don't add the temps to the block for this BIND_EXPR, as we're
514 not interested in debugging info for them. */
519 gimple_add_tmp_var (tree tmp)
521 if (TREE_CHAIN (tmp) || tmp->decl.seen_in_bind_expr)
524 DECL_CONTEXT (tmp) = current_function_decl;
525 tmp->decl.seen_in_bind_expr = 1;
529 TREE_CHAIN (tmp) = gimplify_ctxp->temps;
530 gimplify_ctxp->temps = tmp;
535 declare_tmp_vars (tmp, DECL_SAVED_TREE (current_function_decl));
538 /* Determines whether to assign a locus to the statement STMT. */
541 should_carry_locus_p (tree stmt)
543 /* Don't emit a line note for a label. We particularly don't want to
544 emit one for the break label, since it doesn't actually correspond
545 to the beginning of the loop/switch. */
546 if (TREE_CODE (stmt) == LABEL_EXPR)
549 /* Do not annotate empty statements, since it confuses gcov. */
550 if (!TREE_SIDE_EFFECTS (stmt))
557 annotate_one_with_locus (tree t, location_t locus)
559 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t)))
560 && ! EXPR_HAS_LOCATION (t)
561 && should_carry_locus_p (t))
562 annotate_with_locus (t, locus);
566 annotate_all_with_locus (tree *stmt_p, location_t locus)
568 tree_stmt_iterator i;
573 for (i = tsi_start (*stmt_p); !tsi_end_p (i); tsi_next (&i))
575 tree t = tsi_stmt (i);
577 #ifdef ENABLE_CHECKING
578 /* Assuming we've already been gimplified, we shouldn't
579 see nested chaining constructs anymore. */
580 if (TREE_CODE (t) == STATEMENT_LIST
581 || TREE_CODE (t) == COMPOUND_EXPR)
585 annotate_one_with_locus (t, locus);
589 /* Similar to copy_tree_r() but do not copy SAVE_EXPR or TARGET_EXPR nodes.
590 These nodes model computations that should only be done once. If we
591 were to unshare something like SAVE_EXPR(i++), the gimplification
592 process would create wrong code. */
595 mostly_copy_tree_r (tree *tp, int *walk_subtrees, void *data)
597 enum tree_code code = TREE_CODE (*tp);
598 /* Don't unshare types, decls, constants and SAVE_EXPR nodes. */
599 if (TREE_CODE_CLASS (code) == 't'
600 || TREE_CODE_CLASS (code) == 'd'
601 || TREE_CODE_CLASS (code) == 'c'
602 || code == SAVE_EXPR || code == TARGET_EXPR
603 /* We can't do anything sensible with a BLOCK used as an expression,
604 but we also can't abort when we see it because of non-expression
605 uses. So just avert our eyes and cross our fingers. Silly Java. */
608 else if (code == BIND_EXPR)
611 copy_tree_r (tp, walk_subtrees, data);
616 /* Mark all the _DECL nodes under *TP as volatile. FIXME: This must die
617 after VA_ARG_EXPRs are properly lowered. */
620 mark_decls_volatile_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
621 void *data ATTRIBUTE_UNUSED)
624 TREE_THIS_VOLATILE (*tp) = 1;
630 /* Callback for walk_tree to unshare most of the shared trees rooted at
631 *TP. If *TP has been visited already (i.e., TREE_VISITED (*TP) == 1),
632 then *TP is deep copied by calling copy_tree_r.
634 This unshares the same trees as copy_tree_r with the exception of
635 SAVE_EXPR nodes. These nodes model computations that should only be
636 done once. If we were to unshare something like SAVE_EXPR(i++), the
637 gimplification process would create wrong code. */
640 copy_if_shared_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
641 void *data ATTRIBUTE_UNUSED)
644 enum tree_code code = TREE_CODE (t);
646 /* Skip types, decls, and constants. But we do want to look at their
647 types and the bounds of types. Mark them as visited so we properly
648 unmark their subtrees on the unmark pass. If we've already seen them,
649 don't look down further. */
650 if (TREE_CODE_CLASS (code) == 't'
651 || TREE_CODE_CLASS (code) == 'd'
652 || TREE_CODE_CLASS (code) == 'c')
654 if (TREE_VISITED (t))
657 TREE_VISITED (t) = 1;
660 /* Special-case BIND_EXPR. We should never be copying these, therefore
661 we can omit examining BIND_EXPR_VARS. Which also avoids problems with
662 double processing of the DECL_INITIAL, which could be seen via both
663 the BIND_EXPR_VARS and a DECL_STMT. */
664 else if (code == BIND_EXPR)
666 if (TREE_VISITED (t))
668 TREE_VISITED (t) = 1;
670 walk_tree (&BIND_EXPR_BODY (t), copy_if_shared_r, NULL, NULL);
673 /* If this node has been visited already, unshare it and don't look
675 else if (TREE_VISITED (t))
677 walk_tree (tp, mostly_copy_tree_r, NULL, NULL);
681 /* Otherwise, mark the tree as visited and keep looking. */
684 TREE_VISITED (t) = 1;
685 if (TREE_CODE (*tp) == VA_ARG_EXPR
686 && targetm.calls.gimplify_va_arg_expr == NULL)
688 /* Mark any _DECL inside the operand as volatile to avoid
689 the optimizers messing around with it. We have to do this
690 early, otherwise we might mark a variable as volatile
691 after we gimplify other statements that use the variable
692 assuming it's not volatile. */
694 /* FIXME once most targets define the above hook, this should
695 go away (perhaps along with the #include "target.h"). */
696 walk_tree (&TREE_OPERAND (*tp, 0), mark_decls_volatile_r,
705 unmark_visited_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
706 void *data ATTRIBUTE_UNUSED)
708 if (TREE_VISITED (*tp))
709 TREE_VISITED (*tp) = 0;
716 /* Unshare all the trees in BODY_P, a pointer to the body of FNDECL, and the
717 bodies of any nested functions. */
720 unshare_body (tree *body_p, tree fndecl)
722 struct cgraph_node *cgn = cgraph_node (fndecl);
724 walk_tree (body_p, copy_if_shared_r, NULL, NULL);
725 for (cgn = cgn->nested; cgn; cgn = cgn->next_nested)
726 unshare_body (&DECL_SAVED_TREE (cgn->decl), cgn->decl);
729 /* Likewise, but mark all trees as not visited. */
732 unvisit_body (tree *body_p, tree fndecl)
734 struct cgraph_node *cgn = cgraph_node (fndecl);
736 walk_tree (body_p, unmark_visited_r, NULL, NULL);
737 for (cgn = cgn->nested; cgn; cgn = cgn->next_nested)
738 unvisit_body (&DECL_SAVED_TREE (cgn->decl), cgn->decl);
741 /* Unshare T and all the trees reached from T via TREE_CHAIN. */
744 unshare_all_trees (tree t)
746 walk_tree (&t, copy_if_shared_r, NULL, NULL);
747 walk_tree (&t, unmark_visited_r, NULL, NULL);
750 /* Unconditionally make an unshared copy of EXPR. This is used when using
751 stored expressions which span multiple functions, such as BINFO_VTABLE,
752 as the normal unsharing process can't tell that they're shared. */
755 unshare_expr (tree expr)
757 walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
761 /* A terser interface for building a representation of a exception
765 gimple_build_eh_filter (tree body, tree allowed, tree failure)
769 /* FIXME should the allowed types go in TREE_TYPE? */
770 t = build (EH_FILTER_EXPR, void_type_node, allowed, NULL_TREE);
771 append_to_statement_list (failure, &EH_FILTER_FAILURE (t));
773 t = build (TRY_CATCH_EXPR, void_type_node, NULL_TREE, t);
774 append_to_statement_list (body, &TREE_OPERAND (t, 0));
780 /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
781 contain statements and have a value. Assign its value to a temporary
782 and give it void_type_node. Returns the temporary, or NULL_TREE if
783 WRAPPER was already void. */
786 voidify_wrapper_expr (tree wrapper, tree temp)
788 if (!VOID_TYPE_P (TREE_TYPE (wrapper)))
790 tree *p, sub = wrapper;
793 /* Set p to point to the body of the wrapper. */
794 switch (TREE_CODE (sub))
797 /* For a BIND_EXPR, the body is operand 1. */
798 p = &BIND_EXPR_BODY (sub);
802 p = &TREE_OPERAND (sub, 0);
806 /* Advance to the last statement. Set all container types to void. */
807 if (TREE_CODE (*p) == STATEMENT_LIST)
809 tree_stmt_iterator i = tsi_last (*p);
810 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i);
814 for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1))
816 TREE_SIDE_EFFECTS (*p) = 1;
817 TREE_TYPE (*p) = void_type_node;
821 if (p == NULL || IS_EMPTY_STMT (*p))
823 /* Look through exception handling. */
824 else if (TREE_CODE (*p) == TRY_FINALLY_EXPR
825 || TREE_CODE (*p) == TRY_CATCH_EXPR)
830 /* The C++ frontend already did this for us. */
831 else if (TREE_CODE (*p) == INIT_EXPR
832 || TREE_CODE (*p) == TARGET_EXPR)
833 temp = TREE_OPERAND (*p, 0);
834 /* If we're returning a dereference, move the dereference
835 outside the wrapper. */
836 else if (TREE_CODE (*p) == INDIRECT_REF)
838 tree ptr = TREE_OPERAND (*p, 0);
839 temp = create_tmp_var (TREE_TYPE (ptr), "retval");
840 *p = build (MODIFY_EXPR, TREE_TYPE (ptr), temp, ptr);
841 temp = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (temp)), temp);
842 /* If this is a BIND_EXPR for a const inline function, it might not
843 have TREE_SIDE_EFFECTS set. That is no longer accurate. */
844 TREE_SIDE_EFFECTS (wrapper) = 1;
849 temp = create_tmp_var (TREE_TYPE (wrapper), "retval");
850 *p = build (MODIFY_EXPR, TREE_TYPE (temp), temp, *p);
851 TREE_SIDE_EFFECTS (wrapper) = 1;
854 TREE_TYPE (wrapper) = void_type_node;
861 /* Prepare calls to builtins to SAVE and RESTORE the stack as well as
862 a temporary through which they communicate. */
865 build_stack_save_restore (tree *save, tree *restore)
867 tree save_call, tmp_var;
870 build_function_call_expr (implicit_built_in_decls[BUILT_IN_STACK_SAVE],
872 tmp_var = create_tmp_var (ptr_type_node, "saved_stack");
874 *save = build (MODIFY_EXPR, ptr_type_node, tmp_var, save_call);
876 build_function_call_expr (implicit_built_in_decls[BUILT_IN_STACK_RESTORE],
877 tree_cons (NULL_TREE, tmp_var, NULL_TREE));
880 /* Gimplify a BIND_EXPR. Just voidify and recurse. */
882 static enum gimplify_status
883 gimplify_bind_expr (tree *expr_p, tree temp, tree *pre_p)
885 tree bind_expr = *expr_p;
886 bool old_save_stack = gimplify_ctxp->save_stack;
889 temp = voidify_wrapper_expr (bind_expr, temp);
891 /* Mark variables seen in this bind expr. */
892 for (t = BIND_EXPR_VARS (bind_expr); t ; t = TREE_CHAIN (t))
893 t->decl.seen_in_bind_expr = 1;
895 gimple_push_bind_expr (bind_expr);
896 gimplify_ctxp->save_stack = false;
898 gimplify_to_stmt_list (&BIND_EXPR_BODY (bind_expr));
900 if (gimplify_ctxp->save_stack)
902 tree stack_save, stack_restore;
904 /* Save stack on entry and restore it on exit. Add a try_finally
905 block to achieve this. Note that mudflap depends on the
906 format of the emitted code: see mx_register_decls(). */
907 build_stack_save_restore (&stack_save, &stack_restore);
909 t = build (TRY_FINALLY_EXPR, void_type_node,
910 BIND_EXPR_BODY (bind_expr), NULL_TREE);
911 append_to_statement_list (stack_restore, &TREE_OPERAND (t, 1));
913 BIND_EXPR_BODY (bind_expr) = NULL_TREE;
914 append_to_statement_list (stack_save, &BIND_EXPR_BODY (bind_expr));
915 append_to_statement_list (t, &BIND_EXPR_BODY (bind_expr));
918 gimplify_ctxp->save_stack = old_save_stack;
919 gimple_pop_bind_expr ();
924 append_to_statement_list (bind_expr, pre_p);
931 /* Gimplify a RETURN_EXPR. If the expression to be returned is not a
932 GIMPLE value, it is assigned to a new temporary and the statement is
933 re-written to return the temporary.
935 PRE_P points to the list where side effects that must happen before
936 STMT should be stored. */
938 static enum gimplify_status
939 gimplify_return_expr (tree stmt, tree *pre_p)
941 tree ret_expr = TREE_OPERAND (stmt, 0);
942 tree result_decl, result;
944 if (!ret_expr || TREE_CODE (ret_expr) == RESULT_DECL)
947 if (ret_expr == error_mark_node)
950 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
951 result_decl = NULL_TREE;
954 result_decl = TREE_OPERAND (ret_expr, 0);
955 #ifdef ENABLE_CHECKING
956 if ((TREE_CODE (ret_expr) != MODIFY_EXPR
957 && TREE_CODE (ret_expr) != INIT_EXPR)
958 || TREE_CODE (result_decl) != RESULT_DECL)
963 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
964 Recall that aggregate_value_p is FALSE for any aggregate type that is
965 returned in registers. If we're returning values in registers, then
966 we don't want to extend the lifetime of the RESULT_DECL, particularly
967 across another call. In addition, for those aggregates for which
968 hard_function_value generates a PARALLEL, we'll abort during normal
969 expansion of structure assignments; there's special code in expand_return
970 to handle this case that does not exist in expand_expr. */
972 || aggregate_value_p (result_decl, TREE_TYPE (current_function_decl)))
973 result = result_decl;
974 else if (gimplify_ctxp->return_temp)
975 result = gimplify_ctxp->return_temp;
978 result = create_tmp_var (TREE_TYPE (result_decl), NULL);
980 /* ??? With complex control flow (usually involving abnormal edges),
981 we can wind up warning about an uninitialized value for this. Due
982 to how this variable is constructed and initialized, this is never
983 true. Give up and never warn. */
984 TREE_NO_WARNING (result) = 1;
986 gimplify_ctxp->return_temp = result;
989 /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
990 Then gimplify the whole thing. */
991 if (result != result_decl)
992 TREE_OPERAND (ret_expr, 0) = result;
994 gimplify_and_add (TREE_OPERAND (stmt, 0), pre_p);
996 /* If we didn't use a temporary, then the result is just the result_decl.
997 Otherwise we need a simple copy. This should already be gimple. */
998 if (result == result_decl)
1001 ret_expr = build (MODIFY_EXPR, TREE_TYPE (result), result_decl, result);
1002 TREE_OPERAND (stmt, 0) = ret_expr;
1007 /* Gimplify a LOOP_EXPR. Normally this just involves gimplifying the body
1008 and replacing the LOOP_EXPR with goto, but if the loop contains an
1009 EXIT_EXPR, we need to append a label for it to jump to. */
1011 static enum gimplify_status
1012 gimplify_loop_expr (tree *expr_p, tree *pre_p)
1014 tree saved_label = gimplify_ctxp->exit_label;
1015 tree start_label = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
1016 tree jump_stmt = build_and_jump (&LABEL_EXPR_LABEL (start_label));
1018 append_to_statement_list (start_label, pre_p);
1020 gimplify_ctxp->exit_label = NULL_TREE;
1022 gimplify_and_add (LOOP_EXPR_BODY (*expr_p), pre_p);
1024 if (gimplify_ctxp->exit_label)
1026 append_to_statement_list (jump_stmt, pre_p);
1027 *expr_p = build1 (LABEL_EXPR, void_type_node, gimplify_ctxp->exit_label);
1030 *expr_p = jump_stmt;
1032 gimplify_ctxp->exit_label = saved_label;
1037 /* Compare two case labels. Because the front end should already have
1038 made sure that case ranges do not overlap, it is enough to only compare
1039 the CASE_LOW values of each case label. */
1042 compare_case_labels (const void *p1, const void *p2)
1044 tree case1 = *(tree *)p1;
1045 tree case2 = *(tree *)p2;
1047 return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
1050 /* Sort the case labels in LABEL_VEC in ascending order. */
1053 sort_case_labels (tree label_vec)
1055 size_t len = TREE_VEC_LENGTH (label_vec);
1056 tree default_case = TREE_VEC_ELT (label_vec, len - 1);
1058 if (CASE_LOW (default_case))
1062 /* The last label in the vector should be the default case
1064 for (i = 0; i < len; ++i)
1066 tree t = TREE_VEC_ELT (label_vec, i);
1070 TREE_VEC_ELT (label_vec, i) = TREE_VEC_ELT (label_vec, len - 1);
1071 TREE_VEC_ELT (label_vec, len - 1) = default_case;
1077 qsort (&TREE_VEC_ELT (label_vec, 0), len - 1, sizeof (tree),
1078 compare_case_labels);
1081 /* Gimplify a SWITCH_EXPR, and collect a TREE_VEC of the labels it can
1084 static enum gimplify_status
1085 gimplify_switch_expr (tree *expr_p, tree *pre_p)
1087 tree switch_expr = *expr_p;
1088 enum gimplify_status ret;
1090 ret = gimplify_expr (&SWITCH_COND (switch_expr), pre_p, NULL,
1091 is_gimple_val, fb_rvalue);
1093 if (SWITCH_BODY (switch_expr))
1095 varray_type labels, saved_labels;
1096 tree label_vec, default_case = NULL_TREE;
1099 /* If someone can be bothered to fill in the labels, they can
1100 be bothered to null out the body too. */
1101 if (SWITCH_LABELS (switch_expr))
1104 saved_labels = gimplify_ctxp->case_labels;
1105 VARRAY_TREE_INIT (gimplify_ctxp->case_labels, 8, "case_labels");
1107 gimplify_to_stmt_list (&SWITCH_BODY (switch_expr));
1109 labels = gimplify_ctxp->case_labels;
1110 gimplify_ctxp->case_labels = saved_labels;
1112 len = VARRAY_ACTIVE_SIZE (labels);
1114 for (i = 0; i < len; ++i)
1116 tree t = VARRAY_TREE (labels, i);
1119 /* The default case must be the last label in the list. */
1121 VARRAY_TREE (labels, i) = VARRAY_TREE (labels, len - 1);
1127 label_vec = make_tree_vec (len + 1);
1128 SWITCH_LABELS (*expr_p) = label_vec;
1129 append_to_statement_list (switch_expr, pre_p);
1133 /* If the switch has no default label, add one, so that we jump
1134 around the switch body. */
1135 default_case = build (CASE_LABEL_EXPR, void_type_node, NULL_TREE,
1136 NULL_TREE, create_artificial_label ());
1137 append_to_statement_list (SWITCH_BODY (switch_expr), pre_p);
1138 *expr_p = build (LABEL_EXPR, void_type_node,
1139 CASE_LABEL (default_case));
1142 *expr_p = SWITCH_BODY (switch_expr);
1144 for (i = 0; i < len; ++i)
1145 TREE_VEC_ELT (label_vec, i) = VARRAY_TREE (labels, i);
1146 TREE_VEC_ELT (label_vec, len) = default_case;
1148 sort_case_labels (label_vec);
1150 SWITCH_BODY (switch_expr) = NULL;
1152 else if (!SWITCH_LABELS (switch_expr))
1158 static enum gimplify_status
1159 gimplify_case_label_expr (tree *expr_p)
1161 tree expr = *expr_p;
1162 if (gimplify_ctxp->case_labels)
1163 VARRAY_PUSH_TREE (gimplify_ctxp->case_labels, expr);
1166 *expr_p = build (LABEL_EXPR, void_type_node, CASE_LABEL (expr));
1170 /* Gimplify a LABELED_BLOCK_EXPR into a LABEL_EXPR following
1171 a (possibly empty) body. */
1173 static enum gimplify_status
1174 gimplify_labeled_block_expr (tree *expr_p)
1176 tree body = LABELED_BLOCK_BODY (*expr_p);
1177 tree label = LABELED_BLOCK_LABEL (*expr_p);
1180 DECL_CONTEXT (label) = current_function_decl;
1181 t = build (LABEL_EXPR, void_type_node, label);
1182 if (body != NULL_TREE)
1183 t = build (COMPOUND_EXPR, void_type_node, body, t);
1189 /* Gimplify a EXIT_BLOCK_EXPR into a GOTO_EXPR. */
1191 static enum gimplify_status
1192 gimplify_exit_block_expr (tree *expr_p)
1194 tree labeled_block = TREE_OPERAND (*expr_p, 0);
1197 /* First operand must be a LABELED_BLOCK_EXPR, which should
1198 already be lowered (or partially lowered) when we get here. */
1199 #if defined ENABLE_CHECKING
1200 if (TREE_CODE (labeled_block) != LABELED_BLOCK_EXPR)
1204 label = LABELED_BLOCK_LABEL (labeled_block);
1205 *expr_p = build1 (GOTO_EXPR, void_type_node, label);
1210 /* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
1214 build_and_jump (tree *label_p)
1216 if (label_p == NULL)
1217 /* If there's nowhere to jump, just fall through. */
1220 if (*label_p == NULL_TREE)
1222 tree label = create_artificial_label ();
1226 return build1 (GOTO_EXPR, void_type_node, *label_p);
1229 /* Gimplify an EXIT_EXPR by converting to a GOTO_EXPR inside a COND_EXPR.
1230 This also involves building a label to jump to and communicating it to
1231 gimplify_loop_expr through gimplify_ctxp->exit_label. */
1233 static enum gimplify_status
1234 gimplify_exit_expr (tree *expr_p)
1236 tree cond = TREE_OPERAND (*expr_p, 0);
1239 expr = build_and_jump (&gimplify_ctxp->exit_label);
1240 expr = build (COND_EXPR, void_type_node, cond, expr, NULL_TREE);
1246 /* A helper function to be called via walk_tree. Mark all labels under *TP
1247 as being forced. To be called for DECL_INITIAL of static variables. */
1250 force_labels_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
1254 if (TREE_CODE (*tp) == LABEL_DECL)
1255 FORCED_LABEL (*tp) = 1;
1260 /* Break out elements of a constructor used as an initializer into separate
1263 Note that we still need to clear any elements that don't have explicit
1264 initializers, so if not all elements are initialized we keep the
1265 original MODIFY_EXPR, we just remove all of the constructor elements. */
1267 static enum gimplify_status
1268 gimplify_init_constructor (tree *expr_p, tree *pre_p,
1269 tree *post_p, bool want_value)
1271 tree object = TREE_OPERAND (*expr_p, 0);
1272 tree ctor = TREE_OPERAND (*expr_p, 1);
1273 tree type = TREE_TYPE (ctor);
1274 enum gimplify_status ret;
1277 if (TREE_CODE (ctor) != CONSTRUCTOR)
1278 return GS_UNHANDLED;
1280 elt_list = CONSTRUCTOR_ELTS (ctor);
1283 switch (TREE_CODE (type))
1287 case QUAL_UNION_TYPE:
1290 HOST_WIDE_INT i, num_elements, num_nonzero_elements;
1291 HOST_WIDE_INT num_nonconstant_elements;
1294 /* Aggregate types must lower constructors to initialization of
1295 individual elements. The exception is that a CONSTRUCTOR node
1296 with no elements indicates zero-initialization of the whole. */
1297 if (elt_list == NULL)
1305 return GS_UNHANDLED;
1308 categorize_ctor_elements (ctor, &num_nonzero_elements,
1309 &num_nonconstant_elements);
1310 num_elements = count_type_elements (TREE_TYPE (ctor));
1312 /* If a const aggregate variable is being initialized, then it
1313 should never be a lose to promote the variable to be static. */
1314 if (num_nonconstant_elements == 0
1315 && TREE_READONLY (object)
1316 && TREE_CODE (object) == VAR_DECL)
1318 DECL_INITIAL (object) = ctor;
1319 TREE_STATIC (object) = 1;
1320 if (!DECL_NAME (object))
1321 DECL_NAME (object) = create_tmp_var_name ("C");
1322 walk_tree (&DECL_INITIAL (object), force_labels_r, NULL, NULL);
1324 /* ??? C++ doesn't automatically append a .<number> to the
1325 assembler name, and even when it does, it looks a FE private
1326 data structures to figure out what that number should be,
1327 which are not set for this variable. I suppose this is
1328 important for local statics for inline functions, which aren't
1329 "local" in the object file sense. So in order to get a unique
1330 TU-local symbol, we must invoke the lhd version now. */
1331 lhd_set_decl_assembler_name (object);
1333 *expr_p = NULL_TREE;
1337 /* If there are "lots" of initialized elements, and all of them
1338 are valid address constants, then the entire initializer can
1339 be dropped to memory, and then memcpy'd out. */
1340 if (num_nonconstant_elements == 0)
1342 HOST_WIDE_INT size = int_size_in_bytes (type);
1345 /* ??? We can still get unbounded array types, at least
1346 from the C++ front end. This seems wrong, but attempt
1347 to work around it for now. */
1350 size = int_size_in_bytes (TREE_TYPE (object));
1352 TREE_TYPE (ctor) = type = TREE_TYPE (object);
1355 /* Find the maximum alignment we can assume for the object. */
1356 /* ??? Make use of DECL_OFFSET_ALIGN. */
1357 if (DECL_P (object))
1358 align = DECL_ALIGN (object);
1360 align = TYPE_ALIGN (type);
1362 if (size > 0 && !can_move_by_pieces (size, align))
1364 tree new = create_tmp_var_raw (type, "C");
1365 gimple_add_tmp_var (new);
1366 TREE_STATIC (new) = 1;
1367 TREE_READONLY (new) = 1;
1368 DECL_INITIAL (new) = ctor;
1369 if (align > DECL_ALIGN (new))
1371 DECL_ALIGN (new) = align;
1372 DECL_USER_ALIGN (new) = 1;
1374 walk_tree (&DECL_INITIAL (new), force_labels_r, NULL, NULL);
1376 TREE_OPERAND (*expr_p, 1) = new;
1381 /* If there are "lots" of initialized elements, even discounting
1382 those that are not address constants (and thus *must* be
1383 computed at runtime), then partition the constructor into
1384 constant and non-constant parts. Block copy the constant
1385 parts in, then generate code for the non-constant parts. */
1386 /* TODO. There's code in cp/typeck.c to do this. */
1388 /* If there are "lots" of zeros, then block clear the object first. */
1390 if (num_elements - num_nonzero_elements > CLEAR_RATIO
1391 && num_nonzero_elements < num_elements/4)
1394 /* ??? This bit ought not be needed. For any element not present
1395 in the initializer, we should simply set them to zero. Except
1396 we'd need to *find* the elements that are not present, and that
1397 requires trickery to avoid quadratic compile-time behavior in
1398 large cases or excessive memory use in small cases. */
1401 HOST_WIDE_INT len = list_length (elt_list);
1402 if (TREE_CODE (type) == ARRAY_TYPE)
1404 tree nelts = array_type_nelts (type);
1405 if (!host_integerp (nelts, 1)
1406 || tree_low_cst (nelts, 1) != len)
1409 else if (len != fields_length (type))
1415 CONSTRUCTOR_ELTS (ctor) = NULL_TREE;
1416 append_to_statement_list (*expr_p, pre_p);
1419 for (i = 0; elt_list; i++, elt_list = TREE_CHAIN (elt_list))
1421 tree purpose, value, cref, init;
1423 purpose = TREE_PURPOSE (elt_list);
1424 value = TREE_VALUE (elt_list);
1426 if (cleared && initializer_zerop (value))
1429 if (TREE_CODE (type) == ARRAY_TYPE)
1431 tree t = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (object)));
1433 /* ??? Here's to hoping the front end fills in all of the
1434 indicies, so we don't have to figure out what's missing
1438 /* ??? Need to handle this. */
1439 if (TREE_CODE (purpose) == RANGE_EXPR)
1442 cref = build (ARRAY_REF, t, object, purpose, NULL_TREE, NULL_TREE);
1445 cref = build (COMPONENT_REF, TREE_TYPE (purpose), object,
1446 purpose, NULL_TREE);
1448 init = build (MODIFY_EXPR, TREE_TYPE (purpose), cref, value);
1450 /* Each member initialization is a full-expression. */
1451 gimplify_and_add (init, pre_p);
1454 *expr_p = NULL_TREE;
1462 /* Extract the real and imaginary parts out of the ctor. */
1466 r = TREE_VALUE (elt_list);
1467 elt_list = TREE_CHAIN (elt_list);
1470 i = TREE_VALUE (elt_list);
1471 if (TREE_CHAIN (elt_list))
1475 if (r == NULL || i == NULL)
1477 tree zero = convert (TREE_TYPE (type), integer_zero_node);
1484 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
1485 represent creation of a complex value. */
1486 if (TREE_CONSTANT (r) && TREE_CONSTANT (i))
1488 ctor = build_complex (type, r, i);
1489 TREE_OPERAND (*expr_p, 1) = ctor;
1493 ctor = build (COMPLEX_EXPR, type, r, i);
1494 TREE_OPERAND (*expr_p, 1) = ctor;
1495 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
1496 is_gimple_rhs, fb_rvalue);
1502 /* Go ahead and simplify constant constructors to VECTOR_CST. */
1503 if (TREE_CONSTANT (ctor))
1504 TREE_OPERAND (*expr_p, 1) = build_vector (type, elt_list);
1507 /* Vector types use CONSTRUCTOR all the way through gimple
1508 compilation as a general initializer. */
1509 for (; elt_list; elt_list = TREE_CHAIN (elt_list))
1511 enum gimplify_status tret;
1512 tret = gimplify_expr (&TREE_VALUE (elt_list), pre_p, post_p,
1513 is_gimple_constructor_elt, fb_rvalue);
1514 if (tret == GS_ERROR)
1521 /* So how did we get a CONSTRUCTOR for a scalar type? */
1525 if (ret == GS_ERROR)
1527 else if (want_value)
1529 append_to_statement_list (*expr_p, pre_p);
1537 /* *EXPR_P is a COMPONENT_REF being used as an rvalue. If its type is
1538 different from its canonical type, wrap the whole thing inside a
1539 NOP_EXPR and force the type of the COMPONENT_REF to be the canonical
1542 The canonical type of a COMPONENT_REF is the type of the field being
1543 referenced--unless the field is a bit-field which can be read directly
1544 in a smaller mode, in which case the canonical type is the
1545 sign-appropriate type corresponding to that mode. */
1548 canonicalize_component_ref (tree *expr_p)
1550 tree expr = *expr_p;
1553 if (TREE_CODE (expr) != COMPONENT_REF)
1556 if (INTEGRAL_TYPE_P (TREE_TYPE (expr)))
1557 type = TREE_TYPE (get_unwidened (expr, NULL_TREE));
1559 type = TREE_TYPE (TREE_OPERAND (expr, 1));
1561 if (TREE_TYPE (expr) != type)
1563 tree old_type = TREE_TYPE (expr);
1565 /* Set the type of the COMPONENT_REF to the underlying type. */
1566 TREE_TYPE (expr) = type;
1568 /* And wrap the whole thing inside a NOP_EXPR. */
1569 expr = build1 (NOP_EXPR, old_type, expr);
1575 /* If a NOP conversion is changing a pointer to array of foo to a pointer
1576 to foo, embed that change in the ADDR_EXPR by converting
1581 where L is the lower bound. For simplicity, only do this for constant
1585 canonicalize_addr_expr (tree *expr_p)
1587 tree expr = *expr_p;
1588 tree ctype = TREE_TYPE (expr);
1589 tree addr_expr = TREE_OPERAND (expr, 0);
1590 tree atype = TREE_TYPE (addr_expr);
1591 tree dctype, datype, ddatype, otype, obj_expr;
1593 /* Both cast and addr_expr types should be pointers. */
1594 if (!POINTER_TYPE_P (ctype) || !POINTER_TYPE_P (atype))
1597 /* The addr_expr type should be a pointer to an array. */
1598 datype = TREE_TYPE (atype);
1599 if (TREE_CODE (datype) != ARRAY_TYPE)
1602 /* Both cast and addr_expr types should address the same object type. */
1603 dctype = TREE_TYPE (ctype);
1604 ddatype = TREE_TYPE (datype);
1605 if (!lang_hooks.types_compatible_p (ddatype, dctype))
1608 /* The addr_expr and the object type should match. */
1609 obj_expr = TREE_OPERAND (addr_expr, 0);
1610 otype = TREE_TYPE (obj_expr);
1611 if (!lang_hooks.types_compatible_p (otype, datype))
1614 /* The lower bound and element sizes must be constant. */
1615 if (TREE_CODE (TYPE_SIZE_UNIT (dctype)) != INTEGER_CST
1616 || !TYPE_DOMAIN (datype) || !TYPE_MIN_VALUE (TYPE_DOMAIN (datype))
1617 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST)
1620 /* All checks succeeded. Build a new node to merge the cast. */
1621 *expr_p = build4 (ARRAY_REF, dctype, obj_expr,
1622 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
1623 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
1624 size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (dctype),
1625 size_int (TYPE_ALIGN (dctype)
1627 *expr_p = build1 (ADDR_EXPR, ctype, *expr_p);
1630 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions
1631 underneath as appropriate. */
1633 static enum gimplify_status
1634 gimplify_conversion (tree *expr_p)
1636 /* Strip away as many useless type conversions as possible
1638 STRIP_USELESS_TYPE_CONVERSION (*expr_p);
1640 /* If we still have a conversion at the toplevel, then strip
1641 away all but the outermost conversion. */
1642 if (TREE_CODE (*expr_p) == NOP_EXPR || TREE_CODE (*expr_p) == CONVERT_EXPR)
1644 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p, 0));
1646 /* And remove the outermost conversion if it's useless. */
1647 if (tree_ssa_useless_type_conversion (*expr_p))
1648 *expr_p = TREE_OPERAND (*expr_p, 0);
1651 /* If we still have a conversion at the toplevel,
1652 then canonicalize some constructs. */
1653 if (TREE_CODE (*expr_p) == NOP_EXPR || TREE_CODE (*expr_p) == CONVERT_EXPR)
1655 tree sub = TREE_OPERAND (*expr_p, 0);
1657 /* If a NOP conversion is changing the type of a COMPONENT_REF
1658 expression, then canonicalize its type now in order to expose more
1659 redundant conversions. */
1660 if (TREE_CODE (sub) == COMPONENT_REF)
1661 canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0));
1663 /* If a NOP conversion is changing a pointer to array of foo
1664 to a pointer to foo, embed that change in the ADDR_EXPR. */
1665 else if (TREE_CODE (sub) == ADDR_EXPR)
1666 canonicalize_addr_expr (expr_p);
1672 /* Reduce MIN/MAX_EXPR to a COND_EXPR for further gimplification. */
1674 static enum gimplify_status
1675 gimplify_minimax_expr (tree *expr_p, tree *pre_p, tree *post_p)
1677 tree op1 = TREE_OPERAND (*expr_p, 0);
1678 tree op2 = TREE_OPERAND (*expr_p, 1);
1679 enum tree_code code;
1680 enum gimplify_status r0, r1;
1682 if (TREE_CODE (*expr_p) == MIN_EXPR)
1687 r0 = gimplify_expr (&op1, pre_p, post_p, is_gimple_val, fb_rvalue);
1688 r1 = gimplify_expr (&op2, pre_p, post_p, is_gimple_val, fb_rvalue);
1690 *expr_p = build (COND_EXPR, TREE_TYPE (*expr_p),
1691 build (code, boolean_type_node, op1, op2),
1694 if (r0 == GS_ERROR || r1 == GS_ERROR)
1700 /* Subroutine of gimplify_compound_lval.
1701 Converts an ARRAY_REF to the equivalent *(&array + offset) form. */
1703 static enum gimplify_status
1704 gimplify_array_ref_to_plus (tree *expr_p, tree *pre_p, tree *post_p)
1706 tree array = TREE_OPERAND (*expr_p, 0);
1707 tree arrtype = TREE_TYPE (array);
1708 tree elttype = TREE_TYPE (arrtype);
1709 tree size = array_ref_element_size (*expr_p);
1710 tree ptrtype = build_pointer_type (elttype);
1711 enum tree_code add_code = PLUS_EXPR;
1712 tree idx = TREE_OPERAND (*expr_p, 1);
1713 tree minidx = unshare_expr (array_ref_low_bound (*expr_p));
1714 tree offset, addr, result;
1715 enum gimplify_status ret;
1717 /* If the array domain does not start at zero, apply the offset. */
1718 if (!integer_zerop (minidx))
1720 idx = convert (TREE_TYPE (minidx), idx);
1721 idx = fold (build (MINUS_EXPR, TREE_TYPE (minidx), idx, minidx));
1724 /* If the index is negative -- a technically invalid situation now
1725 that we've biased the index back to zero -- then casting it to
1726 unsigned has ill effects. In particular, -1*4U/4U != -1.
1727 Represent this as a subtraction of a positive rather than addition
1728 of a negative. This will prevent any conversion back to ARRAY_REF
1729 from getting the wrong results from the division. */
1730 if (TREE_CODE (idx) == INTEGER_CST && tree_int_cst_sgn (idx) < 0)
1732 idx = fold (build1 (NEGATE_EXPR, TREE_TYPE (idx), idx));
1733 add_code = MINUS_EXPR;
1736 /* Pointer arithmetic must be done in sizetype. */
1737 idx = fold_convert (sizetype, idx);
1739 /* Convert the index to a byte offset. */
1740 offset = size_binop (MULT_EXPR, size, idx);
1742 ret = gimplify_expr (&array, pre_p, post_p, is_gimple_min_lval, fb_lvalue);
1743 if (ret == GS_ERROR)
1746 addr = build_fold_addr_expr_with_type (array, ptrtype);
1747 result = fold (build (add_code, ptrtype, addr, offset));
1748 *expr_p = build1 (INDIRECT_REF, elttype, result);
1753 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
1754 node pointed by EXPR_P.
1757 : min_lval '[' val ']'
1759 | compound_lval '[' val ']'
1760 | compound_lval '.' ID
1762 This is not part of the original SIMPLE definition, which separates
1763 array and member references, but it seems reasonable to handle them
1764 together. Also, this way we don't run into problems with union
1765 aliasing; gcc requires that for accesses through a union to alias, the
1766 union reference must be explicit, which was not always the case when we
1767 were splitting up array and member refs.
1769 PRE_P points to the list where side effects that must happen before
1770 *EXPR_P should be stored.
1772 POST_P points to the list where side effects that must happen after
1773 *EXPR_P should be stored. */
1775 static enum gimplify_status
1776 gimplify_compound_lval (tree *expr_p, tree *pre_p,
1777 tree *post_p, bool want_lvalue)
1781 enum gimplify_status ret = GS_OK, tret;
1784 #if defined ENABLE_CHECKING
1785 if (TREE_CODE (*expr_p) != ARRAY_REF
1786 && TREE_CODE (*expr_p) != ARRAY_RANGE_REF
1787 && TREE_CODE (*expr_p) != COMPONENT_REF
1788 && TREE_CODE (*expr_p) != BIT_FIELD_REF
1789 && TREE_CODE (*expr_p) != REALPART_EXPR
1790 && TREE_CODE (*expr_p) != IMAGPART_EXPR)
1794 /* Create a stack of the subexpressions so later we can walk them in
1795 order from inner to outer. */
1796 VARRAY_TREE_INIT (stack, 10, "stack");
1798 /* We can either handle REALPART_EXPR, IMAGEPART_EXPR anything that
1799 handled_components can deal with. */
1801 (handled_component_p (*p)
1802 || TREE_CODE (*p) == REALPART_EXPR || TREE_CODE (*p) == IMAGPART_EXPR);
1803 p = &TREE_OPERAND (*p, 0))
1804 VARRAY_PUSH_TREE (stack, *p);
1806 /* Now STACK is a stack of pointers to all the refs we've walked through
1807 and P points to the innermost expression.
1809 Java requires that we elaborated nodes in source order. That
1810 means we must gimplify the inner expression followed by each of
1811 the indices, in order. But we can't gimplify the inner
1812 expression until we deal with any variable bounds, sizes, or
1813 positions in order to deal with PLACEHOLDER_EXPRs.
1815 So we do this in three steps. First we deal with the annotations
1816 for any variables in the components, then we gimplify the base,
1817 then we gimplify any indices, from left to right. */
1818 for (i = VARRAY_ACTIVE_SIZE (stack) - 1; i >= 0; i--)
1820 tree t = VARRAY_TREE (stack, i);
1822 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
1824 /* Gimplify the low bound and element type size and put them into
1825 the ARRAY_REF. If these values are set, they have already been
1827 if (!TREE_OPERAND (t, 2))
1829 tree low = unshare_expr (array_ref_low_bound (t));
1830 if (!is_gimple_min_invariant (low))
1832 TREE_OPERAND (t, 2) = low;
1833 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
1834 is_gimple_tmp_var, fb_rvalue);
1835 ret = MIN (ret, tret);
1839 if (!TREE_OPERAND (t, 3))
1841 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
1842 tree elmt_size = unshare_expr (array_ref_element_size (t));
1843 tree factor = size_int (TYPE_ALIGN (elmt_type) / BITS_PER_UNIT);
1845 /* Divide the element size by the alignment of the element
1847 elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor);
1849 if (!is_gimple_min_invariant (elmt_size))
1851 TREE_OPERAND (t, 3) = elmt_size;
1852 tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p, post_p,
1853 is_gimple_tmp_var, fb_rvalue);
1854 ret = MIN (ret, tret);
1858 else if (TREE_CODE (t) == COMPONENT_REF)
1860 /* Set the field offset into T and gimplify it. */
1861 if (!TREE_OPERAND (t, 2))
1863 tree offset = unshare_expr (component_ref_field_offset (t));
1864 tree field = TREE_OPERAND (t, 1);
1866 = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT);
1868 /* Divide the offset by its alignment. */
1869 offset = size_binop (EXACT_DIV_EXPR, offset, factor);
1871 if (!is_gimple_min_invariant (offset))
1873 TREE_OPERAND (t, 2) = offset;
1874 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
1875 is_gimple_tmp_var, fb_rvalue);
1876 ret = MIN (ret, tret);
1882 /* Step 2 is to gimplify the base expression. */
1883 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
1884 want_lvalue ? fb_lvalue : fb_rvalue);
1885 ret = MIN (ret, tret);
1887 /* And finally, the indices and operands to BIT_FIELD_REF. */
1888 for (; VARRAY_ACTIVE_SIZE (stack) > 0; )
1890 tree t = VARRAY_TOP_TREE (stack);
1892 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
1894 /* Gimplify the dimension.
1895 Temporary fix for gcc.c-torture/execute/20040313-1.c.
1896 Gimplify non-constant array indices into a temporary
1898 FIXME - The real fix is to gimplify post-modify
1899 expressions into a minimal gimple lvalue. However, that
1900 exposes bugs in alias analysis. The alias analyzer does
1901 not handle &PTR->FIELD very well. Will fix after the
1902 branch is merged into mainline (dnovillo 2004-05-03). */
1903 if (!is_gimple_min_invariant (TREE_OPERAND (t, 1)))
1905 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
1906 is_gimple_tmp_var, fb_rvalue);
1907 ret = MIN (ret, tret);
1910 else if (TREE_CODE (t) == BIT_FIELD_REF)
1912 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
1913 is_gimple_val, fb_rvalue);
1914 ret = MIN (ret, tret);
1915 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
1916 is_gimple_val, fb_rvalue);
1917 ret = MIN (ret, tret);
1920 /* The innermost expression P may have originally had TREE_SIDE_EFFECTS
1921 set which would have caused all the outer expressions in EXPR_P
1922 leading to P to also have had TREE_SIDE_EFFECTS set. */
1923 recalculate_side_effects (t);
1927 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
1928 want_lvalue ? fb_lvalue : fb_rvalue);
1929 ret = MIN (ret, tret);
1931 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */
1932 if (!want_lvalue && TREE_CODE (*expr_p) == COMPONENT_REF)
1934 canonicalize_component_ref (expr_p);
1935 ret = MIN (ret, GS_OK);
1941 /* Gimplify the self modifying expression pointed by EXPR_P (++, --, +=, -=).
1943 PRE_P points to the list where side effects that must happen before
1944 *EXPR_P should be stored.
1946 POST_P points to the list where side effects that must happen after
1947 *EXPR_P should be stored.
1949 WANT_VALUE is nonzero iff we want to use the value of this expression
1950 in another expression. */
1952 static enum gimplify_status
1953 gimplify_self_mod_expr (tree *expr_p, tree *pre_p, tree *post_p,
1956 enum tree_code code;
1957 tree lhs, lvalue, rhs, t1;
1959 enum tree_code arith_code;
1960 enum gimplify_status ret;
1962 code = TREE_CODE (*expr_p);
1964 #if defined ENABLE_CHECKING
1965 if (code != POSTINCREMENT_EXPR
1966 && code != POSTDECREMENT_EXPR
1967 && code != PREINCREMENT_EXPR
1968 && code != PREDECREMENT_EXPR)
1972 /* Prefix or postfix? */
1973 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1974 /* Faster to treat as prefix if result is not used. */
1975 postfix = want_value;
1979 /* Add or subtract? */
1980 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
1981 arith_code = PLUS_EXPR;
1983 arith_code = MINUS_EXPR;
1985 /* Gimplify the LHS into a GIMPLE lvalue. */
1986 lvalue = TREE_OPERAND (*expr_p, 0);
1987 ret = gimplify_expr (&lvalue, pre_p, post_p, is_gimple_lvalue, fb_lvalue);
1988 if (ret == GS_ERROR)
1991 /* Extract the operands to the arithmetic operation. */
1993 rhs = TREE_OPERAND (*expr_p, 1);
1995 /* For postfix operator, we evaluate the LHS to an rvalue and then use
1996 that as the result value and in the postqueue operation. */
1999 ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue);
2000 if (ret == GS_ERROR)
2004 t1 = build (arith_code, TREE_TYPE (*expr_p), lhs, rhs);
2005 t1 = build (MODIFY_EXPR, TREE_TYPE (lvalue), lvalue, t1);
2009 gimplify_and_add (t1, post_p);
2020 /* Gimplify the CALL_EXPR node pointed by EXPR_P.
2023 : ID '(' arglist ')'
2029 PRE_P points to the list where side effects that must happen before
2030 *EXPR_P should be stored. */
2032 static enum gimplify_status
2033 gimplify_call_expr (tree *expr_p, tree *pre_p, bool (*gimple_test_f) (tree))
2037 enum gimplify_status ret;
2039 #if defined ENABLE_CHECKING
2040 if (TREE_CODE (*expr_p) != CALL_EXPR)
2044 /* For reliable diagnostics during inlining, it is necessary that
2045 every call_expr be annotated with file and line. */
2046 if (!EXPR_LOCUS (*expr_p))
2047 annotate_with_locus (*expr_p, input_location);
2049 /* This may be a call to a builtin function.
2051 Builtin function calls may be transformed into different
2052 (and more efficient) builtin function calls under certain
2053 circumstances. Unfortunately, gimplification can muck things
2054 up enough that the builtin expanders are not aware that certain
2055 transformations are still valid.
2057 So we attempt transformation/gimplification of the call before
2058 we gimplify the CALL_EXPR. At this time we do not manage to
2059 transform all calls in the same manner as the expanders do, but
2060 we do transform most of them. */
2061 decl = get_callee_fndecl (*expr_p);
2062 if (decl && DECL_BUILT_IN (decl))
2066 /* If it is allocation of stack, record the need to restore the memory
2067 when the enclosing bind_expr is exited. */
2068 if (DECL_FUNCTION_CODE (decl) == BUILT_IN_STACK_ALLOC)
2069 gimplify_ctxp->save_stack = true;
2071 /* If it is restore of the stack, reset it, since it means we are
2072 regimplifying the bind_expr. Note that we use the fact that
2073 for try_finally_expr, try part is processed first. */
2074 if (DECL_FUNCTION_CODE (decl) == BUILT_IN_STACK_RESTORE)
2075 gimplify_ctxp->save_stack = false;
2077 new = simplify_builtin (*expr_p, gimple_test_f == is_gimple_stmt);
2079 if (new && new != *expr_p)
2081 /* There was a transformation of this call which computes the
2082 same value, but in a more efficient way. Return and try
2089 /* There is a sequence point before the call, so any side effects in
2090 the calling expression must occur before the actual call. Force
2091 gimplify_expr to use an internal post queue. */
2092 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, NULL,
2093 is_gimple_call_addr, fb_rvalue);
2095 if (PUSH_ARGS_REVERSED)
2096 TREE_OPERAND (*expr_p, 1) = nreverse (TREE_OPERAND (*expr_p, 1));
2097 for (arglist = TREE_OPERAND (*expr_p, 1); arglist;
2098 arglist = TREE_CHAIN (arglist))
2100 enum gimplify_status t;
2102 /* There is a sequence point before a function call. Side effects in
2103 the argument list must occur before the actual call. So, when
2104 gimplifying arguments, force gimplify_expr to use an internal
2105 post queue which is then appended to the end of PRE_P. */
2106 t = gimplify_expr (&TREE_VALUE (arglist), pre_p, NULL, is_gimple_val,
2112 if (PUSH_ARGS_REVERSED)
2113 TREE_OPERAND (*expr_p, 1) = nreverse (TREE_OPERAND (*expr_p, 1));
2115 /* Try this again in case gimplification exposed something. */
2116 if (ret != GS_ERROR && decl && DECL_BUILT_IN (decl))
2118 tree new = simplify_builtin (*expr_p, gimple_test_f == is_gimple_stmt);
2120 if (new && new != *expr_p)
2122 /* There was a transformation of this call which computes the
2123 same value, but in a more efficient way. Return and try
2130 /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
2131 decl. This allows us to eliminate redundant or useless
2132 calls to "const" functions. */
2133 if (TREE_CODE (*expr_p) == CALL_EXPR
2134 && (call_expr_flags (*expr_p) & (ECF_CONST | ECF_PURE)))
2135 TREE_SIDE_EFFECTS (*expr_p) = 0;
2140 /* Handle shortcut semantics in the predicate operand of a COND_EXPR by
2141 rewriting it into multiple COND_EXPRs, and possibly GOTO_EXPRs.
2143 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
2144 condition is true or false, respectively. If null, we should generate
2145 our own to skip over the evaluation of this specific expression.
2147 This function is the tree equivalent of do_jump.
2149 shortcut_cond_r should only be called by shortcut_cond_expr. */
2152 shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p)
2154 tree local_label = NULL_TREE;
2155 tree t, expr = NULL;
2157 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
2158 retain the shortcut semantics. Just insert the gotos here;
2159 shortcut_cond_expr will append the real blocks later. */
2160 if (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
2162 /* Turn if (a && b) into
2164 if (a); else goto no;
2165 if (b) goto yes; else goto no;
2168 if (false_label_p == NULL)
2169 false_label_p = &local_label;
2171 t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p);
2172 append_to_statement_list (t, &expr);
2174 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
2176 append_to_statement_list (t, &expr);
2178 else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
2180 /* Turn if (a || b) into
2183 if (b) goto yes; else goto no;
2186 if (true_label_p == NULL)
2187 true_label_p = &local_label;
2189 t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL);
2190 append_to_statement_list (t, &expr);
2192 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
2194 append_to_statement_list (t, &expr);
2196 else if (TREE_CODE (pred) == COND_EXPR)
2198 /* As long as we're messing with gotos, turn if (a ? b : c) into
2200 if (b) goto yes; else goto no;
2202 if (c) goto yes; else goto no; */
2203 expr = build (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0),
2204 shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
2206 shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p,
2211 expr = build (COND_EXPR, void_type_node, pred,
2212 build_and_jump (true_label_p),
2213 build_and_jump (false_label_p));
2218 t = build1 (LABEL_EXPR, void_type_node, local_label);
2219 append_to_statement_list (t, &expr);
2226 shortcut_cond_expr (tree expr)
2228 tree pred = TREE_OPERAND (expr, 0);
2229 tree then_ = TREE_OPERAND (expr, 1);
2230 tree else_ = TREE_OPERAND (expr, 2);
2231 tree true_label, false_label, end_label, t;
2233 tree *false_label_p;
2234 bool emit_end, emit_false;
2235 bool then_se = then_ && TREE_SIDE_EFFECTS (then_);
2236 bool else_se = else_ && TREE_SIDE_EFFECTS (else_);
2238 /* First do simple transformations. */
2241 /* If there is no 'else', turn (a && b) into if (a) if (b). */
2242 while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
2244 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
2245 then_ = shortcut_cond_expr (expr);
2246 pred = TREE_OPERAND (pred, 0);
2247 expr = build (COND_EXPR, void_type_node, pred, then_, NULL_TREE);
2252 /* If there is no 'then', turn
2255 if (a); else if (b); else d. */
2256 while (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
2258 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
2259 else_ = shortcut_cond_expr (expr);
2260 pred = TREE_OPERAND (pred, 0);
2261 expr = build (COND_EXPR, void_type_node, pred, NULL_TREE, else_);
2265 /* If we're done, great. */
2266 if (TREE_CODE (pred) != TRUTH_ANDIF_EXPR
2267 && TREE_CODE (pred) != TRUTH_ORIF_EXPR)
2270 /* Otherwise we need to mess with gotos. Change
2273 if (a); else goto no;
2276 and recursively gimplify the condition. */
2278 true_label = false_label = end_label = NULL_TREE;
2280 /* If our arms just jump somewhere, hijack those labels so we don't
2281 generate jumps to jumps. */
2284 && TREE_CODE (then_) == GOTO_EXPR
2285 && TREE_CODE (GOTO_DESTINATION (then_)) == LABEL_DECL)
2287 true_label = GOTO_DESTINATION (then_);
2293 && TREE_CODE (else_) == GOTO_EXPR
2294 && TREE_CODE (GOTO_DESTINATION (else_)) == LABEL_DECL)
2296 false_label = GOTO_DESTINATION (else_);
2301 /* If we aren't hijacking a label for the 'then' branch, it falls through. */
2303 true_label_p = &true_label;
2305 true_label_p = NULL;
2307 /* The 'else' branch also needs a label if it contains interesting code. */
2308 if (false_label || else_se)
2309 false_label_p = &false_label;
2311 false_label_p = NULL;
2313 /* If there was nothing else in our arms, just forward the label(s). */
2314 if (!then_se && !else_se)
2315 return shortcut_cond_r (pred, true_label_p, false_label_p);
2317 /* If our last subexpression already has a terminal label, reuse it. */
2319 expr = expr_last (else_);
2321 expr = expr_last (then_);
2324 if (expr && TREE_CODE (expr) == LABEL_EXPR)
2325 end_label = LABEL_EXPR_LABEL (expr);
2327 /* If we don't care about jumping to the 'else' branch, jump to the end
2328 if the condition is false. */
2330 false_label_p = &end_label;
2332 /* We only want to emit these labels if we aren't hijacking them. */
2333 emit_end = (end_label == NULL_TREE);
2334 emit_false = (false_label == NULL_TREE);
2336 pred = shortcut_cond_r (pred, true_label_p, false_label_p);
2339 append_to_statement_list (pred, &expr);
2341 append_to_statement_list (then_, &expr);
2344 t = build_and_jump (&end_label);
2345 append_to_statement_list (t, &expr);
2348 t = build1 (LABEL_EXPR, void_type_node, false_label);
2349 append_to_statement_list (t, &expr);
2351 append_to_statement_list (else_, &expr);
2353 if (emit_end && end_label)
2355 t = build1 (LABEL_EXPR, void_type_node, end_label);
2356 append_to_statement_list (t, &expr);
2362 /* EXPR is used in a boolean context; make sure it has BOOLEAN_TYPE. */
2365 gimple_boolify (tree expr)
2367 tree type = TREE_TYPE (expr);
2369 if (TREE_CODE (type) == BOOLEAN_TYPE)
2372 /* If this is the predicate of a COND_EXPR, it might not even be a
2374 expr = lang_hooks.truthvalue_conversion (expr);
2376 switch (TREE_CODE (expr))
2378 case TRUTH_AND_EXPR:
2380 case TRUTH_XOR_EXPR:
2381 case TRUTH_ANDIF_EXPR:
2382 case TRUTH_ORIF_EXPR:
2383 /* Also boolify the arguments of truth exprs. */
2384 TREE_OPERAND (expr, 1) = gimple_boolify (TREE_OPERAND (expr, 1));
2387 case TRUTH_NOT_EXPR:
2388 TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));
2391 case EQ_EXPR: case NE_EXPR:
2392 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2393 /* These expressions always produce boolean results. */
2394 TREE_TYPE (expr) = boolean_type_node;
2398 /* Other expressions that get here must have boolean values, but
2399 might need to be converted to the appropriate mode. */
2400 return convert (boolean_type_node, expr);
2404 /* Convert the conditional expression pointed by EXPR_P '(p) ? a : b;'
2413 The second form is used when *EXPR_P is of type void.
2415 TARGET is the tree for T1 above.
2417 PRE_P points to the list where side effects that must happen before
2418 *EXPR_P should be stored. */
2420 static enum gimplify_status
2421 gimplify_cond_expr (tree *expr_p, tree *pre_p, tree target)
2423 tree expr = *expr_p;
2425 enum gimplify_status ret;
2427 type = TREE_TYPE (expr);
2429 TREE_TYPE (expr) = void_type_node;
2431 /* If this COND_EXPR has a value, copy the values into a temporary within
2433 else if (! VOID_TYPE_P (type))
2442 tmp = create_tmp_var (TREE_TYPE (expr), "iftmp");
2446 /* Build the then clause, 't1 = a;'. But don't build an assignment
2447 if this branch is void; in C++ it can be, if it's a throw. */
2448 if (TREE_TYPE (TREE_OPERAND (expr, 1)) != void_type_node)
2449 TREE_OPERAND (expr, 1)
2450 = build (MODIFY_EXPR, void_type_node, tmp, TREE_OPERAND (expr, 1));
2452 /* Build the else clause, 't1 = b;'. */
2453 if (TREE_TYPE (TREE_OPERAND (expr, 2)) != void_type_node)
2454 TREE_OPERAND (expr, 2)
2455 = build (MODIFY_EXPR, void_type_node, tmp, TREE_OPERAND (expr, 2));
2457 TREE_TYPE (expr) = void_type_node;
2458 recalculate_side_effects (expr);
2460 /* Move the COND_EXPR to the prequeue and use the temp in its place. */
2461 gimplify_and_add (expr, pre_p);
2467 /* Make sure the condition has BOOLEAN_TYPE. */
2468 TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));
2470 /* Break apart && and || conditions. */
2471 if (TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ANDIF_EXPR
2472 || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR)
2474 expr = shortcut_cond_expr (expr);
2476 if (expr != *expr_p)
2480 /* We can't rely on gimplify_expr to re-gimplify the expanded
2481 form properly, as cleanups might cause the target labels to be
2482 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to
2483 set up a conditional context. */
2484 gimple_push_condition ();
2485 gimplify_stmt (expr_p);
2486 gimple_pop_condition (pre_p);
2492 /* Now do the normal gimplification. */
2493 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL,
2494 is_gimple_condexpr, fb_rvalue);
2496 gimple_push_condition ();
2498 gimplify_to_stmt_list (&TREE_OPERAND (expr, 1));
2499 gimplify_to_stmt_list (&TREE_OPERAND (expr, 2));
2500 recalculate_side_effects (expr);
2502 gimple_pop_condition (pre_p);
2504 if (ret == GS_ERROR)
2506 else if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2508 else if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 2)))
2509 /* Rewrite "if (a); else b" to "if (!a) b" */
2511 TREE_OPERAND (expr, 0) = invert_truthvalue (TREE_OPERAND (expr, 0));
2512 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL,
2513 is_gimple_condexpr, fb_rvalue);
2515 tmp = TREE_OPERAND (expr, 1);
2516 TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 2);
2517 TREE_OPERAND (expr, 2) = tmp;
2520 /* Both arms are empty; replace the COND_EXPR with its predicate. */
2521 expr = TREE_OPERAND (expr, 0);
2527 /* Gimplify the MODIFY_EXPR node pointed by EXPR_P.
2533 PRE_P points to the list where side effects that must happen before
2534 *EXPR_P should be stored.
2536 POST_P points to the list where side effects that must happen after
2537 *EXPR_P should be stored.
2539 WANT_VALUE is nonzero iff we want to use the value of this expression
2540 in another expression. */
2542 static enum gimplify_status
2543 gimplify_modify_expr (tree *expr_p, tree *pre_p, tree *post_p, bool want_value)
2545 tree *from_p = &TREE_OPERAND (*expr_p, 1);
2546 tree *to_p = &TREE_OPERAND (*expr_p, 0);
2547 enum gimplify_status ret = GS_UNHANDLED;
2549 #if defined ENABLE_CHECKING
2550 if (TREE_CODE (*expr_p) != MODIFY_EXPR && TREE_CODE (*expr_p) != INIT_EXPR)
2554 /* The distinction between MODIFY_EXPR and INIT_EXPR is no longer useful. */
2555 if (TREE_CODE (*expr_p) == INIT_EXPR)
2556 TREE_SET_CODE (*expr_p, MODIFY_EXPR);
2558 /* See if any simplifications can be done based on what the RHS is. */
2559 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
2561 if (ret != GS_UNHANDLED)
2564 /* If the value being copied is of variable width, expose the length
2565 if the copy by converting the whole thing to a memcpy. Note that
2566 we need to do this before gimplifying any of the operands
2567 so that we can resolve any PLACEHOLDER_EXPRs in the size. */
2568 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p))) != INTEGER_CST)
2572 t = TYPE_SIZE_UNIT (TREE_TYPE (*to_p));
2573 t = SUBSTITUTE_PLACEHOLDER_IN_EXPR (t, *to_p);
2574 t = SUBSTITUTE_PLACEHOLDER_IN_EXPR (t, *from_p);
2575 t = unshare_expr (t);
2576 args = tree_cons (NULL, t, NULL);
2577 t = build_fold_addr_expr (*from_p);
2578 args = tree_cons (NULL, t, args);
2579 dest = build_fold_addr_expr (*to_p);
2580 args = tree_cons (NULL, dest, args);
2581 t = implicit_built_in_decls[BUILT_IN_MEMCPY];
2582 t = build_function_call_expr (t, args);
2585 t = build1 (NOP_EXPR, TREE_TYPE (dest), t);
2586 t = build1 (INDIRECT_REF, TREE_TYPE (*to_p), t);
2592 ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_lvalue, fb_lvalue);
2593 if (ret == GS_ERROR)
2596 ret = gimplify_expr (from_p, pre_p, post_p, is_gimple_rhs, fb_rvalue);
2597 if (ret == GS_ERROR)
2600 /* Now see if the above changed *from_p to something we handle specially. */
2601 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
2603 if (ret != GS_UNHANDLED)
2606 /* If the destination is already simple, nothing else needed. */
2607 if (is_gimple_tmp_var (*to_p))
2611 /* If the RHS of the MODIFY_EXPR may throw or make a nonlocal goto and
2612 the LHS is a user variable, then we need to introduce a temporary.
2613 ie temp = RHS; LHS = temp.
2615 This way the optimizers can determine that the user variable is
2616 only modified if evaluation of the RHS does not throw.
2618 FIXME this should be handled by the is_gimple_rhs predicate. */
2620 if (aggregate_value_p (TREE_TYPE (*from_p), NULL_TREE))
2621 /* Don't force a temp of a large aggregate type; the copy could be
2622 arbitrarily expensive. Instead we will generate a V_MAY_DEF for
2624 else if (TREE_CODE (*from_p) == CALL_EXPR
2625 || (flag_non_call_exceptions && tree_could_trap_p (*from_p))
2626 /* If we're dealing with a renamable type, either source or dest
2627 must be a renamed variable. */
2628 || (is_gimple_reg_type (TREE_TYPE (*from_p))
2629 && !is_gimple_reg (*to_p)))
2630 gimplify_expr (from_p, pre_p, post_p, is_gimple_val, fb_rvalue);
2632 ret = want_value ? GS_OK : GS_ALL_DONE;
2637 append_to_statement_list (*expr_p, pre_p);
2644 /* Subroutine of above to do simplifications of MODIFY_EXPRs based on
2645 the code of the RHS. We loop for as long as we can do something. */
2647 static enum gimplify_status
2648 gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, tree *pre_p,
2649 tree *post_p, bool want_value)
2651 enum gimplify_status ret = GS_OK;
2653 while (ret != GS_UNHANDLED)
2654 switch (TREE_CODE (*from_p))
2658 /* If we are initializing something from a TARGET_EXPR, strip the
2659 TARGET_EXPR and initialize it directly, if possible. This can't
2660 be done if the initializer is void, since that implies that the
2661 temporary is set in some non-trivial way.
2663 ??? What about code that pulls out the temp and uses it
2664 elsewhere? I think that such code never uses the TARGET_EXPR as
2665 an initializer. If I'm wrong, we'll abort because the temp won't
2666 have any RTL. In that case, I guess we'll need to replace
2667 references somehow. */
2668 tree init = TARGET_EXPR_INITIAL (*from_p);
2670 if (!VOID_TYPE_P (TREE_TYPE (init)))
2681 /* Remove any COMPOUND_EXPR in the RHS so the following cases will be
2683 gimplify_compound_expr (from_p, pre_p, true);
2688 /* If we're initializing from a CONSTRUCTOR, break this into
2689 individual MODIFY_EXPRs. */
2690 return gimplify_init_constructor (expr_p, pre_p, post_p, want_value);
2693 /* If we're assigning from a ?: expression with ADDRESSABLE type, push
2694 the assignment down into the branches, since we can't generate a
2695 temporary of such a type. */
2696 if (TREE_ADDRESSABLE (TREE_TYPE (*from_p)))
2699 return gimplify_cond_expr (expr_p, pre_p, *to_p);
2713 /* Gimplify a comparison between two variable-sized objects. Do this
2714 with a call to BUILT_IN_MEMCMP. */
2716 static enum gimplify_status
2717 gimplify_variable_sized_compare (tree *expr_p)
2719 tree op0 = TREE_OPERAND (*expr_p, 0);
2720 tree op1 = TREE_OPERAND (*expr_p, 1);
2723 t = TYPE_SIZE_UNIT (TREE_TYPE (op0));
2724 t = SUBSTITUTE_PLACEHOLDER_IN_EXPR (t, op0);
2725 t = unshare_expr (t);
2726 args = tree_cons (NULL, t, NULL);
2727 t = build_fold_addr_expr (op1);
2728 args = tree_cons (NULL, t, args);
2729 dest = build_fold_addr_expr (op0);
2730 args = tree_cons (NULL, dest, args);
2731 t = implicit_built_in_decls[BUILT_IN_MEMCMP];
2732 t = build_function_call_expr (t, args);
2734 = build (TREE_CODE (*expr_p), TREE_TYPE (*expr_p), t, integer_zero_node);
2739 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P
2740 points to the expression to gimplify.
2742 Expressions of the form 'a && b' are gimplified to:
2744 a && b ? true : false
2746 gimplify_cond_expr will do the rest.
2748 PRE_P points to the list where side effects that must happen before
2749 *EXPR_P should be stored. */
2751 static enum gimplify_status
2752 gimplify_boolean_expr (tree *expr_p)
2754 /* Preserve the original type of the expression. */
2755 tree type = TREE_TYPE (*expr_p);
2757 *expr_p = build (COND_EXPR, type, *expr_p,
2758 convert (type, boolean_true_node),
2759 convert (type, boolean_false_node));
2764 /* Gimplifies an expression sequence. This function gimplifies each
2765 expression and re-writes the original expression with the last
2766 expression of the sequence in GIMPLE form.
2768 PRE_P points to the list where the side effects for all the
2769 expressions in the sequence will be emitted.
2771 WANT_VALUE is true when the result of the last COMPOUND_EXPR is used. */
2772 /* ??? Should rearrange to share the pre-queue with all the indirect
2773 invocations of gimplify_expr. Would probably save on creations
2774 of statement_list nodes. */
2776 static enum gimplify_status
2777 gimplify_compound_expr (tree *expr_p, tree *pre_p, bool want_value)
2783 tree *sub_p = &TREE_OPERAND (t, 0);
2785 if (TREE_CODE (*sub_p) == COMPOUND_EXPR)
2786 gimplify_compound_expr (sub_p, pre_p, false);
2788 gimplify_stmt (sub_p);
2789 append_to_statement_list (*sub_p, pre_p);
2791 t = TREE_OPERAND (t, 1);
2793 while (TREE_CODE (t) == COMPOUND_EXPR);
2800 gimplify_stmt (expr_p);
2805 /* Gimplifies a statement list. These may be created either by an
2806 enlightened front-end, or by shortcut_cond_expr. */
2808 static enum gimplify_status
2809 gimplify_statement_list (tree *expr_p)
2811 tree_stmt_iterator i = tsi_start (*expr_p);
2813 while (!tsi_end_p (i))
2817 gimplify_stmt (tsi_stmt_ptr (i));
2822 else if (TREE_CODE (t) == STATEMENT_LIST)
2824 tsi_link_before (&i, t, TSI_SAME_STMT);
2834 /* Gimplify a SAVE_EXPR node. EXPR_P points to the expression to
2835 gimplify. After gimplification, EXPR_P will point to a new temporary
2836 that holds the original value of the SAVE_EXPR node.
2838 PRE_P points to the list where side effects that must happen before
2839 *EXPR_P should be stored. */
2841 static enum gimplify_status
2842 gimplify_save_expr (tree *expr_p, tree *pre_p, tree *post_p)
2844 enum gimplify_status ret = GS_ALL_DONE;
2847 #if defined ENABLE_CHECKING
2848 if (TREE_CODE (*expr_p) != SAVE_EXPR)
2852 val = TREE_OPERAND (*expr_p, 0);
2854 /* If the operand is already a GIMPLE temporary, just re-write the
2856 if (is_gimple_tmp_var (val))
2858 /* The operand may be a void-valued expression such as SAVE_EXPRs
2859 generated by the Java frontend for class initialization. It is
2860 being executed only for its side-effects. */
2861 else if (TREE_TYPE (val) == void_type_node)
2863 tree body = TREE_OPERAND (*expr_p, 0);
2864 ret = gimplify_expr (& body, pre_p, post_p, is_gimple_stmt, fb_none);
2865 append_to_statement_list (body, pre_p);
2869 *expr_p = TREE_OPERAND (*expr_p, 0)
2870 = get_initialized_tmp_var (val, pre_p, post_p);
2875 /* Re-write the ADDR_EXPR node pointed by EXPR_P
2882 PRE_P points to the list where side effects that must happen before
2883 *EXPR_P should be stored.
2885 POST_P points to the list where side effects that must happen after
2886 *EXPR_P should be stored. */
2888 static enum gimplify_status
2889 gimplify_addr_expr (tree *expr_p, tree *pre_p, tree *post_p)
2891 tree expr = *expr_p;
2892 tree op0 = TREE_OPERAND (expr, 0);
2893 enum gimplify_status ret;
2895 switch (TREE_CODE (op0))
2898 /* Check if we are dealing with an expression of the form '&*ptr'.
2899 While the front end folds away '&*ptr' into 'ptr', these
2900 expressions may be generated internally by the compiler (e.g.,
2901 builtins like __builtin_va_end). */
2902 *expr_p = TREE_OPERAND (op0, 0);
2907 /* Fold &a[6] to (&a + 6). */
2908 ret = gimplify_array_ref_to_plus (&TREE_OPERAND (expr, 0),
2911 /* This added an INDIRECT_REF. Fold it away. */
2912 *expr_p = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
2915 case VIEW_CONVERT_EXPR:
2916 /* Take the address of our operand and then convert it to the type of
2919 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
2920 all clear. The impact of this transformation is even less clear. */
2921 *expr_p = fold_convert (TREE_TYPE (expr),
2922 build_fold_addr_expr (TREE_OPERAND (op0, 0)));
2927 /* We use fb_either here because the C frontend sometimes takes
2928 the address of a call that returns a struct. */
2929 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p,
2930 is_gimple_addr_expr_arg, fb_either);
2931 if (ret != GS_ERROR)
2933 /* At this point, the argument of the ADDR_EXPR should be
2934 sufficiently simple that there are never side effects. */
2935 /* ??? Could split out the decision code from build1 to verify. */
2936 TREE_SIDE_EFFECTS (expr) = 0;
2938 /* Make sure TREE_INVARIANT/TREE_CONSTANT is set properly. */
2939 recompute_tree_invarant_for_addr_expr (expr);
2941 /* Mark the RHS addressable. */
2942 lang_hooks.mark_addressable (TREE_OPERAND (expr, 0));
2947 /* If the operand is gimplified into a _DECL, mark the address expression
2948 as TREE_INVARIANT. */
2949 if (DECL_P (TREE_OPERAND (expr, 0)))
2950 TREE_INVARIANT (expr) = 1;
2955 /* Gimplify the operands of an ASM_EXPR. Input operands should be a gimple
2956 value; output operands should be a gimple lvalue. */
2958 static enum gimplify_status
2959 gimplify_asm_expr (tree *expr_p, tree *pre_p, tree *post_p)
2961 tree expr = *expr_p;
2962 int noutputs = list_length (ASM_OUTPUTS (expr));
2963 const char **oconstraints
2964 = (const char **) alloca ((noutputs) * sizeof (const char *));
2967 const char *constraint;
2968 bool allows_mem, allows_reg, is_inout;
2969 enum gimplify_status ret, tret;
2972 = resolve_asm_operand_names (ASM_STRING (expr), ASM_OUTPUTS (expr),
2976 for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = TREE_CHAIN (link))
2978 oconstraints[i] = constraint
2979 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
2981 parse_output_constraint (&constraint, i, 0, 0,
2982 &allows_mem, &allows_reg, &is_inout);
2984 if (!allows_reg && allows_mem)
2985 lang_hooks.mark_addressable (TREE_VALUE (link));
2987 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
2988 is_inout ? is_gimple_min_lval : is_gimple_lvalue,
2989 fb_lvalue | fb_mayfail);
2990 if (tret == GS_ERROR)
2992 error ("invalid lvalue in asm output %d", i);
2998 /* An input/output operand. To give the optimizers more
2999 flexibility, split it into separate input and output
3003 size_t constraint_len = strlen (constraint);
3005 /* Turn the in/out constraint into an output constraint. */
3006 char *p = xstrdup (constraint);
3008 TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p);
3011 /* And add a matching input constraint. */
3014 sprintf (buf, "%d", i);
3015 input = build_string (strlen (buf), buf);
3018 input = build_string (constraint_len - 1, constraint + 1);
3019 input = build_tree_list (build_tree_list (NULL_TREE, input),
3020 unshare_expr (TREE_VALUE (link)));
3021 ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input);
3025 for (link = ASM_INPUTS (expr); link; ++i, link = TREE_CHAIN (link))
3028 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
3029 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
3030 oconstraints, &allows_mem, &allows_reg);
3032 /* If the operand is a memory input, it should be an lvalue. */
3033 if (!allows_reg && allows_mem)
3035 lang_hooks.mark_addressable (TREE_VALUE (link));
3036 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
3037 is_gimple_lvalue, fb_lvalue | fb_mayfail);
3038 if (tret == GS_ERROR)
3040 error ("memory input %d is not directly addressable", i);
3046 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
3047 is_gimple_val, fb_rvalue);
3048 if (tret == GS_ERROR)
3056 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding
3057 WITH_CLEANUP_EXPRs to the prequeue as we encounter cleanups while
3058 gimplifying the body, and converting them to TRY_FINALLY_EXPRs when we
3059 return to this function.
3061 FIXME should we complexify the prequeue handling instead? Or use flags
3062 for all the cleanups and let the optimizer tighten them up? The current
3063 code seems pretty fragile; it will break on a cleanup within any
3064 non-conditional nesting. But any such nesting would be broken, anyway;
3065 we can't write a TRY_FINALLY_EXPR that starts inside a nesting construct
3066 and continues out of it. We can do that at the RTL level, though, so
3067 having an optimizer to tighten up try/finally regions would be a Good
3070 static enum gimplify_status
3071 gimplify_cleanup_point_expr (tree *expr_p, tree *pre_p)
3073 tree_stmt_iterator iter;
3076 tree temp = voidify_wrapper_expr (*expr_p, NULL);
3078 /* We only care about the number of conditions between the innermost
3079 CLEANUP_POINT_EXPR and the cleanup. So save and reset the count. */
3080 int old_conds = gimplify_ctxp->conditions;
3081 gimplify_ctxp->conditions = 0;
3083 body = TREE_OPERAND (*expr_p, 0);
3084 gimplify_to_stmt_list (&body);
3086 gimplify_ctxp->conditions = old_conds;
3088 for (iter = tsi_start (body); !tsi_end_p (iter); )
3090 tree *wce_p = tsi_stmt_ptr (iter);
3093 if (TREE_CODE (wce) == WITH_CLEANUP_EXPR)
3095 if (tsi_one_before_end_p (iter))
3097 tsi_link_before (&iter, TREE_OPERAND (wce, 1), TSI_SAME_STMT);
3105 sl = tsi_split_statement_list_after (&iter);
3106 tfe = build (TRY_FINALLY_EXPR, void_type_node, sl, NULL_TREE);
3107 append_to_statement_list (TREE_OPERAND (wce, 1),
3108 &TREE_OPERAND (tfe, 1));
3110 iter = tsi_start (sl);
3120 append_to_statement_list (body, pre_p);
3130 /* Insert a cleanup marker for gimplify_cleanup_point_expr. CLEANUP
3131 is the cleanup action required. */
3134 gimple_push_cleanup (tree var, tree cleanup, tree *pre_p)
3138 /* Errors can result in improperly nested cleanups. Which results in
3139 confusion when trying to resolve the WITH_CLEANUP_EXPR. */
3140 if (errorcount || sorrycount)
3143 if (gimple_conditional_context ())
3145 /* If we're in a conditional context, this is more complex. We only
3146 want to run the cleanup if we actually ran the initialization that
3147 necessitates it, but we want to run it after the end of the
3148 conditional context. So we wrap the try/finally around the
3149 condition and use a flag to determine whether or not to actually
3150 run the destructor. Thus
3154 becomes (approximately)
3158 if (test) { A::A(temp); flag = 1; val = f(temp); }
3161 if (flag) A::~A(temp);
3166 tree flag = create_tmp_var (boolean_type_node, "cleanup");
3167 tree ffalse = build (MODIFY_EXPR, void_type_node, flag,
3168 boolean_false_node);
3169 tree ftrue = build (MODIFY_EXPR, void_type_node, flag,
3171 cleanup = build (COND_EXPR, void_type_node, flag, cleanup, NULL);
3172 wce = build (WITH_CLEANUP_EXPR, void_type_node, NULL_TREE,
3173 cleanup, NULL_TREE);
3174 append_to_statement_list (ffalse, &gimplify_ctxp->conditional_cleanups);
3175 append_to_statement_list (wce, &gimplify_ctxp->conditional_cleanups);
3176 append_to_statement_list (ftrue, pre_p);
3178 /* Because of this manipulation, and the EH edges that jump
3179 threading cannot redirect, the temporary (VAR) will appear
3180 to be used uninitialized. Don't warn. */
3181 TREE_NO_WARNING (var) = 1;
3185 wce = build (WITH_CLEANUP_EXPR, void_type_node, NULL_TREE,
3186 cleanup, NULL_TREE);
3187 append_to_statement_list (wce, pre_p);
3190 gimplify_stmt (&TREE_OPERAND (wce, 1));
3193 /* Gimplify a TARGET_EXPR which doesn't appear on the rhs of an INIT_EXPR. */
3195 static enum gimplify_status
3196 gimplify_target_expr (tree *expr_p, tree *pre_p, tree *post_p)
3198 tree targ = *expr_p;
3199 tree temp = TARGET_EXPR_SLOT (targ);
3200 tree init = TARGET_EXPR_INITIAL (targ);
3201 enum gimplify_status ret;
3205 /* TARGET_EXPR temps aren't part of the enclosing block, so add it
3206 to the temps list. */
3207 gimple_add_tmp_var (temp);
3209 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
3210 expression is supposed to initialize the slot. */
3211 if (VOID_TYPE_P (TREE_TYPE (init)))
3212 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none);
3215 /* Special handling for BIND_EXPR can result in fewer temps. */
3217 if (TREE_CODE (init) == BIND_EXPR)
3218 gimplify_bind_expr (&init, temp, pre_p);
3221 init = build (MODIFY_EXPR, void_type_node, temp, init);
3222 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt,
3226 if (ret == GS_ERROR)
3228 append_to_statement_list (init, pre_p);
3230 /* If needed, push the cleanup for the temp. */
3231 if (TARGET_EXPR_CLEANUP (targ))
3233 gimplify_stmt (&TARGET_EXPR_CLEANUP (targ));
3234 gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ), pre_p);
3237 /* Only expand this once. */
3238 TREE_OPERAND (targ, 3) = init;
3239 TARGET_EXPR_INITIAL (targ) = NULL_TREE;
3241 else if (!temp->decl.seen_in_bind_expr)
3242 /* We should have expanded this before. */
3249 /* Gimplification of expression trees. */
3251 /* Gimplify an expression which appears at statement context; usually, this
3252 means replacing it with a suitably gimple STATEMENT_LIST. */
3255 gimplify_stmt (tree *stmt_p)
3257 gimplify_expr (stmt_p, NULL, NULL, is_gimple_stmt, fb_none);
3260 /* Similarly, but force the result to be a STATEMENT_LIST. */
3263 gimplify_to_stmt_list (tree *stmt_p)
3265 gimplify_stmt (stmt_p);
3267 *stmt_p = alloc_stmt_list ();
3268 else if (TREE_CODE (*stmt_p) != STATEMENT_LIST)
3271 *stmt_p = alloc_stmt_list ();
3272 append_to_statement_list (t, stmt_p);
3277 /* Gimplifies the expression tree pointed by EXPR_P. Return 0 if
3278 gimplification failed.
3280 PRE_P points to the list where side effects that must happen before
3281 EXPR should be stored.
3283 POST_P points to the list where side effects that must happen after
3284 EXPR should be stored, or NULL if there is no suitable list. In
3285 that case, we copy the result to a temporary, emit the
3286 post-effects, and then return the temporary.
3288 GIMPLE_TEST_F points to a function that takes a tree T and
3289 returns nonzero if T is in the GIMPLE form requested by the
3290 caller. The GIMPLE predicates are in tree-gimple.c.
3292 This test is used twice. Before gimplification, the test is
3293 invoked to determine whether *EXPR_P is already gimple enough. If
3294 that fails, *EXPR_P is gimplified according to its code and
3295 GIMPLE_TEST_F is called again. If the test still fails, then a new
3296 temporary variable is created and assigned the value of the
3297 gimplified expression.
3299 FALLBACK tells the function what sort of a temporary we want. If the 1
3300 bit is set, an rvalue is OK. If the 2 bit is set, an lvalue is OK.
3301 If both are set, either is OK, but an lvalue is preferable.
3303 The return value is either GS_ERROR or GS_ALL_DONE, since this function
3304 iterates until solution. */
3306 enum gimplify_status
3307 gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p,
3308 bool (* gimple_test_f) (tree), fallback_t fallback)
3311 tree internal_pre = NULL_TREE;
3312 tree internal_post = NULL_TREE;
3314 int is_statement = (pre_p == NULL);
3316 location_t saved_location;
3317 enum gimplify_status ret;
3319 save_expr = *expr_p;
3320 if (save_expr == NULL_TREE)
3323 /* We used to check the predicate here and return immediately if it
3324 succeeds. This is wrong; the design is for gimplification to be
3325 idempotent, and for the predicates to only test for valid forms, not
3326 whether they are fully simplified. */
3328 /* Set up our internal queues if needed. */
3330 pre_p = &internal_pre;
3332 post_p = &internal_post;
3334 saved_location = input_location;
3335 if (save_expr == error_mark_node)
3338 locus = EXPR_LOCUS (save_expr);
3340 input_location = *locus;
3342 /* Loop over the specific gimplifiers until the toplevel node
3343 remains the same. */
3346 /* Strip any uselessness. */
3347 STRIP_MAIN_TYPE_NOPS (*expr_p);
3349 /* Remember the expr. */
3350 save_expr = *expr_p;
3352 /* Die, die, die, my darling. */
3353 if (save_expr == error_mark_node
3354 || (TREE_TYPE (save_expr)
3355 && TREE_TYPE (save_expr) == error_mark_node))
3361 /* Do any language-specific gimplification. */
3362 ret = lang_hooks.gimplify_expr (expr_p, pre_p, post_p);
3365 if (*expr_p == NULL_TREE)
3367 if (*expr_p != save_expr)
3370 else if (ret != GS_UNHANDLED)
3374 switch (TREE_CODE (*expr_p))
3376 /* First deal with the special cases. */
3378 case POSTINCREMENT_EXPR:
3379 case POSTDECREMENT_EXPR:
3380 case PREINCREMENT_EXPR:
3381 case PREDECREMENT_EXPR:
3382 ret = gimplify_self_mod_expr (expr_p, pre_p, post_p,
3383 fallback != fb_none);
3387 case ARRAY_RANGE_REF:
3391 ret = gimplify_compound_lval (expr_p, pre_p, post_p,
3392 fallback & fb_lvalue);
3396 ret = gimplify_cond_expr (expr_p, pre_p, NULL_TREE);
3400 ret = gimplify_call_expr (expr_p, pre_p, gimple_test_f);
3407 ret = gimplify_compound_expr (expr_p, pre_p, fallback != fb_none);
3412 ret = gimplify_modify_expr (expr_p, pre_p, post_p,
3413 fallback != fb_none);
3416 case TRUTH_ANDIF_EXPR:
3417 case TRUTH_ORIF_EXPR:
3418 ret = gimplify_boolean_expr (expr_p);
3421 case TRUTH_NOT_EXPR:
3422 TREE_OPERAND (*expr_p, 0)
3423 = gimple_boolify (TREE_OPERAND (*expr_p, 0));
3424 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3425 is_gimple_val, fb_rvalue);
3426 recalculate_side_effects (*expr_p);
3430 ret = gimplify_addr_expr (expr_p, pre_p, post_p);
3434 ret = gimplify_va_arg_expr (expr_p, pre_p, post_p);
3437 case VIEW_CONVERT_EXPR:
3438 if (VOID_TYPE_P (TREE_TYPE (*expr_p))
3439 || fallback == fb_none)
3441 /* Just strip a conversion to void (or in void context) and
3443 *expr_p = TREE_OPERAND (*expr_p, 0);
3447 /* If both types are BLKmode or if one type is of variable size,
3448 convert this into a pointer punning operation. This avoids
3449 copies of large data or making a variable-size temporary.
3451 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
3452 all clear. The impact of this transformation is even less
3455 if ((TYPE_MODE (TREE_TYPE (*expr_p)) == BLKmode
3456 && TYPE_MODE (TREE_TYPE (TREE_OPERAND (*expr_p, 0))) == BLKmode)
3457 || !TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (*expr_p)))
3458 || !TREE_CONSTANT (TYPE_SIZE (TREE_TYPE
3459 (TREE_OPERAND (*expr_p,0)))))
3461 tree restype = TREE_TYPE (*expr_p);
3462 *expr_p = build1 (INDIRECT_REF, TREE_TYPE (*expr_p),
3463 fold_convert (build_pointer_type (restype),
3464 build_fold_addr_expr
3465 (TREE_OPERAND (*expr_p, 0))));
3472 if (IS_EMPTY_STMT (*expr_p))
3478 if (VOID_TYPE_P (TREE_TYPE (*expr_p))
3479 || fallback == fb_none)
3481 /* Just strip a conversion to void (or in void context) and
3483 *expr_p = TREE_OPERAND (*expr_p, 0);
3487 ret = gimplify_conversion (expr_p);
3488 if (ret == GS_ERROR)
3490 if (*expr_p != save_expr)
3494 case FIX_TRUNC_EXPR:
3496 case FIX_FLOOR_EXPR:
3497 case FIX_ROUND_EXPR:
3499 /* unary_expr: ... | '(' cast ')' val | ... */
3500 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3501 is_gimple_val, fb_rvalue);
3502 recalculate_side_effects (*expr_p);
3506 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3507 is_gimple_reg, fb_rvalue);
3508 recalculate_side_effects (*expr_p);
3511 /* Constants need not be gimplified. */
3521 *expr_p = DECL_INITIAL (*expr_p);
3525 /* FIXME make this a decl. */
3530 ret = gimplify_bind_expr (expr_p, NULL, pre_p);
3534 ret = gimplify_loop_expr (expr_p, pre_p);
3538 ret = gimplify_switch_expr (expr_p, pre_p);
3541 case LABELED_BLOCK_EXPR:
3542 ret = gimplify_labeled_block_expr (expr_p);
3545 case EXIT_BLOCK_EXPR:
3546 ret = gimplify_exit_block_expr (expr_p);
3550 ret = gimplify_exit_expr (expr_p);
3554 /* If the target is not LABEL, then it is a computed jump
3555 and the target needs to be gimplified. */
3556 if (TREE_CODE (GOTO_DESTINATION (*expr_p)) != LABEL_DECL)
3557 ret = gimplify_expr (&GOTO_DESTINATION (*expr_p), pre_p,
3558 NULL, is_gimple_val, fb_rvalue);
3563 #ifdef ENABLE_CHECKING
3564 if (decl_function_context (LABEL_EXPR_LABEL (*expr_p)) != current_function_decl)
3569 case CASE_LABEL_EXPR:
3570 ret = gimplify_case_label_expr (expr_p);
3574 ret = gimplify_return_expr (*expr_p, pre_p);
3578 /* Don't reduce this in place; let gimplify_init_constructor work
3583 /* The following are special cases that are not handled by the
3584 original GIMPLE grammar. */
3586 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
3589 ret = gimplify_save_expr (expr_p, pre_p, post_p);
3594 enum gimplify_status r0, r1, r2;
3596 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3597 is_gimple_min_lval, fb_either);
3598 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
3599 is_gimple_val, fb_rvalue);
3600 r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p, post_p,
3601 is_gimple_val, fb_rvalue);
3602 recalculate_side_effects (*expr_p);
3604 ret = MIN (r0, MIN (r1, r2));
3608 case NON_LVALUE_EXPR:
3609 /* This should have been stripped above. */
3614 ret = gimplify_asm_expr (expr_p, pre_p, post_p);
3617 case TRY_FINALLY_EXPR:
3618 case TRY_CATCH_EXPR:
3619 gimplify_to_stmt_list (&TREE_OPERAND (*expr_p, 0));
3620 gimplify_to_stmt_list (&TREE_OPERAND (*expr_p, 1));
3624 case CLEANUP_POINT_EXPR:
3625 ret = gimplify_cleanup_point_expr (expr_p, pre_p);
3629 ret = gimplify_target_expr (expr_p, pre_p, post_p);
3633 gimplify_to_stmt_list (&CATCH_BODY (*expr_p));
3637 case EH_FILTER_EXPR:
3638 gimplify_to_stmt_list (&EH_FILTER_FAILURE (*expr_p));
3644 enum gimplify_status r0, r1;
3645 r0 = gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p), pre_p, post_p,
3646 is_gimple_val, fb_rvalue);
3647 r1 = gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p), pre_p, post_p,
3648 is_gimple_val, fb_rvalue);
3655 ret = gimplify_minimax_expr (expr_p, pre_p, post_p);
3659 /* We get here when taking the address of a label. We mark
3660 the label as "forced"; meaning it can never be removed and
3661 it is a potential target for any computed goto. */
3662 FORCED_LABEL (*expr_p) = 1;
3666 case STATEMENT_LIST:
3667 ret = gimplify_statement_list (expr_p);
3671 /* ??? If this is a local variable, and it has not been seen in any
3672 outer BIND_EXPR, then it's probably the result of a duplicate
3673 declaration, for which we've already issued an error. It would
3674 be really nice if the front end wouldn't leak these at all.
3675 Currently the only known culprit is C++ destructors, as seen
3676 in g++.old-deja/g++.jason/binding.C. */
3678 if (!TREE_STATIC (tmp) && !DECL_EXTERNAL (tmp)
3679 && decl_function_context (tmp) == current_function_decl
3680 && !tmp->decl.seen_in_bind_expr)
3682 #ifdef ENABLE_CHECKING
3683 if (!errorcount && !sorrycount)
3693 /* If this is a comparison of objects of aggregate type, handle
3694 it specially (by converting to a call to memcmp). It would be
3695 nice to only have to do this for variable-sized objects, but
3696 then we'd have to allow the same nest of reference nodes we
3697 allow for MODIFY_EXPR and that's too complex. */
3698 if (TREE_CODE_CLASS (TREE_CODE (*expr_p)) == '<'
3699 && (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (*expr_p, 1)))))
3700 ret = gimplify_variable_sized_compare (expr_p);
3702 /* If *EXPR_P does not need to be special-cased, handle it
3703 according to its class. */
3704 else if (TREE_CODE_CLASS (TREE_CODE (*expr_p)) == '1')
3705 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
3706 post_p, is_gimple_val, fb_rvalue);
3707 else if (TREE_CODE_CLASS (TREE_CODE (*expr_p)) == '2'
3708 || TREE_CODE_CLASS (TREE_CODE (*expr_p)) == '<'
3709 || TREE_CODE (*expr_p) == TRUTH_AND_EXPR
3710 || TREE_CODE (*expr_p) == TRUTH_OR_EXPR
3711 || TREE_CODE (*expr_p) == TRUTH_XOR_EXPR)
3713 enum gimplify_status r0, r1;
3715 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
3716 post_p, is_gimple_val, fb_rvalue);
3717 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
3718 post_p, is_gimple_val, fb_rvalue);
3722 else if (TREE_CODE_CLASS (TREE_CODE (*expr_p)) == 'd'
3723 || TREE_CODE_CLASS (TREE_CODE (*expr_p)) == 'c')
3729 /* Fail if we don't know how to handle this tree code. */
3732 recalculate_side_effects (*expr_p);
3736 /* If we replaced *expr_p, gimplify again. */
3737 if (ret == GS_OK && (*expr_p == NULL || *expr_p == save_expr))
3740 while (ret == GS_OK);
3742 /* If we encountered an error_mark somewhere nested inside, either
3743 stub out the statement or propagate the error back out. */
3744 if (ret == GS_ERROR)
3751 #ifdef ENABLE_CHECKING
3752 /* This was only valid as a return value from the langhook, which
3753 we handled. Make sure it doesn't escape from any other context. */
3754 if (ret == GS_UNHANDLED)
3758 if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p))
3760 /* We aren't looking for a value, and we don't have a valid
3761 statement. If it doesn't have side-effects, throw it away. */
3762 if (!TREE_SIDE_EFFECTS (*expr_p))
3764 else if (!TREE_THIS_VOLATILE (*expr_p))
3766 /* This is probably a _REF that contains something nested that
3767 has side effects. Recurse through the operands to find it. */
3768 enum tree_code code = TREE_CODE (*expr_p);
3770 if (code == COMPONENT_REF
3771 || code == REALPART_EXPR || code == IMAGPART_EXPR)
3772 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3773 gimple_test_f, fallback);
3774 else if (code == ARRAY_REF || code == ARRAY_RANGE_REF)
3776 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3777 gimple_test_f, fallback);
3778 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
3779 gimple_test_f, fallback);
3782 /* Anything else with side-effects
3783 must be converted to a valid statement before we get here. */
3788 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)))
3790 /* Historically, the compiler has treated a bare
3791 reference to a volatile lvalue as forcing a load. */
3792 tree tmp = create_tmp_var (TREE_TYPE (*expr_p), "vol");
3793 *expr_p = build (MODIFY_EXPR, TREE_TYPE (tmp), tmp, *expr_p);
3796 /* We can't do anything useful with a volatile reference to
3797 incomplete type, so just throw it away. */
3801 /* If we are gimplifying at the statement level, we're done. Tack
3802 everything together and replace the original statement with the
3804 if (fallback == fb_none || is_statement)
3806 if (internal_pre || internal_post)
3808 append_to_statement_list (*expr_p, &internal_pre);
3809 append_to_statement_list (internal_post, &internal_pre);
3810 annotate_all_with_locus (&internal_pre, input_location);
3811 *expr_p = internal_pre;
3815 else if (TREE_CODE (*expr_p) == STATEMENT_LIST)
3816 annotate_all_with_locus (expr_p, input_location);
3818 annotate_one_with_locus (*expr_p, input_location);
3822 /* Otherwise we're gimplifying a subexpression, so the resulting value is
3825 /* If it's sufficiently simple already, we're done. Unless we are
3826 handling some post-effects internally; if that's the case, we need to
3827 copy into a temp before adding the post-effects to the tree. */
3828 if (!internal_post && (*gimple_test_f) (*expr_p))
3831 /* Otherwise, we need to create a new temporary for the gimplified
3834 /* We can't return an lvalue if we have an internal postqueue. The
3835 object the lvalue refers to would (probably) be modified by the
3836 postqueue; we need to copy the value out first, which means an
3838 if ((fallback & fb_lvalue) && !internal_post
3839 && is_gimple_addr_expr_arg (*expr_p))
3841 /* An lvalue will do. Take the address of the expression, store it
3842 in a temporary, and replace the expression with an INDIRECT_REF of
3844 tmp = build_fold_addr_expr (*expr_p);
3845 gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue);
3846 *expr_p = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (tmp)), tmp);
3848 else if ((fallback & fb_rvalue) && is_gimple_rhs (*expr_p))
3850 #if defined ENABLE_CHECKING
3851 if (VOID_TYPE_P (TREE_TYPE (*expr_p)))
3855 /* An rvalue will do. Assign the gimplified expression into a new
3856 temporary TMP and replace the original expression with TMP. */
3858 if (internal_post || (fallback & fb_lvalue))
3859 /* The postqueue might change the value of the expression between
3860 the initialization and use of the temporary, so we can't use a
3861 formal temp. FIXME do we care? */
3862 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
3864 *expr_p = get_formal_tmp_var (*expr_p, pre_p);
3866 else if (fallback & fb_mayfail)
3868 /* If this is an asm statement, and the user asked for the impossible,
3869 don't abort. Fail and let gimplify_asm_expr issue an error. */
3875 fprintf (stderr, "gimplification failed:\n");
3876 print_generic_expr (stderr, *expr_p, 0);
3877 debug_tree (*expr_p);
3881 #if defined ENABLE_CHECKING
3882 /* Make sure the temporary matches our predicate. */
3883 if (!(*gimple_test_f) (*expr_p))
3889 annotate_all_with_locus (&internal_post, input_location);
3890 append_to_statement_list (internal_post, pre_p);
3894 input_location = saved_location;
3898 /* Look through TYPE for variable-sized objects and gimplify each such
3899 size that we find. Add to LIST_P any statements generated. */
3902 gimplify_type_sizes (tree type, tree *list_p)
3906 switch (TREE_CODE (type))
3916 gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p);
3917 gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p);
3921 /* These anonymous types don't have declarations, so handle them here. */
3922 gimplify_type_sizes (TYPE_DOMAIN (type), list_p);
3927 case QUAL_UNION_TYPE:
3928 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3929 if (TREE_CODE (field) == FIELD_DECL)
3930 gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p);
3937 gimplify_one_sizepos (&TYPE_SIZE (type), list_p);
3938 gimplify_one_sizepos (&TYPE_SIZE_UNIT (type), list_p);
3941 /* Subroutine of the above to gimplify one size or position, *EXPR_P.
3942 We add any required statements to STMT_P. */
3945 gimplify_one_sizepos (tree *expr_p, tree *stmt_p)
3947 /* We don't do anything if the value isn't there, is constant, or contains
3948 A PLACEHOLDER_EXPR. */
3949 if (*expr_p == NULL_TREE || TREE_CONSTANT (*expr_p)
3950 || CONTAINS_PLACEHOLDER_P (*expr_p))
3953 gimplify_expr (expr_p, stmt_p, NULL, is_gimple_val, fb_rvalue);
3956 #ifdef ENABLE_CHECKING
3957 /* Compare types A and B for a "close enough" match. */
3960 cpt_same_type (tree a, tree b)
3962 if (lang_hooks.types_compatible_p (a, b))
3965 /* ??? The C++ FE decomposes METHOD_TYPES to FUNCTION_TYPES and doesn't
3966 link them together. This routine is intended to catch type errors
3967 that will affect the optimizers, and the optimizers don't add new
3968 dereferences of function pointers, so ignore it. */
3969 if ((TREE_CODE (a) == FUNCTION_TYPE || TREE_CODE (a) == METHOD_TYPE)
3970 && (TREE_CODE (b) == FUNCTION_TYPE || TREE_CODE (b) == METHOD_TYPE))
3973 /* ??? The C FE pushes type qualifiers after the fact into the type of
3974 the element from the type of the array. See build_unary_op's handling
3975 of ADDR_EXPR. This seems wrong -- if we were going to do this, we
3976 should have done it when creating the variable in the first place.
3977 Alternately, why aren't the two array types made variants? */
3978 if (TREE_CODE (a) == ARRAY_TYPE && TREE_CODE (b) == ARRAY_TYPE)
3979 return cpt_same_type (TREE_TYPE (a), TREE_TYPE (b));
3981 /* And because of those, we have to recurse down through pointers. */
3982 if (POINTER_TYPE_P (a) && POINTER_TYPE_P (b))
3983 return cpt_same_type (TREE_TYPE (a), TREE_TYPE (b));
3988 /* Check for some cases of the front end missing cast expressions.
3989 The type of a dereference should correspond to the pointer type;
3990 similarly the type of an address should match its object. */
3993 check_pointer_types_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
3994 void *data ATTRIBUTE_UNUSED)
3997 tree ptype, otype, dtype;
3999 switch (TREE_CODE (t))
4003 otype = TREE_TYPE (t);
4004 ptype = TREE_TYPE (TREE_OPERAND (t, 0));
4005 dtype = TREE_TYPE (ptype);
4006 if (!cpt_same_type (otype, dtype))
4011 ptype = TREE_TYPE (t);
4012 otype = TREE_TYPE (TREE_OPERAND (t, 0));
4013 dtype = TREE_TYPE (ptype);
4014 if (!cpt_same_type (otype, dtype))
4016 /* &array is allowed to produce a pointer to the element, rather than
4017 a pointer to the array type. We must allow this in order to
4018 properly represent assigning the address of an array in C into
4019 pointer to the element type. */
4020 if (TREE_CODE (otype) == ARRAY_TYPE
4021 && POINTER_TYPE_P (ptype)
4022 && cpt_same_type (TREE_TYPE (otype), dtype))
4037 /* Gimplify the body of statements pointed by BODY_P. FNDECL is the
4038 function decl containing BODY. */
4041 gimplify_body (tree *body_p, tree fndecl)
4043 location_t saved_location = input_location;
4046 timevar_push (TV_TREE_GIMPLIFY);
4047 push_gimplify_context ();
4049 /* Unshare most shared trees in the body and in that of any nested functions.
4050 It would seem we don't have to do this for nested functions because
4051 they are supposed to be output and then the outer function gimplified
4052 first, but the g++ front end doesn't always do it that way. */
4053 unshare_body (body_p, fndecl);
4054 unvisit_body (body_p, fndecl);
4056 /* Make sure input_location isn't set to something wierd. */
4057 input_location = DECL_SOURCE_LOCATION (fndecl);
4059 /* Gimplify the function's body. */
4060 gimplify_stmt (body_p);
4063 /* Unshare again, in case gimplification was sloppy. */
4064 unshare_all_trees (body);
4067 body = alloc_stmt_list ();
4068 else if (TREE_CODE (body) == STATEMENT_LIST)
4070 tree t = expr_only (*body_p);
4075 /* If there isn't an outer BIND_EXPR, add one. */
4076 if (TREE_CODE (body) != BIND_EXPR)
4078 tree b = build (BIND_EXPR, void_type_node, NULL_TREE,
4079 NULL_TREE, NULL_TREE);
4080 TREE_SIDE_EFFECTS (b) = 1;
4081 append_to_statement_list_force (body, &BIND_EXPR_BODY (b));
4086 pop_gimplify_context (body);
4088 #ifdef ENABLE_CHECKING
4089 walk_tree (body_p, check_pointer_types_r, NULL, NULL);
4092 timevar_pop (TV_TREE_GIMPLIFY);
4093 input_location = saved_location;
4096 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL
4097 node for the function we want to gimplify. */
4100 gimplify_function_tree (tree fndecl)
4104 oldfn = current_function_decl;
4105 current_function_decl = fndecl;
4107 gimplify_body (&DECL_SAVED_TREE (fndecl), fndecl);
4109 /* If we're instrumenting function entry/exit, then prepend the call to
4110 the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
4111 catch the exit hook. */
4112 /* ??? Add some way to ignore exceptions for this TFE. */
4113 if (flag_instrument_function_entry_exit
4114 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl))
4118 tf = build (TRY_FINALLY_EXPR, void_type_node, NULL, NULL);
4119 TREE_SIDE_EFFECTS (tf) = 1;
4120 x = DECL_SAVED_TREE (fndecl);
4121 append_to_statement_list (x, &TREE_OPERAND (tf, 0));
4122 x = implicit_built_in_decls[BUILT_IN_PROFILE_FUNC_EXIT];
4123 x = build_function_call_expr (x, NULL);
4124 append_to_statement_list (x, &TREE_OPERAND (tf, 1));
4126 bind = build (BIND_EXPR, void_type_node, NULL, NULL, NULL);
4127 TREE_SIDE_EFFECTS (bind) = 1;
4128 x = implicit_built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER];
4129 x = build_function_call_expr (x, NULL);
4130 append_to_statement_list (x, &BIND_EXPR_BODY (bind));
4131 append_to_statement_list (tf, &BIND_EXPR_BODY (bind));
4133 DECL_SAVED_TREE (fndecl) = bind;
4136 current_function_decl = oldfn;
4139 #include "gt-gimplify.h"