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