]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-optimize.c
Fix cp changelog from previous checkin
[thirdparty/gcc.git] / gcc / tree-optimize.c
CommitLineData
ac534736 1/* Top-level control of tree optimizations.
283334f0 2 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
6de9cd9a 3 Contributed by Diego Novillo <dnovillo@redhat.com>
4985cde3
RH
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
6de9cd9a 25#include "tm.h"
4985cde3 26#include "tree.h"
6de9cd9a
DN
27#include "rtl.h"
28#include "tm_p.h"
29#include "hard-reg-set.h"
30#include "basic-block.h"
31#include "output.h"
32#include "expr.h"
33#include "diagnostic.h"
34#include "basic-block.h"
4985cde3 35#include "flags.h"
6de9cd9a
DN
36#include "tree-flow.h"
37#include "tree-dump.h"
4985cde3 38#include "timevar.h"
4985cde3 39#include "function.h"
6de9cd9a
DN
40#include "langhooks.h"
41#include "toplev.h"
42#include "flags.h"
43#include "cgraph.h"
44#include "tree-inline.h"
45#include "tree-mudflap.h"
46#include "tree-pass.h"
47#include "tree-alias-common.h"
4985cde3 48#include "ggc.h"
6de9cd9a 49#include "cgraph.h"
9f8628ba 50#include "graph.h"
6de9cd9a
DN
51
52
53/* Global variables used to communicate with passes. */
54int dump_flags;
55bitmap vars_to_rename;
56bool in_gimple_form;
57
58/* The root of the compilation pass tree, once constructed. */
59static struct tree_opt_pass *all_passes;
60
84936f6f 61/* Pass: dump the gimplified, inlined, functions. */
6de9cd9a
DN
62
63static struct tree_opt_pass pass_gimple =
64{
65 "gimple", /* name */
66 NULL, /* gate */
84936f6f 67 NULL, /* execute */
6de9cd9a
DN
68 NULL, /* sub */
69 NULL, /* next */
70 0, /* static_pass_number */
71 0, /* tv_id */
72 0, /* properties_required */
73 PROP_gimple_any, /* properties_provided */
74 0, /* properties_destroyed */
75 0, /* todo_flags_start */
9f8628ba
PB
76 TODO_dump_func, /* todo_flags_finish */
77 0 /* letter */
6de9cd9a
DN
78};
79
6de9cd9a
DN
80/* Gate: execute, or not, all of the non-trivial optimizations. */
81
82static bool
83gate_all_optimizations (void)
84{
85 return (optimize >= 1
86 /* Don't bother doing anything if the program has errors. */
87 && !(errorcount || sorrycount));
88}
89
90static struct tree_opt_pass pass_all_optimizations =
91{
92 NULL, /* name */
93 gate_all_optimizations, /* gate */
94 NULL, /* execute */
95 NULL, /* sub */
96 NULL, /* next */
97 0, /* static_pass_number */
98 0, /* tv_id */
99 0, /* properties_required */
100 0, /* properties_provided */
101 0, /* properties_destroyed */
102 0, /* todo_flags_start */
9f8628ba
PB
103 0, /* todo_flags_finish */
104 0 /* letter */
6de9cd9a
DN
105};
106
165b54c3
SB
107/* Pass: cleanup the CFG just before expanding trees to RTL.
108 This is just a round of label cleanups and case node grouping
109 because after the tree optimizers have run such cleanups may
110 be necessary. */
111
112static void
113execute_cleanup_cfg_post_optimizing (void)
114{
115 cleanup_tree_cfg ();
116 cleanup_dead_labels ();
117 group_case_labels ();
118}
119
120static struct tree_opt_pass pass_cleanup_cfg_post_optimizing =
121{
122 NULL, /* name */
123 NULL, /* gate */
124 execute_cleanup_cfg_post_optimizing, /* execute */
125 NULL, /* sub */
126 NULL, /* next */
127 0, /* static_pass_number */
128 0, /* tv_id */
129 PROP_cfg, /* properties_required */
130 0, /* properties_provided */
131 0, /* properties_destroyed */
132 0, /* todo_flags_start */
9f8628ba
PB
133 0, /* todo_flags_finish */
134 0 /* letter */
165b54c3
SB
135};
136
6de9cd9a
DN
137/* Pass: do the actions required to finish with tree-ssa optimization
138 passes. */
139
140static void
242229bb 141execute_free_datastructures (void)
6de9cd9a 142{
6de9cd9a
DN
143 tree *chain;
144
145 /* ??? This isn't the right place for this. Worse, it got computed
146 more or less at random in various passes. */
147 free_dominance_info (CDI_DOMINATORS);
148
149 /* Emit gotos for implicit jumps. */
150 disband_implicit_edges ();
151
152 /* Remove the ssa structures. Do it here since this includes statement
153 annotations that need to be intact during disband_implicit_edges. */
154 delete_tree_ssa ();
155
156 /* Re-chain the statements from the blocks. */
157 chain = &DECL_SAVED_TREE (current_function_decl);
158 *chain = alloc_stmt_list ();
6de9cd9a 159
242229bb
JH
160 /* And get rid of annotations we no longer need. */
161 delete_tree_cfg_annotations ();
6de9cd9a
DN
162}
163
242229bb 164static struct tree_opt_pass pass_free_datastructures =
6de9cd9a
DN
165{
166 NULL, /* name */
167 NULL, /* gate */
242229bb 168 execute_free_datastructures, /* execute */
6de9cd9a
DN
169 NULL, /* sub */
170 NULL, /* next */
171 0, /* static_pass_number */
172 0, /* tv_id */
173 PROP_cfg, /* properties_required */
174 0, /* properties_provided */
242229bb 175 0, /* properties_destroyed */
6de9cd9a 176 0, /* todo_flags_start */
9f8628ba
PB
177 0, /* todo_flags_finish */
178 0 /* letter */
6de9cd9a
DN
179};
180
33c94679
DN
181
182/* Do the actions required to initialize internal data structures used
183 in tree-ssa optimization passes. */
184
185static void
186execute_init_datastructures (void)
187{
188 /* Allocate hash tables, arrays and other structures. */
189 init_tree_ssa ();
190}
191
192static struct tree_opt_pass pass_init_datastructures =
193{
194 NULL, /* name */
195 NULL, /* gate */
196 execute_init_datastructures, /* execute */
197 NULL, /* sub */
198 NULL, /* next */
199 0, /* static_pass_number */
200 0, /* tv_id */
201 PROP_cfg, /* properties_required */
202 0, /* properties_provided */
203 0, /* properties_destroyed */
204 0, /* todo_flags_start */
9f8628ba
PB
205 0, /* todo_flags_finish */
206 0 /* letter */
33c94679
DN
207};
208
6de9cd9a
DN
209/* Iterate over the pass tree allocating dump file numbers. We want
210 to do this depth first, and independent of whether the pass is
211 enabled or not. */
212
213static void
9f8628ba 214register_one_dump_file (struct tree_opt_pass *pass, int n)
6de9cd9a
DN
215{
216 char *dot_name, *flag_name;
217 char num[10];
218
b3fade83 219 /* See below in next_pass_1. */
6de9cd9a 220 num[0] = '\0';
b3fade83 221 if (pass->static_pass_number != -1)
6de9cd9a
DN
222 sprintf (num, "%d", ((int) pass->static_pass_number < 0
223 ? 1 : pass->static_pass_number));
224
225 dot_name = concat (".", pass->name, num, NULL);
9f8628ba
PB
226 if (pass->properties_provided & PROP_trees)
227 {
228 flag_name = concat ("tree-", pass->name, num, NULL);
229 pass->static_pass_number = dump_register (dot_name, flag_name,
230 TDF_TREE, n + TDI_tree_all, 0);
231 }
232 else
233 {
234 flag_name = concat ("rtl-", pass->name, num, NULL);
235 pass->static_pass_number = dump_register (dot_name, flag_name,
236 TDF_RTL, n, pass->letter);
237 }
6de9cd9a
DN
238}
239
2f8e398b
PB
240static int
241register_dump_files (struct tree_opt_pass *pass, int properties)
6de9cd9a 242{
9f8628ba 243 static int n = 0;
6de9cd9a
DN
244 do
245 {
9f8628ba
PB
246 int new_properties;
247 int pass_number;
2f8e398b
PB
248
249 pass->properties_required = properties;
9f8628ba 250 new_properties =
2f8e398b
PB
251 (properties | pass->properties_provided) & ~pass->properties_destroyed;
252
9f8628ba
PB
253 /* Reset the counter when we reach RTL-based passes. */
254 if ((pass->properties_provided ^ pass->properties_required) & PROP_rtl)
255 n = 0;
256
257 pass_number = n;
258 if (pass->name)
259 n++;
260
6de9cd9a 261 if (pass->sub)
9f8628ba
PB
262 new_properties = register_dump_files (pass->sub, new_properties);
263
264 /* If we have a gate, combine the properties that we could have with
265 and without the pass being examined. */
266 if (pass->gate)
267 properties &= new_properties;
268 else
269 properties = new_properties;
270
271 pass->properties_provided = properties;
272 if (pass->name)
273 register_one_dump_file (pass, pass_number);
274
6de9cd9a
DN
275 pass = pass->next;
276 }
277 while (pass);
2f8e398b
PB
278
279 return properties;
6de9cd9a
DN
280}
281
b3fade83
BB
282/* Add a pass to the pass list. Duplicate the pass if it's already
283 in the list. */
6de9cd9a 284
b3fade83
BB
285static struct tree_opt_pass **
286next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
6de9cd9a 287{
6de9cd9a 288
b3fade83 289 /* A non-zero static_pass_number indicates that the
8c27b7d4 290 pass is already in the list. */
b3fade83 291 if (pass->static_pass_number)
6de9cd9a 292 {
b3fade83
BB
293 struct tree_opt_pass *new;
294
295 new = xmalloc (sizeof (*new));
296 memcpy (new, pass, sizeof (*new));
297
298 /* Indicate to register_dump_files that this pass has duplicates,
299 and so it should rename the dump file. The first instance will
300 be -1, and be number of duplicates = -static_pass_number - 1.
301 Subsequent instances will be > 0 and just the duplicate number. */
302 if (pass->name)
303 {
304 pass->static_pass_number -= 1;
305 new->static_pass_number = -pass->static_pass_number;
306 }
307
308 *list = new;
6de9cd9a 309 }
b3fade83
BB
310 else
311 {
312 pass->static_pass_number = -1;
313 *list = pass;
314 }
315
316 return &(*list)->next;
317
6de9cd9a
DN
318}
319
320/* Construct the pass tree. */
321
322void
323init_tree_optimization_passes (void)
324{
325 struct tree_opt_pass **p;
326
b3fade83 327#define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
6de9cd9a
DN
328
329 p = &all_passes;
330 NEXT_PASS (pass_gimple);
331 NEXT_PASS (pass_remove_useless_stmts);
332 NEXT_PASS (pass_mudflap_1);
333 NEXT_PASS (pass_lower_cf);
334 NEXT_PASS (pass_lower_eh);
242229bb 335 NEXT_PASS (pass_build_cfg);
26277d41 336 NEXT_PASS (pass_pre_expand);
242229bb 337 NEXT_PASS (pass_tree_profile);
33c94679 338 NEXT_PASS (pass_init_datastructures);
6de9cd9a 339 NEXT_PASS (pass_all_optimizations);
55e99d52 340 NEXT_PASS (pass_warn_function_return);
6de9cd9a 341 NEXT_PASS (pass_mudflap_2);
242229bb 342 NEXT_PASS (pass_free_datastructures);
2f8e398b
PB
343 NEXT_PASS (pass_expand);
344 NEXT_PASS (pass_rest_of_compilation);
6de9cd9a
DN
345 *p = NULL;
346
347 p = &pass_all_optimizations.sub;
6de9cd9a
DN
348 NEXT_PASS (pass_referenced_vars);
349 NEXT_PASS (pass_build_pta);
350 NEXT_PASS (pass_build_ssa);
c1b763fa 351 NEXT_PASS (pass_may_alias);
6de9cd9a
DN
352 NEXT_PASS (pass_rename_ssa_copies);
353 NEXT_PASS (pass_early_warn_uninitialized);
354 NEXT_PASS (pass_dce);
355 NEXT_PASS (pass_dominator);
356 NEXT_PASS (pass_redundant_phi);
b3fade83 357 NEXT_PASS (pass_dce);
6de9cd9a
DN
358 NEXT_PASS (pass_forwprop);
359 NEXT_PASS (pass_phiopt);
360 NEXT_PASS (pass_may_alias);
361 NEXT_PASS (pass_tail_recursion);
362 NEXT_PASS (pass_ch);
6de9cd9a 363 NEXT_PASS (pass_profile);
6de9cd9a 364 NEXT_PASS (pass_sra);
b3fade83
BB
365 NEXT_PASS (pass_rename_ssa_copies);
366 NEXT_PASS (pass_dominator);
367 NEXT_PASS (pass_redundant_phi);
368 NEXT_PASS (pass_dce);
6de9cd9a 369 NEXT_PASS (pass_dse);
b3fade83
BB
370 NEXT_PASS (pass_may_alias);
371 NEXT_PASS (pass_forwprop);
372 NEXT_PASS (pass_phiopt);
6de9cd9a 373 NEXT_PASS (pass_ccp);
b3fade83 374 NEXT_PASS (pass_redundant_phi);
6de9cd9a
DN
375 NEXT_PASS (pass_fold_builtins);
376 NEXT_PASS (pass_split_crit_edges);
377 NEXT_PASS (pass_pre);
c66b6c66 378 NEXT_PASS (pass_loop);
b3fade83
BB
379 NEXT_PASS (pass_dominator);
380 NEXT_PASS (pass_redundant_phi);
6de9cd9a 381 NEXT_PASS (pass_cd_dce);
b3fade83
BB
382 NEXT_PASS (pass_dse);
383 NEXT_PASS (pass_forwprop);
384 NEXT_PASS (pass_phiopt);
6de9cd9a
DN
385 NEXT_PASS (pass_tail_calls);
386 NEXT_PASS (pass_late_warn_uninitialized);
d8903b30 387 NEXT_PASS (pass_del_pta);
6de9cd9a
DN
388 NEXT_PASS (pass_del_ssa);
389 NEXT_PASS (pass_nrv);
390 NEXT_PASS (pass_remove_useless_vars);
165b54c3 391 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
6de9cd9a
DN
392 *p = NULL;
393
c66b6c66
ZD
394 p = &pass_loop.sub;
395 NEXT_PASS (pass_loop_init);
a7e5372d 396 NEXT_PASS (pass_lim);
82b85a85 397 NEXT_PASS (pass_iv_canon);
40923b20 398 NEXT_PASS (pass_if_conversion);
79fe1b3b 399 NEXT_PASS (pass_vectorize);
82b85a85 400 NEXT_PASS (pass_complete_unroll);
8b11a64c 401 NEXT_PASS (pass_iv_optimize);
c66b6c66
ZD
402 NEXT_PASS (pass_loop_done);
403 *p = NULL;
404
6de9cd9a 405#undef NEXT_PASS
6de9cd9a
DN
406
407 /* Register the passes with the tree dump code. */
2f8e398b 408 register_dump_files (all_passes, 0);
6de9cd9a
DN
409}
410
411static void execute_pass_list (struct tree_opt_pass *);
412
6de9cd9a
DN
413static unsigned int last_verified;
414
415static void
9f8628ba 416execute_todo (int properties, unsigned int flags)
6de9cd9a
DN
417{
418 if (flags & TODO_rename_vars)
419 {
5f240ec4
ZD
420 rewrite_into_ssa (false);
421 bitmap_clear (vars_to_rename);
6de9cd9a
DN
422 }
423
424 if ((flags & TODO_dump_func) && dump_file)
2aaf3dd5 425 {
9f8628ba
PB
426 if (properties & PROP_trees)
427 dump_function_to_file (current_function_decl,
428 dump_file, dump_flags);
429 else if (properties & PROP_cfg)
430 print_rtl_with_bb (dump_file, get_insns ());
431 else
432 print_rtl (dump_file, get_insns ());
2aaf3dd5
DN
433
434 /* Flush the file. If verification fails, we won't be able to
435 close the file before aborting. */
436 fflush (dump_file);
437 }
6de9cd9a
DN
438
439 if (flags & TODO_ggc_collect)
440 ggc_collect ();
441
442#ifdef ENABLE_CHECKING
443 if (flags & TODO_verify_ssa)
444 verify_ssa ();
445 if (flags & TODO_verify_flow)
446 verify_flow_info ();
447 if (flags & TODO_verify_stmts)
448 verify_stmts ();
449#endif
450}
451
452static bool
453execute_one_pass (struct tree_opt_pass *pass)
454{
455 unsigned int todo;
456
457 /* See if we're supposed to run this pass. */
458 if (pass->gate && !pass->gate ())
459 return false;
460
2f8e398b
PB
461 /* Note that the folders should only create gimple expressions.
462 This is a hack until the new folder is ready. */
463 in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
6de9cd9a
DN
464
465 /* Run pre-pass verification. */
466 todo = pass->todo_flags_start & ~last_verified;
467 if (todo)
9f8628ba 468 execute_todo (pass->properties_required, todo);
6de9cd9a
DN
469
470 /* If a dump file name is present, open it if enabled. */
b3fade83 471 if (pass->static_pass_number != -1)
6de9cd9a 472 {
9f8628ba
PB
473 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
474 dump_file_name = get_dump_file_name (pass->static_pass_number);
6de9cd9a
DN
475 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
476 if (dump_file)
477 {
478 const char *dname, *aname;
673fda6b 479 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
6de9cd9a
DN
480 aname = (IDENTIFIER_POINTER
481 (DECL_ASSEMBLER_NAME (current_function_decl)));
9f8628ba
PB
482 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
483 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
484 ? " (hot)"
485 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
486 ? " (unlikely executed)"
487 : "");
6de9cd9a 488 }
9f8628ba
PB
489
490 if (initializing_dump
491 && graph_dump_format != no_graph
492 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
493 == (PROP_cfg | PROP_rtl))
494 clean_graph_dump_file (dump_file_name);
6de9cd9a
DN
495 }
496
497 /* If a timevar is present, start it. */
498 if (pass->tv_id)
499 timevar_push (pass->tv_id);
500
6de9cd9a
DN
501 /* Do it! */
502 if (pass->execute)
503 pass->execute ();
4985cde3 504
9f8628ba
PB
505 if (dump_file
506 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
507 == (PROP_cfg | PROP_rtl))
508 print_rtl_graph_with_bb (dump_file_name, get_insns ());
509
6de9cd9a
DN
510 /* Run post-pass cleanup and verification. */
511 todo = pass->todo_flags_finish;
512 last_verified = todo & TODO_verify_all;
513 if (todo)
9f8628ba 514 execute_todo (pass->properties_provided, todo);
6de9cd9a 515
6de9cd9a
DN
516 /* Close down timevar and dump file. */
517 if (pass->tv_id)
518 timevar_pop (pass->tv_id);
9f8628ba
PB
519 if (dump_file_name)
520 {
521 free ((char *) dump_file_name);
522 dump_file_name = NULL;
523 }
6de9cd9a
DN
524 if (dump_file)
525 {
526 dump_end (pass->static_pass_number, dump_file);
527 dump_file = NULL;
528 }
529
530 return true;
531}
532
533static void
534execute_pass_list (struct tree_opt_pass *pass)
535{
536 do
537 {
538 if (execute_one_pass (pass) && pass->sub)
539 execute_pass_list (pass->sub);
540 pass = pass->next;
541 }
542 while (pass);
543}
544
545\f
4985cde3
RH
546/* For functions-as-trees languages, this performs all optimization and
547 compilation for FNDECL. */
548
549void
c1f927e8 550tree_rest_of_compilation (tree fndecl, bool nested_p)
4985cde3 551{
5d4854c8 552 location_t saved_loc;
6de9cd9a 553 struct cgraph_node *saved_node = NULL, *node;
5d4854c8 554
4985cde3
RH
555 timevar_push (TV_EXPAND);
556
4985cde3
RH
557 if (flag_unit_at_a_time && !cgraph_global_info_ready)
558 abort ();
559
4985cde3
RH
560 /* Initialize the RTL code for the function. */
561 current_function_decl = fndecl;
5d4854c8 562 saved_loc = input_location;
f31686a3 563 input_location = DECL_SOURCE_LOCATION (fndecl);
4985cde3
RH
564 init_function_start (fndecl);
565
4985cde3
RH
566 /* Even though we're inside a function body, we still don't want to
567 call expand_expr to calculate the size of a variable-sized array.
568 We haven't necessarily assigned RTL to all variables yet, so it's
569 not safe to try to expand expressions involving them. */
4985cde3
RH
570 cfun->x_dont_save_pending_sizes_p = 1;
571
18c6ada9
JH
572 node = cgraph_node (fndecl);
573
574 /* We might need the body of this function so that we can expand
575 it inline somewhere else. This means not lowering some constructs
576 such as exception handling. */
577 if (cgraph_preserve_function_body_p (fndecl))
578 {
579 if (!flag_unit_at_a_time)
580 {
581 struct cgraph_edge *e;
582
583 saved_node = cgraph_clone_node (node);
584 for (e = saved_node->callees; e; e = e->next_callee)
585 if (!e->inline_failed)
586 cgraph_clone_inlined_nodes (e, true);
587 }
1a837f77
RK
588 cfun->saved_static_chain_decl = cfun->static_chain_decl;
589 cfun->saved_tree = save_body (fndecl, &cfun->saved_args,
590 &cfun->saved_static_chain_decl);
18c6ada9
JH
591 }
592
593 if (flag_inline_trees)
594 {
595 struct cgraph_edge *e;
596 for (e = node->callees; e; e = e->next_callee)
597 if (!e->inline_failed || warn_inline)
598 break;
599 if (e)
600 {
601 timevar_push (TV_INTEGRATION);
602 optimize_inline_calls (fndecl);
603 timevar_pop (TV_INTEGRATION);
604 }
605 }
606
5f240ec4
ZD
607 if (!vars_to_rename)
608 vars_to_rename = BITMAP_XMALLOC ();
609
4985cde3
RH
610 /* If this is a nested function, protect the local variables in the stack
611 above us from being collected while we're compiling this function. */
c1f927e8 612 if (nested_p)
4985cde3
RH
613 ggc_push_context ();
614
2f8e398b
PB
615 /* Perform all tree transforms and optimizations. */
616 execute_pass_list (all_passes);
4985cde3 617
6de9cd9a
DN
618 /* Restore original body if still needed. */
619 if (cfun->saved_tree)
620 {
621 DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
622 DECL_ARGUMENTS (fndecl) = cfun->saved_args;
1a837f77 623 cfun->static_chain_decl = cfun->saved_static_chain_decl;
18c6ada9 624
6de9cd9a
DN
625 /* When not in unit-at-a-time mode, we must preserve out of line copy
626 representing node before inlining. Restore original outgoing edges
627 using clone we created earlier. */
628 if (!flag_unit_at_a_time)
629 {
630 struct cgraph_edge *e;
631 while (node->callees)
632 cgraph_remove_edge (node->callees);
633 node->callees = saved_node->callees;
634 saved_node->callees = NULL;
635 for (e = saved_node->callees; e; e = e->next_callee)
636 e->caller = node;
637 cgraph_remove_node (saved_node);
638 }
639 }
640 else
641 DECL_SAVED_TREE (fndecl) = NULL;
642 cfun = 0;
4985cde3
RH
643
644 /* If requested, warn about function definitions where the function will
645 return a value (usually of some struct or union type) which itself will
646 take up a lot of stack space. */
647 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
648 {
649 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
650
651 if (ret_type && TYPE_SIZE_UNIT (ret_type)
652 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
653 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
654 larger_than_size))
655 {
4985cde3
RH
656 unsigned int size_as_int
657 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
658
659 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
ddd2d57e
RH
660 warning ("%Jsize of return value of '%D' is %u bytes",
661 fndecl, fndecl, size_as_int);
4985cde3 662 else
ddd2d57e
RH
663 warning ("%Jsize of return value of '%D' is larger than %wd bytes",
664 fndecl, fndecl, larger_than_size);
4985cde3
RH
665 }
666 }
667
6de9cd9a 668 if (!nested_p && !flag_inline_trees)
4985cde3 669 {
d173e685 670 DECL_SAVED_TREE (fndecl) = NULL;
6de9cd9a
DN
671 if (DECL_STRUCT_FUNCTION (fndecl) == 0
672 && !cgraph_node (fndecl)->origin)
d173e685
JH
673 {
674 /* Stop pointing to the local nodes about to be freed.
675 But DECL_INITIAL must remain nonzero so we know this
676 was an actual function definition.
677 For a nested function, this is done in c_pop_function_context.
678 If rest_of_compilation set this to 0, leave it 0. */
679 if (DECL_INITIAL (fndecl) != 0)
680 DECL_INITIAL (fndecl) = error_mark_node;
d173e685 681 }
4985cde3
RH
682 }
683
5d4854c8
RH
684 input_location = saved_loc;
685
6de9cd9a
DN
686 ggc_collect ();
687
688 /* Undo the GC context switch. */
689 if (nested_p)
690 ggc_pop_context ();
4985cde3
RH
691 timevar_pop (TV_EXPAND);
692}