1 /* Top-level control of tree optimizations.
2 Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
33 #include "diagnostic.h"
34 #include "basic-block.h"
36 #include "tree-flow.h"
37 #include "tree-dump.h"
40 #include "langhooks.h"
44 #include "tree-inline.h"
45 #include "tree-mudflap.h"
46 #include "tree-pass.h"
53 /* Global variables used to communicate with passes. */
57 /* The root of the compilation pass tree, once constructed. */
58 static struct tree_opt_pass
*all_passes
, *all_ipa_passes
, *all_lowering_passes
;
60 /* Gate: execute, or not, all of the non-trivial optimizations. */
63 gate_all_optimizations (void)
66 /* Don't bother doing anything if the program has errors. */
67 && !(errorcount
|| sorrycount
));
70 static struct tree_opt_pass pass_all_optimizations
=
73 gate_all_optimizations
, /* gate */
77 0, /* static_pass_number */
79 0, /* properties_required */
80 0, /* properties_provided */
81 0, /* properties_destroyed */
82 0, /* todo_flags_start */
83 0, /* todo_flags_finish */
87 static struct tree_opt_pass pass_early_local_passes
=
90 gate_all_optimizations
, /* gate */
94 0, /* static_pass_number */
96 0, /* properties_required */
97 0, /* properties_provided */
98 0, /* properties_destroyed */
99 0, /* todo_flags_start */
100 0, /* todo_flags_finish */
104 /* Pass: cleanup the CFG just before expanding trees to RTL.
105 This is just a round of label cleanups and case node grouping
106 because after the tree optimizers have run such cleanups may
110 execute_cleanup_cfg_pre_ipa (void)
115 static struct tree_opt_pass pass_cleanup_cfg
=
117 "cleanup_cfg", /* name */
119 execute_cleanup_cfg_pre_ipa
, /* execute */
122 0, /* static_pass_number */
124 PROP_cfg
, /* properties_required */
125 0, /* properties_provided */
126 0, /* properties_destroyed */
127 0, /* todo_flags_start */
128 TODO_dump_func
, /* todo_flags_finish */
133 /* Pass: cleanup the CFG just before expanding trees to RTL.
134 This is just a round of label cleanups and case node grouping
135 because after the tree optimizers have run such cleanups may
139 execute_cleanup_cfg_post_optimizing (void)
142 cleanup_dead_labels ();
143 group_case_labels ();
146 static struct tree_opt_pass pass_cleanup_cfg_post_optimizing
=
148 "final_cleanup", /* name */
150 execute_cleanup_cfg_post_optimizing
, /* execute */
153 0, /* static_pass_number */
155 PROP_cfg
, /* properties_required */
156 0, /* properties_provided */
157 0, /* properties_destroyed */
158 0, /* todo_flags_start */
159 TODO_dump_func
, /* todo_flags_finish */
163 /* Pass: do the actions required to finish with tree-ssa optimization
167 execute_free_datastructures (void)
169 /* ??? This isn't the right place for this. Worse, it got computed
170 more or less at random in various passes. */
171 free_dominance_info (CDI_DOMINATORS
);
172 free_dominance_info (CDI_POST_DOMINATORS
);
174 /* Remove the ssa structures. Do it here since this includes statement
175 annotations that need to be intact during disband_implicit_edges. */
179 static struct tree_opt_pass pass_free_datastructures
=
183 execute_free_datastructures
, /* execute */
186 0, /* static_pass_number */
188 PROP_cfg
, /* properties_required */
189 0, /* properties_provided */
190 0, /* properties_destroyed */
191 0, /* todo_flags_start */
192 0, /* todo_flags_finish */
195 /* Pass: free cfg annotations. */
198 execute_free_cfg_annotations (void)
201 block_stmt_iterator bsi
;
203 /* Emit gotos for implicit jumps. */
204 disband_implicit_edges ();
206 /* Remove annotations from every tree in the function. */
208 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
210 tree stmt
= bsi_stmt (bsi
);
211 ggc_free (stmt
->common
.ann
);
212 stmt
->common
.ann
= NULL
;
215 /* And get rid of annotations we no longer need. */
216 delete_tree_cfg_annotations ();
219 static struct tree_opt_pass pass_free_cfg_annotations
=
223 execute_free_cfg_annotations
, /* execute */
226 0, /* static_pass_number */
228 PROP_cfg
, /* properties_required */
229 0, /* properties_provided */
230 0, /* properties_destroyed */
231 0, /* todo_flags_start */
232 0, /* todo_flags_finish */
235 /* Pass: fixup_cfg - IPA passes or compilation of earlier functions might've
236 changed some properties - such as marked functions nothrow. Remove now
237 redundant edges and basic blocks. */
240 execute_fixup_cfg (void)
243 block_stmt_iterator bsi
;
248 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
250 tree stmt
= bsi_stmt (bsi
);
251 tree call
= get_call_expr_in (stmt
);
253 if (call
&& call_expr_flags (call
) & (ECF_CONST
| ECF_PURE
))
254 TREE_SIDE_EFFECTS (call
) = 0;
255 if (!tree_could_throw_p (stmt
) && lookup_stmt_eh_region (stmt
))
256 remove_stmt_from_eh_region (stmt
);
258 tree_purge_dead_eh_edges (bb
);
264 static struct tree_opt_pass pass_fixup_cfg
=
268 execute_fixup_cfg
, /* execute */
271 0, /* static_pass_number */
273 PROP_cfg
, /* properties_required */
274 0, /* properties_provided */
275 0, /* properties_destroyed */
276 0, /* todo_flags_start */
277 0, /* todo_flags_finish */
281 /* Do the actions required to initialize internal data structures used
282 in tree-ssa optimization passes. */
285 execute_init_datastructures (void)
287 /* Allocate hash tables, arrays and other structures. */
291 static struct tree_opt_pass pass_init_datastructures
=
295 execute_init_datastructures
, /* execute */
298 0, /* static_pass_number */
300 PROP_cfg
, /* properties_required */
301 0, /* properties_provided */
302 0, /* properties_destroyed */
303 0, /* todo_flags_start */
304 0, /* todo_flags_finish */
308 /* Iterate over the pass tree allocating dump file numbers. We want
309 to do this depth first, and independent of whether the pass is
313 register_one_dump_file (struct tree_opt_pass
*pass
, bool ipa
, int n
)
315 char *dot_name
, *flag_name
, *glob_name
;
318 /* See below in next_pass_1. */
320 if (pass
->static_pass_number
!= -1)
321 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
322 ? 1 : pass
->static_pass_number
));
324 dot_name
= concat (".", pass
->name
, num
, NULL
);
327 flag_name
= concat ("ipa-", pass
->name
, num
, NULL
);
328 glob_name
= concat ("ipa-", pass
->name
, NULL
);
329 /* First IPA dump is cgraph that is dumped via separate channels. */
330 pass
->static_pass_number
= dump_register (dot_name
, flag_name
, glob_name
,
333 else if (pass
->properties_provided
& PROP_trees
)
335 flag_name
= concat ("tree-", pass
->name
, num
, NULL
);
336 glob_name
= concat ("tree-", pass
->name
, NULL
);
337 pass
->static_pass_number
= dump_register (dot_name
, flag_name
, glob_name
,
338 TDF_TREE
, n
+ TDI_tree_all
, 0);
342 flag_name
= concat ("rtl-", pass
->name
, num
, NULL
);
343 glob_name
= concat ("rtl-", pass
->name
, NULL
);
344 pass
->static_pass_number
= dump_register (dot_name
, flag_name
, glob_name
,
345 TDF_RTL
, n
, pass
->letter
);
350 register_dump_files (struct tree_opt_pass
*pass
, bool ipa
, int properties
)
358 pass
->properties_required
= properties
;
360 (properties
| pass
->properties_provided
) & ~pass
->properties_destroyed
;
362 /* Reset the counter when we reach RTL-based passes. */
363 if ((pass
->properties_provided
^ pass
->properties_required
) & PROP_rtl
)
371 new_properties
= register_dump_files (pass
->sub
, false, new_properties
);
373 /* If we have a gate, combine the properties that we could have with
374 and without the pass being examined. */
376 properties
&= new_properties
;
378 properties
= new_properties
;
380 pass
->properties_provided
= properties
;
382 register_one_dump_file (pass
, ipa
, pass_number
);
391 /* Add a pass to the pass list. Duplicate the pass if it's already
394 static struct tree_opt_pass
**
395 next_pass_1 (struct tree_opt_pass
**list
, struct tree_opt_pass
*pass
)
398 /* A nonzero static_pass_number indicates that the
399 pass is already in the list. */
400 if (pass
->static_pass_number
)
402 struct tree_opt_pass
*new;
404 new = xmalloc (sizeof (*new));
405 memcpy (new, pass
, sizeof (*new));
407 /* Indicate to register_dump_files that this pass has duplicates,
408 and so it should rename the dump file. The first instance will
409 be -1, and be number of duplicates = -static_pass_number - 1.
410 Subsequent instances will be > 0 and just the duplicate number. */
413 pass
->static_pass_number
-= 1;
414 new->static_pass_number
= -pass
->static_pass_number
;
421 pass
->static_pass_number
= -1;
425 return &(*list
)->next
;
429 /* Construct the pass tree. */
432 init_tree_optimization_passes (void)
434 struct tree_opt_pass
**p
;
436 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
437 /* Interprocedural optimization passes. */
439 NEXT_PASS (pass_early_ipa_inline
);
440 NEXT_PASS (pass_early_local_passes
);
441 NEXT_PASS (pass_ipa_inline
);
444 /* All passes needed to lower the function into shape optimizers can operate
445 on. These passes are performed before interprocedural passes, unlike rest
446 of local passes (all_passes). */
447 p
= &all_lowering_passes
;
448 NEXT_PASS (pass_remove_useless_stmts
);
449 NEXT_PASS (pass_mudflap_1
);
450 NEXT_PASS (pass_lower_cf
);
451 NEXT_PASS (pass_lower_eh
);
452 NEXT_PASS (pass_build_cfg
);
453 NEXT_PASS (pass_lower_complex_O0
);
454 NEXT_PASS (pass_lower_vector
);
455 NEXT_PASS (pass_warn_function_return
);
456 NEXT_PASS (pass_early_tree_profile
);
459 p
= &pass_early_local_passes
.sub
;
460 NEXT_PASS (pass_tree_profile
);
461 NEXT_PASS (pass_cleanup_cfg
);
462 NEXT_PASS (pass_rebuild_cgraph_edges
);
466 NEXT_PASS (pass_fixup_cfg
);
467 NEXT_PASS (pass_init_datastructures
);
468 NEXT_PASS (pass_all_optimizations
);
469 NEXT_PASS (pass_warn_function_noreturn
);
470 NEXT_PASS (pass_mudflap_2
);
471 NEXT_PASS (pass_free_datastructures
);
472 NEXT_PASS (pass_free_cfg_annotations
);
473 NEXT_PASS (pass_expand
);
474 NEXT_PASS (pass_rest_of_compilation
);
477 p
= &pass_all_optimizations
.sub
;
478 NEXT_PASS (pass_referenced_vars
);
479 NEXT_PASS (pass_create_structure_vars
);
480 NEXT_PASS (pass_build_ssa
);
481 NEXT_PASS (pass_build_pta
);
482 NEXT_PASS (pass_may_alias
);
483 NEXT_PASS (pass_return_slot
);
484 NEXT_PASS (pass_del_pta
);
485 NEXT_PASS (pass_rename_ssa_copies
);
486 NEXT_PASS (pass_early_warn_uninitialized
);
488 /* Initial scalar cleanups. */
489 NEXT_PASS (pass_ccp
);
490 NEXT_PASS (pass_fre
);
491 NEXT_PASS (pass_dce
);
492 NEXT_PASS (pass_forwprop
);
493 NEXT_PASS (pass_copy_prop
);
494 NEXT_PASS (pass_vrp
);
495 NEXT_PASS (pass_dce
);
496 NEXT_PASS (pass_merge_phi
);
497 NEXT_PASS (pass_dominator
);
499 NEXT_PASS (pass_phiopt
);
500 NEXT_PASS (pass_build_pta
);
501 NEXT_PASS (pass_may_alias
);
502 NEXT_PASS (pass_del_pta
);
503 NEXT_PASS (pass_tail_recursion
);
504 NEXT_PASS (pass_profile
);
506 NEXT_PASS (pass_stdarg
);
507 NEXT_PASS (pass_lower_complex
);
508 NEXT_PASS (pass_sra
);
509 /* FIXME: SRA may generate arbitrary gimple code, exposing new
510 aliased and call-clobbered variables. As mentioned below,
511 pass_may_alias should be a TODO item. */
512 NEXT_PASS (pass_may_alias
);
513 NEXT_PASS (pass_rename_ssa_copies
);
514 NEXT_PASS (pass_dominator
);
515 NEXT_PASS (pass_copy_prop
);
516 NEXT_PASS (pass_dce
);
517 NEXT_PASS (pass_dse
);
518 NEXT_PASS (pass_may_alias
);
519 NEXT_PASS (pass_forwprop
);
520 NEXT_PASS (pass_phiopt
);
521 NEXT_PASS (pass_object_sizes
);
522 NEXT_PASS (pass_store_ccp
);
523 NEXT_PASS (pass_store_copy_prop
);
524 NEXT_PASS (pass_fold_builtins
);
525 /* FIXME: May alias should a TODO but for 4.0.0,
526 we add may_alias right after fold builtins
527 which can create arbitrary GIMPLE. */
528 NEXT_PASS (pass_may_alias
);
529 NEXT_PASS (pass_cse_reciprocals
);
530 NEXT_PASS (pass_split_crit_edges
);
531 NEXT_PASS (pass_reassoc
);
532 NEXT_PASS (pass_pre
);
533 NEXT_PASS (pass_sink_code
);
534 NEXT_PASS (pass_loop
);
535 NEXT_PASS (pass_dominator
);
536 NEXT_PASS (pass_copy_prop
);
537 NEXT_PASS (pass_cd_dce
);
538 /* FIXME: If DCE is not run before checking for uninitialized uses,
539 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
540 However, this also causes us to misdiagnose cases that should be
541 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
543 To fix the false positives in uninit-5.c, we would have to
544 account for the predicates protecting the set and the use of each
545 variable. Using a representation like Gated Single Assignment
547 NEXT_PASS (pass_late_warn_uninitialized
);
548 NEXT_PASS (pass_dse
);
549 NEXT_PASS (pass_forwprop
);
550 NEXT_PASS (pass_phiopt
);
551 NEXT_PASS (pass_tail_calls
);
552 NEXT_PASS (pass_rename_ssa_copies
);
553 NEXT_PASS (pass_uncprop
);
554 NEXT_PASS (pass_del_ssa
);
555 NEXT_PASS (pass_nrv
);
556 NEXT_PASS (pass_remove_useless_vars
);
557 NEXT_PASS (pass_mark_used_blocks
);
558 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
562 NEXT_PASS (pass_loop_init
);
563 NEXT_PASS (pass_copy_prop
);
564 NEXT_PASS (pass_lim
);
565 NEXT_PASS (pass_unswitch
);
566 NEXT_PASS (pass_scev_cprop
);
567 NEXT_PASS (pass_record_bounds
);
568 NEXT_PASS (pass_linear_transform
);
569 NEXT_PASS (pass_iv_canon
);
570 NEXT_PASS (pass_if_conversion
);
571 NEXT_PASS (pass_vectorize
);
572 /* NEXT_PASS (pass_may_alias) cannot be done again because the
573 vectorizer creates alias relations that are not supported by
575 NEXT_PASS (pass_lower_vector_ssa
);
576 NEXT_PASS (pass_complete_unroll
);
577 NEXT_PASS (pass_iv_optimize
);
578 NEXT_PASS (pass_loop_done
);
583 register_dump_files (all_lowering_passes
, false, PROP_gimple_any
);
584 register_dump_files (all_passes
, false, PROP_gimple_any
588 register_dump_files (all_ipa_passes
, true, PROP_gimple_any
594 static unsigned int last_verified
;
597 execute_todo (struct tree_opt_pass
*pass
, unsigned int flags
, bool use_required
)
600 = use_required
? pass
->properties_required
: pass
->properties_provided
;
602 #if defined ENABLE_CHECKING
603 if (need_ssa_update_p ())
604 gcc_assert (flags
& TODO_update_ssa_any
);
607 if (flags
& TODO_update_ssa_any
)
609 unsigned update_flags
= flags
& TODO_update_ssa_any
;
610 update_ssa (update_flags
);
613 if (flags
& TODO_cleanup_cfg
)
616 cleanup_tree_cfg_loop ();
621 if ((flags
& TODO_dump_func
)
622 && dump_file
&& current_function_decl
)
624 if (properties
& PROP_trees
)
625 dump_function_to_file (current_function_decl
,
626 dump_file
, dump_flags
);
627 else if (properties
& PROP_cfg
)
628 print_rtl_with_bb (dump_file
, get_insns ());
630 print_rtl (dump_file
, get_insns ());
632 /* Flush the file. If verification fails, we won't be able to
633 close the file before dieing. */
636 if ((flags
& TODO_dump_cgraph
)
637 && dump_file
&& !current_function_decl
)
639 dump_cgraph (dump_file
);
640 /* Flush the file. If verification fails, we won't be able to
641 close the file before aborting. */
645 if (flags
& TODO_ggc_collect
)
650 #if defined ENABLE_CHECKING
651 if ((pass
->properties_required
& PROP_ssa
)
652 && !(pass
->properties_destroyed
& PROP_ssa
))
654 if (flags
& TODO_verify_flow
)
656 if (flags
& TODO_verify_stmts
)
658 if (flags
& TODO_verify_loops
)
659 verify_loop_closed_ssa ();
664 execute_one_pass (struct tree_opt_pass
*pass
)
668 /* See if we're supposed to run this pass. */
669 if (pass
->gate
&& !pass
->gate ())
672 /* Note that the folders should only create gimple expressions.
673 This is a hack until the new folder is ready. */
674 in_gimple_form
= (pass
->properties_provided
& PROP_trees
) != 0;
676 /* Run pre-pass verification. */
677 todo
= pass
->todo_flags_start
& ~last_verified
;
679 execute_todo (pass
, todo
, true);
681 /* If a dump file name is present, open it if enabled. */
682 if (pass
->static_pass_number
!= -1)
684 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
685 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
686 dump_file
= dump_begin (pass
->static_pass_number
, &dump_flags
);
687 if (dump_file
&& current_function_decl
)
689 const char *dname
, *aname
;
690 dname
= lang_hooks
.decl_printable_name (current_function_decl
, 2);
691 aname
= (IDENTIFIER_POINTER
692 (DECL_ASSEMBLER_NAME (current_function_decl
)));
693 fprintf (dump_file
, "\n;; Function %s (%s)%s\n\n", dname
, aname
,
694 cfun
->function_frequency
== FUNCTION_FREQUENCY_HOT
696 : cfun
->function_frequency
== FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
697 ? " (unlikely executed)"
701 if (initializing_dump
702 && graph_dump_format
!= no_graph
703 && (pass
->properties_provided
& (PROP_cfg
| PROP_rtl
))
704 == (PROP_cfg
| PROP_rtl
))
705 clean_graph_dump_file (dump_file_name
);
708 /* If a timevar is present, start it. */
710 timevar_push (pass
->tv_id
);
718 timevar_pop (pass
->tv_id
);
721 && (pass
->properties_provided
& (PROP_cfg
| PROP_rtl
))
722 == (PROP_cfg
| PROP_rtl
))
723 print_rtl_with_bb (dump_file
, get_insns ());
725 /* Run post-pass cleanup and verification. */
726 todo
= pass
->todo_flags_finish
;
727 last_verified
= todo
& TODO_verify_all
;
729 execute_todo (pass
, todo
, false);
731 /* Flush and close dump file. */
734 free ((char *) dump_file_name
);
735 dump_file_name
= NULL
;
739 dump_end (pass
->static_pass_number
, dump_file
);
747 execute_pass_list (struct tree_opt_pass
*pass
)
751 if (execute_one_pass (pass
) && pass
->sub
)
752 execute_pass_list (pass
->sub
);
758 /* Same as execute_pass_list but assume that subpasses of IPA passes
761 execute_ipa_pass_list (struct tree_opt_pass
*pass
)
765 if (execute_one_pass (pass
) && pass
->sub
)
767 struct cgraph_node
*node
;
768 for (node
= cgraph_nodes
; node
; node
= node
->next
)
771 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
772 current_function_decl
= node
->decl
;
773 execute_pass_list (pass
->sub
);
774 free_dominance_info (CDI_DOMINATORS
);
775 free_dominance_info (CDI_POST_DOMINATORS
);
776 current_function_decl
= NULL
;
787 tree_lowering_passes (tree fn
)
789 tree saved_current_function_decl
= current_function_decl
;
791 current_function_decl
= fn
;
792 push_cfun (DECL_STRUCT_FUNCTION (fn
));
793 tree_register_cfg_hooks ();
794 bitmap_obstack_initialize (NULL
);
795 execute_pass_list (all_lowering_passes
);
796 free_dominance_info (CDI_POST_DOMINATORS
);
798 current_function_decl
= saved_current_function_decl
;
799 bitmap_obstack_release (NULL
);
803 /* Execute all IPA passes. */
808 tree_register_cfg_hooks ();
809 bitmap_obstack_initialize (NULL
);
810 execute_ipa_pass_list (all_ipa_passes
);
811 bitmap_obstack_release (NULL
);
815 /* Update recursively all inlined_to pointers of functions
816 inlined into NODE to INLINED_TO. */
818 update_inlined_to_pointers (struct cgraph_node
*node
,
819 struct cgraph_node
*inlined_to
)
821 struct cgraph_edge
*e
;
822 for (e
= node
->callees
; e
; e
= e
->next_callee
)
824 if (e
->callee
->global
.inlined_to
)
826 e
->callee
->global
.inlined_to
= inlined_to
;
827 update_inlined_to_pointers (e
->callee
, inlined_to
);
833 /* For functions-as-trees languages, this performs all optimization and
834 compilation for FNDECL. */
837 tree_rest_of_compilation (tree fndecl
)
839 location_t saved_loc
;
840 struct cgraph_node
*saved_node
= NULL
, *node
;
842 timevar_push (TV_EXPAND
);
844 gcc_assert (!flag_unit_at_a_time
|| cgraph_global_info_ready
);
846 /* Initialize the RTL code for the function. */
847 current_function_decl
= fndecl
;
848 saved_loc
= input_location
;
849 input_location
= DECL_SOURCE_LOCATION (fndecl
);
850 init_function_start (fndecl
);
852 /* Even though we're inside a function body, we still don't want to
853 call expand_expr to calculate the size of a variable-sized array.
854 We haven't necessarily assigned RTL to all variables yet, so it's
855 not safe to try to expand expressions involving them. */
856 cfun
->x_dont_save_pending_sizes_p
= 1;
857 cfun
->after_inlining
= true;
859 node
= cgraph_node (fndecl
);
861 /* We might need the body of this function so that we can expand
862 it inline somewhere else. This means not lowering some constructs
863 such as exception handling. */
864 if (cgraph_preserve_function_body_p (fndecl
))
866 if (!flag_unit_at_a_time
)
868 struct cgraph_edge
*e
;
870 saved_node
= cgraph_clone_node (node
, node
->count
, 1);
871 for (e
= saved_node
->callees
; e
; e
= e
->next_callee
)
872 if (!e
->inline_failed
)
873 cgraph_clone_inlined_nodes (e
, true);
875 cfun
->saved_static_chain_decl
= cfun
->static_chain_decl
;
876 save_body (fndecl
, &cfun
->saved_args
, &cfun
->saved_static_chain_decl
);
879 if (flag_inline_trees
)
881 struct cgraph_edge
*e
;
882 for (e
= node
->callees
; e
; e
= e
->next_callee
)
883 if (!e
->inline_failed
|| warn_inline
)
887 timevar_push (TV_INTEGRATION
);
888 optimize_inline_calls (fndecl
);
889 timevar_pop (TV_INTEGRATION
);
892 /* We are not going to maintain the cgraph edges up to date.
893 Kill it so it won't confuse us. */
894 while (node
->callees
)
896 /* In non-unit-at-a-time we must mark all referenced functions as needed.
898 if (node
->callees
->callee
->analyzed
&& !flag_unit_at_a_time
)
899 cgraph_mark_needed_node (node
->callees
->callee
);
900 cgraph_remove_edge (node
->callees
);
903 /* We are not going to maintain the cgraph edges up to date.
904 Kill it so it won't confuse us. */
905 cgraph_node_remove_callees (node
);
908 /* Initialize the default bitmap obstack. */
909 bitmap_obstack_initialize (NULL
);
910 bitmap_obstack_initialize (®_obstack
); /* FIXME, only at RTL generation*/
912 tree_register_cfg_hooks ();
913 /* Perform all tree transforms and optimizations. */
914 execute_pass_list (all_passes
);
916 bitmap_obstack_release (®_obstack
);
918 /* Release the default bitmap obstack. */
919 bitmap_obstack_release (NULL
);
921 /* Restore original body if still needed. */
924 DECL_ARGUMENTS (fndecl
) = cfun
->saved_args
;
925 cfun
->cfg
= cfun
->saved_cfg
;
926 cfun
->eh
= cfun
->saved_eh
;
927 cfun
->saved_cfg
= NULL
;
928 cfun
->saved_eh
= NULL
;
929 cfun
->saved_args
= NULL_TREE
;
930 cfun
->static_chain_decl
= cfun
->saved_static_chain_decl
;
931 cfun
->saved_static_chain_decl
= NULL
;
932 /* When not in unit-at-a-time mode, we must preserve out of line copy
933 representing node before inlining. Restore original outgoing edges
934 using clone we created earlier. */
935 if (!flag_unit_at_a_time
)
937 struct cgraph_edge
*e
;
939 node
= cgraph_node (current_function_decl
);
940 cgraph_node_remove_callees (node
);
941 node
->callees
= saved_node
->callees
;
942 saved_node
->callees
= NULL
;
943 update_inlined_to_pointers (node
, node
);
944 for (e
= node
->callees
; e
; e
= e
->next_callee
)
946 cgraph_remove_node (saved_node
);
950 DECL_SAVED_TREE (fndecl
) = NULL
;
953 /* If requested, warn about function definitions where the function will
954 return a value (usually of some struct or union type) which itself will
955 take up a lot of stack space. */
956 if (warn_larger_than
&& !DECL_EXTERNAL (fndecl
) && TREE_TYPE (fndecl
))
958 tree ret_type
= TREE_TYPE (TREE_TYPE (fndecl
));
960 if (ret_type
&& TYPE_SIZE_UNIT (ret_type
)
961 && TREE_CODE (TYPE_SIZE_UNIT (ret_type
)) == INTEGER_CST
962 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type
),
965 unsigned int size_as_int
966 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type
));
968 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type
), size_as_int
) == 0)
969 warning (0, "%Jsize of return value of %qD is %u bytes",
970 fndecl
, fndecl
, size_as_int
);
972 warning (0, "%Jsize of return value of %qD is larger than %wd bytes",
973 fndecl
, fndecl
, larger_than_size
);
977 if (!flag_inline_trees
)
979 DECL_SAVED_TREE (fndecl
) = NULL
;
980 if (DECL_STRUCT_FUNCTION (fndecl
) == 0
981 && !cgraph_node (fndecl
)->origin
)
983 /* Stop pointing to the local nodes about to be freed.
984 But DECL_INITIAL must remain nonzero so we know this
985 was an actual function definition.
986 For a nested function, this is done in c_pop_function_context.
987 If rest_of_compilation set this to 0, leave it 0. */
988 if (DECL_INITIAL (fndecl
) != 0)
989 DECL_INITIAL (fndecl
) = error_mark_node
;
993 input_location
= saved_loc
;
996 timevar_pop (TV_EXPAND
);