]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-optimize.c
tree-ssa-alias.c (compute_flow_insensitive_aliasing): Make sure subvars get marked...
[thirdparty/gcc.git] / gcc / tree-optimize.c
CommitLineData
ac534736 1/* Top-level control of tree optimizations.
ad616de1 2 Copyright 2001, 2002, 2003, 2004, 2005 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"
2b271002 50#include "cfgloop.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{
edfaf675 122 "final_cleanup", /* name */
165b54c3
SB
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 */
edfaf675 133 TODO_dump_func, /* todo_flags_finish */
9f8628ba 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 215{
f46fe224 216 char *dot_name, *flag_name, *glob_name;
6de9cd9a
DN
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);
f46fe224
DB
229 glob_name = concat ("tree-", pass->name, NULL);
230 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
9f8628ba
PB
231 TDF_TREE, n + TDI_tree_all, 0);
232 }
233 else
234 {
235 flag_name = concat ("rtl-", pass->name, num, NULL);
f46fe224
DB
236 glob_name = concat ("rtl-", pass->name, NULL);
237 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
9f8628ba
PB
238 TDF_RTL, n, pass->letter);
239 }
6de9cd9a
DN
240}
241
2f8e398b
PB
242static int
243register_dump_files (struct tree_opt_pass *pass, int properties)
6de9cd9a 244{
9f8628ba 245 static int n = 0;
6de9cd9a
DN
246 do
247 {
9f8628ba
PB
248 int new_properties;
249 int pass_number;
2f8e398b
PB
250
251 pass->properties_required = properties;
9f8628ba 252 new_properties =
2f8e398b
PB
253 (properties | pass->properties_provided) & ~pass->properties_destroyed;
254
9f8628ba
PB
255 /* Reset the counter when we reach RTL-based passes. */
256 if ((pass->properties_provided ^ pass->properties_required) & PROP_rtl)
257 n = 0;
258
259 pass_number = n;
260 if (pass->name)
261 n++;
262
6de9cd9a 263 if (pass->sub)
9f8628ba
PB
264 new_properties = register_dump_files (pass->sub, new_properties);
265
266 /* If we have a gate, combine the properties that we could have with
267 and without the pass being examined. */
268 if (pass->gate)
269 properties &= new_properties;
270 else
271 properties = new_properties;
272
273 pass->properties_provided = properties;
274 if (pass->name)
275 register_one_dump_file (pass, pass_number);
276
6de9cd9a
DN
277 pass = pass->next;
278 }
279 while (pass);
2f8e398b
PB
280
281 return properties;
6de9cd9a
DN
282}
283
b3fade83
BB
284/* Add a pass to the pass list. Duplicate the pass if it's already
285 in the list. */
6de9cd9a 286
b3fade83
BB
287static struct tree_opt_pass **
288next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
6de9cd9a 289{
6de9cd9a 290
8e3c61c5 291 /* A nonzero static_pass_number indicates that the
8c27b7d4 292 pass is already in the list. */
b3fade83 293 if (pass->static_pass_number)
6de9cd9a 294 {
b3fade83
BB
295 struct tree_opt_pass *new;
296
297 new = xmalloc (sizeof (*new));
298 memcpy (new, pass, sizeof (*new));
299
300 /* Indicate to register_dump_files that this pass has duplicates,
301 and so it should rename the dump file. The first instance will
302 be -1, and be number of duplicates = -static_pass_number - 1.
303 Subsequent instances will be > 0 and just the duplicate number. */
304 if (pass->name)
305 {
306 pass->static_pass_number -= 1;
307 new->static_pass_number = -pass->static_pass_number;
308 }
309
310 *list = new;
6de9cd9a 311 }
b3fade83
BB
312 else
313 {
314 pass->static_pass_number = -1;
315 *list = pass;
316 }
317
318 return &(*list)->next;
319
6de9cd9a
DN
320}
321
322/* Construct the pass tree. */
323
324void
325init_tree_optimization_passes (void)
326{
327 struct tree_opt_pass **p;
328
b3fade83 329#define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
6de9cd9a
DN
330
331 p = &all_passes;
332 NEXT_PASS (pass_gimple);
333 NEXT_PASS (pass_remove_useless_stmts);
334 NEXT_PASS (pass_mudflap_1);
335 NEXT_PASS (pass_lower_cf);
336 NEXT_PASS (pass_lower_eh);
242229bb 337 NEXT_PASS (pass_build_cfg);
26277d41 338 NEXT_PASS (pass_pre_expand);
242229bb 339 NEXT_PASS (pass_tree_profile);
33c94679 340 NEXT_PASS (pass_init_datastructures);
6de9cd9a 341 NEXT_PASS (pass_all_optimizations);
55e99d52 342 NEXT_PASS (pass_warn_function_return);
6de9cd9a 343 NEXT_PASS (pass_mudflap_2);
242229bb 344 NEXT_PASS (pass_free_datastructures);
2f8e398b
PB
345 NEXT_PASS (pass_expand);
346 NEXT_PASS (pass_rest_of_compilation);
6de9cd9a
DN
347 *p = NULL;
348
349 p = &pass_all_optimizations.sub;
6de9cd9a 350 NEXT_PASS (pass_referenced_vars);
c75ab022 351 NEXT_PASS (pass_create_structure_vars);
6de9cd9a 352 NEXT_PASS (pass_build_ssa);
c1b763fa 353 NEXT_PASS (pass_may_alias);
6de9cd9a
DN
354 NEXT_PASS (pass_rename_ssa_copies);
355 NEXT_PASS (pass_early_warn_uninitialized);
356 NEXT_PASS (pass_dce);
357 NEXT_PASS (pass_dominator);
358 NEXT_PASS (pass_redundant_phi);
b3fade83 359 NEXT_PASS (pass_dce);
23ab2e4e 360 NEXT_PASS (pass_merge_phi);
6de9cd9a
DN
361 NEXT_PASS (pass_forwprop);
362 NEXT_PASS (pass_phiopt);
363 NEXT_PASS (pass_may_alias);
364 NEXT_PASS (pass_tail_recursion);
365 NEXT_PASS (pass_ch);
6de9cd9a 366 NEXT_PASS (pass_profile);
6de9cd9a 367 NEXT_PASS (pass_sra);
3bd09563
DN
368 /* FIXME: SRA may generate arbitrary gimple code, exposing new
369 aliased and call-clobbered variables. As mentioned below,
370 pass_may_alias should be a TODO item. */
371 NEXT_PASS (pass_may_alias);
b3fade83
BB
372 NEXT_PASS (pass_rename_ssa_copies);
373 NEXT_PASS (pass_dominator);
374 NEXT_PASS (pass_redundant_phi);
375 NEXT_PASS (pass_dce);
6de9cd9a 376 NEXT_PASS (pass_dse);
b3fade83
BB
377 NEXT_PASS (pass_may_alias);
378 NEXT_PASS (pass_forwprop);
379 NEXT_PASS (pass_phiopt);
6de9cd9a 380 NEXT_PASS (pass_ccp);
b3fade83 381 NEXT_PASS (pass_redundant_phi);
6de9cd9a 382 NEXT_PASS (pass_fold_builtins);
209e170c
AP
383 /* FIXME: May alias should a TODO but for 4.0.0,
384 we add may_alias right after fold builtins
385 which can create arbitrary GIMPLE. */
386 NEXT_PASS (pass_may_alias);
6de9cd9a
DN
387 NEXT_PASS (pass_split_crit_edges);
388 NEXT_PASS (pass_pre);
fa555252 389 NEXT_PASS (pass_sink_code);
c66b6c66 390 NEXT_PASS (pass_loop);
b3fade83
BB
391 NEXT_PASS (pass_dominator);
392 NEXT_PASS (pass_redundant_phi);
75983038
DN
393 /* FIXME: If DCE is not run before checking for uninitialized uses,
394 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
395 However, this also causes us to misdiagnose cases that should be
396 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
397
398 To fix the false positives in uninit-5.c, we would have to
399 account for the predicates protecting the set and the use of each
400 variable. Using a representation like Gated Single Assignment
401 may help. */
402 NEXT_PASS (pass_late_warn_uninitialized);
6de9cd9a 403 NEXT_PASS (pass_cd_dce);
b3fade83
BB
404 NEXT_PASS (pass_dse);
405 NEXT_PASS (pass_forwprop);
406 NEXT_PASS (pass_phiopt);
6de9cd9a 407 NEXT_PASS (pass_tail_calls);
85840349 408 NEXT_PASS (pass_rename_ssa_copies);
6de9cd9a
DN
409 NEXT_PASS (pass_del_ssa);
410 NEXT_PASS (pass_nrv);
411 NEXT_PASS (pass_remove_useless_vars);
1eb3331e 412 NEXT_PASS (pass_mark_used_blocks);
165b54c3 413 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
6de9cd9a
DN
414 *p = NULL;
415
c66b6c66
ZD
416 p = &pass_loop.sub;
417 NEXT_PASS (pass_loop_init);
a7e5372d 418 NEXT_PASS (pass_lim);
92fc4a2f 419 NEXT_PASS (pass_unswitch);
f3cd574f 420 NEXT_PASS (pass_record_bounds);
464f49d8
DB
421 NEXT_PASS (pass_linear_transform);
422 NEXT_PASS (pass_iv_canon);
40923b20 423 NEXT_PASS (pass_if_conversion);
79fe1b3b 424 NEXT_PASS (pass_vectorize);
82b85a85 425 NEXT_PASS (pass_complete_unroll);
8b11a64c 426 NEXT_PASS (pass_iv_optimize);
c66b6c66
ZD
427 NEXT_PASS (pass_loop_done);
428 *p = NULL;
429
6de9cd9a 430#undef NEXT_PASS
6de9cd9a
DN
431
432 /* Register the passes with the tree dump code. */
2f8e398b 433 register_dump_files (all_passes, 0);
6de9cd9a
DN
434}
435
436static void execute_pass_list (struct tree_opt_pass *);
437
6de9cd9a
DN
438static unsigned int last_verified;
439
440static void
9f8628ba 441execute_todo (int properties, unsigned int flags)
6de9cd9a
DN
442{
443 if (flags & TODO_rename_vars)
444 {
5f240ec4
ZD
445 rewrite_into_ssa (false);
446 bitmap_clear (vars_to_rename);
6de9cd9a 447 }
52328bf6
DB
448 if (flags & TODO_fix_def_def_chains)
449 {
450 rewrite_def_def_chains ();
451 bitmap_clear (vars_to_rename);
452 }
6de9cd9a 453
88a40e67 454 if (flags & TODO_cleanup_cfg)
2b271002
ZD
455 {
456 if (current_loops)
457 cleanup_tree_cfg_loop ();
458 else
459 cleanup_tree_cfg ();
460 }
88a40e67 461
6de9cd9a 462 if ((flags & TODO_dump_func) && dump_file)
2aaf3dd5 463 {
9f8628ba
PB
464 if (properties & PROP_trees)
465 dump_function_to_file (current_function_decl,
466 dump_file, dump_flags);
467 else if (properties & PROP_cfg)
468 print_rtl_with_bb (dump_file, get_insns ());
469 else
470 print_rtl (dump_file, get_insns ());
2aaf3dd5
DN
471
472 /* Flush the file. If verification fails, we won't be able to
473 close the file before aborting. */
474 fflush (dump_file);
475 }
6de9cd9a
DN
476
477 if (flags & TODO_ggc_collect)
478 ggc_collect ();
479
480#ifdef ENABLE_CHECKING
481 if (flags & TODO_verify_ssa)
482 verify_ssa ();
483 if (flags & TODO_verify_flow)
484 verify_flow_info ();
485 if (flags & TODO_verify_stmts)
486 verify_stmts ();
487#endif
488}
489
490static bool
491execute_one_pass (struct tree_opt_pass *pass)
492{
493 unsigned int todo;
494
495 /* See if we're supposed to run this pass. */
496 if (pass->gate && !pass->gate ())
497 return false;
498
2f8e398b
PB
499 /* Note that the folders should only create gimple expressions.
500 This is a hack until the new folder is ready. */
501 in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
6de9cd9a
DN
502
503 /* Run pre-pass verification. */
504 todo = pass->todo_flags_start & ~last_verified;
505 if (todo)
9f8628ba 506 execute_todo (pass->properties_required, todo);
6de9cd9a
DN
507
508 /* If a dump file name is present, open it if enabled. */
b3fade83 509 if (pass->static_pass_number != -1)
6de9cd9a 510 {
9f8628ba
PB
511 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
512 dump_file_name = get_dump_file_name (pass->static_pass_number);
6de9cd9a
DN
513 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
514 if (dump_file)
515 {
516 const char *dname, *aname;
673fda6b 517 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
6de9cd9a
DN
518 aname = (IDENTIFIER_POINTER
519 (DECL_ASSEMBLER_NAME (current_function_decl)));
9f8628ba
PB
520 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
521 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
522 ? " (hot)"
523 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
524 ? " (unlikely executed)"
525 : "");
6de9cd9a 526 }
9f8628ba
PB
527
528 if (initializing_dump
529 && graph_dump_format != no_graph
530 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
531 == (PROP_cfg | PROP_rtl))
532 clean_graph_dump_file (dump_file_name);
6de9cd9a
DN
533 }
534
535 /* If a timevar is present, start it. */
536 if (pass->tv_id)
537 timevar_push (pass->tv_id);
538
6de9cd9a
DN
539 /* Do it! */
540 if (pass->execute)
541 pass->execute ();
4985cde3 542
e26ce7ed
DN
543 /* Stop timevar. */
544 if (pass->tv_id)
545 timevar_pop (pass->tv_id);
546
9f8628ba
PB
547 if (dump_file
548 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
549 == (PROP_cfg | PROP_rtl))
b7211528 550 print_rtl_with_bb (dump_file, get_insns ());
9f8628ba 551
6de9cd9a
DN
552 /* Run post-pass cleanup and verification. */
553 todo = pass->todo_flags_finish;
554 last_verified = todo & TODO_verify_all;
555 if (todo)
9f8628ba 556 execute_todo (pass->properties_provided, todo);
6de9cd9a 557
e26ce7ed 558 /* Flush and close dump file. */
9f8628ba
PB
559 if (dump_file_name)
560 {
561 free ((char *) dump_file_name);
562 dump_file_name = NULL;
563 }
6de9cd9a
DN
564 if (dump_file)
565 {
566 dump_end (pass->static_pass_number, dump_file);
567 dump_file = NULL;
568 }
569
570 return true;
571}
572
573static void
574execute_pass_list (struct tree_opt_pass *pass)
575{
576 do
577 {
578 if (execute_one_pass (pass) && pass->sub)
579 execute_pass_list (pass->sub);
580 pass = pass->next;
581 }
582 while (pass);
583}
2c459e74
JH
584\f
585
454ff5cb 586/* Update recursively all inlined_to pointers of functions
2c459e74
JH
587 inlined into NODE to INLINED_TO. */
588static void
589update_inlined_to_pointers (struct cgraph_node *node,
590 struct cgraph_node *inlined_to)
591{
592 struct cgraph_edge *e;
593 for (e = node->callees; e; e = e->next_callee)
594 {
595 if (e->callee->global.inlined_to)
596 {
597 e->callee->global.inlined_to = inlined_to;
d21bede3 598 update_inlined_to_pointers (e->callee, inlined_to);
2c459e74
JH
599 }
600 }
601}
6de9cd9a
DN
602
603\f
4985cde3
RH
604/* For functions-as-trees languages, this performs all optimization and
605 compilation for FNDECL. */
606
607void
0f0377f6 608tree_rest_of_compilation (tree fndecl)
4985cde3 609{
5d4854c8 610 location_t saved_loc;
6de9cd9a 611 struct cgraph_node *saved_node = NULL, *node;
5d4854c8 612
4985cde3
RH
613 timevar_push (TV_EXPAND);
614
1e128c5f 615 gcc_assert (!flag_unit_at_a_time || cgraph_global_info_ready);
4985cde3 616
4985cde3
RH
617 /* Initialize the RTL code for the function. */
618 current_function_decl = fndecl;
5d4854c8 619 saved_loc = input_location;
f31686a3 620 input_location = DECL_SOURCE_LOCATION (fndecl);
4985cde3
RH
621 init_function_start (fndecl);
622
4985cde3
RH
623 /* Even though we're inside a function body, we still don't want to
624 call expand_expr to calculate the size of a variable-sized array.
625 We haven't necessarily assigned RTL to all variables yet, so it's
626 not safe to try to expand expressions involving them. */
4985cde3
RH
627 cfun->x_dont_save_pending_sizes_p = 1;
628
18c6ada9
JH
629 node = cgraph_node (fndecl);
630
631 /* We might need the body of this function so that we can expand
632 it inline somewhere else. This means not lowering some constructs
633 such as exception handling. */
634 if (cgraph_preserve_function_body_p (fndecl))
635 {
636 if (!flag_unit_at_a_time)
637 {
638 struct cgraph_edge *e;
639
640 saved_node = cgraph_clone_node (node);
641 for (e = saved_node->callees; e; e = e->next_callee)
642 if (!e->inline_failed)
643 cgraph_clone_inlined_nodes (e, true);
644 }
1a837f77
RK
645 cfun->saved_static_chain_decl = cfun->static_chain_decl;
646 cfun->saved_tree = save_body (fndecl, &cfun->saved_args,
647 &cfun->saved_static_chain_decl);
18c6ada9
JH
648 }
649
650 if (flag_inline_trees)
651 {
652 struct cgraph_edge *e;
653 for (e = node->callees; e; e = e->next_callee)
654 if (!e->inline_failed || warn_inline)
655 break;
656 if (e)
657 {
658 timevar_push (TV_INTEGRATION);
659 optimize_inline_calls (fndecl);
660 timevar_pop (TV_INTEGRATION);
661 }
662 }
663
89480522
JH
664 /* We are not going to maintain the cgraph edges up to date.
665 Kill it so it won't confuse us. */
2563c224 666 cgraph_node_remove_callees (node);
89480522 667
5f240ec4 668
7932a3db
NS
669 /* Initialize the default bitmap obstack. */
670 bitmap_obstack_initialize (NULL);
671 bitmap_obstack_initialize (&reg_obstack); /* FIXME, only at RTL generation*/
672
8bdbfff5 673 vars_to_rename = BITMAP_ALLOC (NULL);
7932a3db 674
2f8e398b
PB
675 /* Perform all tree transforms and optimizations. */
676 execute_pass_list (all_passes);
7932a3db
NS
677
678 bitmap_obstack_release (&reg_obstack);
4985cde3 679
7932a3db
NS
680 /* Release the default bitmap obstack. */
681 bitmap_obstack_release (NULL);
682
6de9cd9a
DN
683 /* Restore original body if still needed. */
684 if (cfun->saved_tree)
685 {
686 DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
687 DECL_ARGUMENTS (fndecl) = cfun->saved_args;
1a837f77 688 cfun->static_chain_decl = cfun->saved_static_chain_decl;
18c6ada9 689
6de9cd9a
DN
690 /* When not in unit-at-a-time mode, we must preserve out of line copy
691 representing node before inlining. Restore original outgoing edges
692 using clone we created earlier. */
693 if (!flag_unit_at_a_time)
694 {
695 struct cgraph_edge *e;
0eac5feb 696
2563c224 697 cgraph_node_remove_callees (node);
6de9cd9a
DN
698 node->callees = saved_node->callees;
699 saved_node->callees = NULL;
d21bede3 700 update_inlined_to_pointers (node, node);
89480522 701 for (e = node->callees; e; e = e->next_callee)
d21bede3 702 e->caller = node;
6de9cd9a
DN
703 cgraph_remove_node (saved_node);
704 }
705 }
706 else
707 DECL_SAVED_TREE (fndecl) = NULL;
708 cfun = 0;
4985cde3
RH
709
710 /* If requested, warn about function definitions where the function will
711 return a value (usually of some struct or union type) which itself will
712 take up a lot of stack space. */
713 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
714 {
715 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
716
717 if (ret_type && TYPE_SIZE_UNIT (ret_type)
718 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
719 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
720 larger_than_size))
721 {
4985cde3
RH
722 unsigned int size_as_int
723 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
724
725 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
7a6336aa 726 warning ("%Jsize of return value of %qD is %u bytes",
ddd2d57e 727 fndecl, fndecl, size_as_int);
4985cde3 728 else
7a6336aa 729 warning ("%Jsize of return value of %qD is larger than %wd bytes",
ddd2d57e 730 fndecl, fndecl, larger_than_size);
4985cde3
RH
731 }
732 }
733
0f0377f6 734 if (!flag_inline_trees)
4985cde3 735 {
d173e685 736 DECL_SAVED_TREE (fndecl) = NULL;
6de9cd9a
DN
737 if (DECL_STRUCT_FUNCTION (fndecl) == 0
738 && !cgraph_node (fndecl)->origin)
d173e685
JH
739 {
740 /* Stop pointing to the local nodes about to be freed.
741 But DECL_INITIAL must remain nonzero so we know this
742 was an actual function definition.
743 For a nested function, this is done in c_pop_function_context.
744 If rest_of_compilation set this to 0, leave it 0. */
745 if (DECL_INITIAL (fndecl) != 0)
746 DECL_INITIAL (fndecl) = error_mark_node;
d173e685 747 }
4985cde3
RH
748 }
749
5d4854c8
RH
750 input_location = saved_loc;
751
6de9cd9a 752 ggc_collect ();
4985cde3
RH
753 timevar_pop (TV_EXPAND);
754}