Makefile.in (tree-ssa-alias.o): Depend on tree-ssa-structalias.h
[gcc.git] / gcc / passes.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
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 the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
26
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
34
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
38
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
42
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "rtl.h"
47 #include "tm_p.h"
48 #include "flags.h"
49 #include "insn-attr.h"
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "hard-reg-set.h"
53 #include "recog.h"
54 #include "output.h"
55 #include "except.h"
56 #include "function.h"
57 #include "toplev.h"
58 #include "expr.h"
59 #include "basic-block.h"
60 #include "intl.h"
61 #include "ggc.h"
62 #include "graph.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "params.h"
67 #include "reload.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
70 #include "real.h"
71 #include "debug.h"
72 #include "target.h"
73 #include "langhooks.h"
74 #include "cfglayout.h"
75 #include "cfgloop.h"
76 #include "hosthooks.h"
77 #include "cgraph.h"
78 #include "opts.h"
79 #include "coverage.h"
80 #include "value-prof.h"
81 #include "tree-inline.h"
82 #include "tree-flow.h"
83 #include "tree-pass.h"
84 #include "tree-dump.h"
85
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
88 #endif
89
90 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
91 #include "dbxout.h"
92 #endif
93
94 #ifdef SDB_DEBUGGING_INFO
95 #include "sdbout.h"
96 #endif
97
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
101 #endif
102
103 /* Global variables used to communicate with passes. */
104 int dump_flags;
105 bool in_gimple_form;
106
107
108 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
109 and TYPE_DECL nodes.
110
111 This does nothing for local (non-static) variables, unless the
112 variable is a register variable with DECL_ASSEMBLER_NAME set. In
113 that case, or if the variable is not an automatic, it sets up the
114 RTL and outputs any assembler code (label definition, storage
115 allocation and initialization).
116
117 DECL is the declaration. TOP_LEVEL is nonzero
118 if this declaration is not within a function. */
119
120 void
121 rest_of_decl_compilation (tree decl,
122 int top_level,
123 int at_end)
124 {
125 /* We deferred calling assemble_alias so that we could collect
126 other attributes such as visibility. Emit the alias now. */
127 {
128 tree alias;
129 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
130 if (alias)
131 {
132 alias = TREE_VALUE (TREE_VALUE (alias));
133 alias = get_identifier (TREE_STRING_POINTER (alias));
134 assemble_alias (decl, alias);
135 }
136 }
137
138 /* Can't defer this, because it needs to happen before any
139 later function definitions are processed. */
140 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
141 make_decl_rtl (decl);
142
143 /* Forward declarations for nested functions are not "external",
144 but we need to treat them as if they were. */
145 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
146 || TREE_CODE (decl) == FUNCTION_DECL)
147 {
148 timevar_push (TV_VARCONST);
149
150 /* Don't output anything when a tentative file-scope definition
151 is seen. But at end of compilation, do output code for them.
152
153 We do output all variables when unit-at-a-time is active and rely on
154 callgraph code to defer them except for forward declarations
155 (see gcc.c-torture/compile/920624-1.c) */
156 if ((at_end
157 || !DECL_DEFER_OUTPUT (decl)
158 || DECL_INITIAL (decl))
159 && !DECL_EXTERNAL (decl))
160 {
161 if (flag_unit_at_a_time && !cgraph_global_info_ready
162 && TREE_CODE (decl) != FUNCTION_DECL)
163 cgraph_varpool_finalize_decl (decl);
164 else
165 assemble_variable (decl, top_level, at_end, 0);
166 }
167
168 #ifdef ASM_FINISH_DECLARE_OBJECT
169 if (decl == last_assemble_variable_decl)
170 {
171 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
172 top_level, at_end);
173 }
174 #endif
175
176 timevar_pop (TV_VARCONST);
177 }
178 else if (TREE_CODE (decl) == TYPE_DECL)
179 {
180 timevar_push (TV_SYMOUT);
181 debug_hooks->type_decl (decl, !top_level);
182 timevar_pop (TV_SYMOUT);
183 }
184
185 /* Let cgraph know about the existence of variables. */
186 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
187 cgraph_varpool_node (decl);
188 }
189
190 /* Called after finishing a record, union or enumeral type. */
191
192 void
193 rest_of_type_compilation (tree type, int toplev)
194 {
195 /* Avoid confusing the debug information machinery when there are
196 errors. */
197 if (errorcount != 0 || sorrycount != 0)
198 return;
199
200 timevar_push (TV_SYMOUT);
201 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
202 timevar_pop (TV_SYMOUT);
203 }
204
205 \f
206
207 void
208 finish_optimization_passes (void)
209 {
210 enum tree_dump_index i;
211 struct dump_file_info *dfi;
212 char *name;
213
214 timevar_push (TV_DUMP);
215 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
216 {
217 dump_file = dump_begin (pass_branch_prob.static_pass_number, NULL);
218 end_branch_prob ();
219 if (dump_file)
220 dump_end (pass_branch_prob.static_pass_number, dump_file);
221 }
222
223 if (optimize > 0)
224 {
225 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
226 if (dump_file)
227 {
228 dump_combine_total_stats (dump_file);
229 dump_end (pass_combine.static_pass_number, dump_file);
230 }
231 }
232
233 /* Do whatever is necessary to finish printing the graphs. */
234 if (graph_dump_format != no_graph)
235 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
236 if (dump_initialized_p (i)
237 && (dfi->flags & TDF_RTL) != 0
238 && (name = get_dump_file_name (i)) != NULL)
239 {
240 finish_graph_dump_file (name);
241 free (name);
242 }
243
244 timevar_pop (TV_DUMP);
245 }
246
247 static bool
248 gate_rest_of_compilation (void)
249 {
250 /* Early return if there were errors. We can run afoul of our
251 consistency checks, and there's not really much point in fixing them. */
252 return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
253 }
254
255 struct tree_opt_pass pass_rest_of_compilation =
256 {
257 NULL, /* name */
258 gate_rest_of_compilation, /* gate */
259 NULL, /* execute */
260 NULL, /* sub */
261 NULL, /* next */
262 0, /* static_pass_number */
263 TV_REST_OF_COMPILATION, /* tv_id */
264 PROP_rtl, /* properties_required */
265 0, /* properties_provided */
266 0, /* properties_destroyed */
267 0, /* todo_flags_start */
268 TODO_ggc_collect, /* todo_flags_finish */
269 0 /* letter */
270 };
271
272 static bool
273 gate_postreload (void)
274 {
275 return reload_completed;
276 }
277
278 struct tree_opt_pass pass_postreload =
279 {
280 NULL, /* name */
281 gate_postreload, /* gate */
282 NULL, /* execute */
283 NULL, /* sub */
284 NULL, /* next */
285 0, /* static_pass_number */
286 0, /* tv_id */
287 PROP_rtl, /* properties_required */
288 0, /* properties_provided */
289 0, /* properties_destroyed */
290 0, /* todo_flags_start */
291 TODO_ggc_collect, /* todo_flags_finish */
292 0 /* letter */
293 };
294
295
296
297 /* The root of the compilation pass tree, once constructed. */
298 struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
299
300 /* Iterate over the pass tree allocating dump file numbers. We want
301 to do this depth first, and independent of whether the pass is
302 enabled or not. */
303
304 static void
305 register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int n)
306 {
307 char *dot_name, *flag_name, *glob_name;
308 char num[10];
309
310 /* See below in next_pass_1. */
311 num[0] = '\0';
312 if (pass->static_pass_number != -1)
313 sprintf (num, "%d", ((int) pass->static_pass_number < 0
314 ? 1 : pass->static_pass_number));
315
316 dot_name = concat (".", pass->name, num, NULL);
317 if (ipa)
318 {
319 flag_name = concat ("ipa-", pass->name, num, NULL);
320 glob_name = concat ("ipa-", pass->name, NULL);
321 /* First IPA dump is cgraph that is dumped via separate channels. */
322 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
323 TDF_IPA, n + 1, 0);
324 }
325 else if (pass->properties_provided & PROP_trees)
326 {
327 flag_name = concat ("tree-", pass->name, num, NULL);
328 glob_name = concat ("tree-", pass->name, NULL);
329 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
330 TDF_TREE, n + TDI_tree_all, 0);
331 }
332 else
333 {
334 flag_name = concat ("rtl-", pass->name, num, NULL);
335 glob_name = concat ("rtl-", pass->name, NULL);
336 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
337 TDF_RTL, n, pass->letter);
338 }
339 }
340
341 static int
342 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
343 {
344 static int n = 0;
345 do
346 {
347 int new_properties;
348 int pass_number;
349
350 pass->properties_required = properties;
351 new_properties =
352 (properties | pass->properties_provided) & ~pass->properties_destroyed;
353
354 /* Reset the counter when we reach RTL-based passes. */
355 if ((new_properties ^ pass->properties_required) & PROP_rtl)
356 n = 0;
357
358 pass_number = n;
359 if (pass->name)
360 n++;
361
362 if (pass->sub)
363 new_properties = register_dump_files (pass->sub, false, new_properties);
364
365 /* If we have a gate, combine the properties that we could have with
366 and without the pass being examined. */
367 if (pass->gate)
368 properties &= new_properties;
369 else
370 properties = new_properties;
371
372 pass->properties_provided = properties;
373 if (pass->name)
374 register_one_dump_file (pass, ipa, pass_number);
375
376 pass = pass->next;
377 }
378 while (pass);
379
380 return properties;
381 }
382
383 /* Add a pass to the pass list. Duplicate the pass if it's already
384 in the list. */
385
386 static struct tree_opt_pass **
387 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
388 {
389
390 /* A nonzero static_pass_number indicates that the
391 pass is already in the list. */
392 if (pass->static_pass_number)
393 {
394 struct tree_opt_pass *new;
395
396 new = xmalloc (sizeof (*new));
397 memcpy (new, pass, sizeof (*new));
398
399 /* Indicate to register_dump_files that this pass has duplicates,
400 and so it should rename the dump file. The first instance will
401 be -1, and be number of duplicates = -static_pass_number - 1.
402 Subsequent instances will be > 0 and just the duplicate number. */
403 if (pass->name)
404 {
405 pass->static_pass_number -= 1;
406 new->static_pass_number = -pass->static_pass_number;
407 }
408
409 *list = new;
410 }
411 else
412 {
413 pass->static_pass_number = -1;
414 *list = pass;
415 }
416
417 return &(*list)->next;
418
419 }
420
421 /* Construct the pass tree. */
422
423 void
424 init_optimization_passes (void)
425 {
426 struct tree_opt_pass **p;
427
428 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
429 /* Interprocedural optimization passes. */
430 p = &all_ipa_passes;
431 NEXT_PASS (pass_early_ipa_inline);
432 NEXT_PASS (pass_early_local_passes);
433 NEXT_PASS (pass_ipa_inline);
434 *p = NULL;
435
436 /* All passes needed to lower the function into shape optimizers can operate
437 on. These passes are performed before interprocedural passes, unlike rest
438 of local passes (all_passes). */
439 p = &all_lowering_passes;
440 NEXT_PASS (pass_remove_useless_stmts);
441 NEXT_PASS (pass_mudflap_1);
442 NEXT_PASS (pass_lower_cf);
443 NEXT_PASS (pass_lower_eh);
444 NEXT_PASS (pass_build_cfg);
445 NEXT_PASS (pass_lower_complex_O0);
446 NEXT_PASS (pass_lower_vector);
447 NEXT_PASS (pass_warn_function_return);
448 NEXT_PASS (pass_early_tree_profile);
449 *p = NULL;
450
451 p = &pass_early_local_passes.sub;
452 NEXT_PASS (pass_tree_profile);
453 NEXT_PASS (pass_cleanup_cfg);
454 NEXT_PASS (pass_rebuild_cgraph_edges);
455 *p = NULL;
456
457 p = &all_passes;
458 NEXT_PASS (pass_fixup_cfg);
459 NEXT_PASS (pass_init_datastructures);
460 NEXT_PASS (pass_all_optimizations);
461 NEXT_PASS (pass_warn_function_noreturn);
462 NEXT_PASS (pass_mudflap_2);
463 NEXT_PASS (pass_free_datastructures);
464 NEXT_PASS (pass_free_cfg_annotations);
465 NEXT_PASS (pass_expand);
466 NEXT_PASS (pass_rest_of_compilation);
467 NEXT_PASS (pass_clean_state);
468 *p = NULL;
469
470 p = &pass_all_optimizations.sub;
471 NEXT_PASS (pass_referenced_vars);
472 NEXT_PASS (pass_create_structure_vars);
473 NEXT_PASS (pass_build_ssa);
474 NEXT_PASS (pass_may_alias);
475 NEXT_PASS (pass_return_slot);
476 NEXT_PASS (pass_rename_ssa_copies);
477 NEXT_PASS (pass_early_warn_uninitialized);
478
479 /* Initial scalar cleanups. */
480 NEXT_PASS (pass_ccp);
481 NEXT_PASS (pass_fre);
482 NEXT_PASS (pass_dce);
483 NEXT_PASS (pass_forwprop);
484 NEXT_PASS (pass_copy_prop);
485 NEXT_PASS (pass_vrp);
486 NEXT_PASS (pass_dce);
487 NEXT_PASS (pass_merge_phi);
488 NEXT_PASS (pass_dominator);
489
490 NEXT_PASS (pass_phiopt);
491 NEXT_PASS (pass_may_alias);
492 NEXT_PASS (pass_tail_recursion);
493 NEXT_PASS (pass_profile);
494 NEXT_PASS (pass_ch);
495 NEXT_PASS (pass_stdarg);
496 NEXT_PASS (pass_lower_complex);
497 NEXT_PASS (pass_sra);
498 /* FIXME: SRA may generate arbitrary gimple code, exposing new
499 aliased and call-clobbered variables. As mentioned below,
500 pass_may_alias should be a TODO item. */
501 NEXT_PASS (pass_may_alias);
502 NEXT_PASS (pass_rename_ssa_copies);
503 NEXT_PASS (pass_dominator);
504 NEXT_PASS (pass_copy_prop);
505 NEXT_PASS (pass_dce);
506 NEXT_PASS (pass_dse);
507 NEXT_PASS (pass_may_alias);
508 NEXT_PASS (pass_forwprop);
509 NEXT_PASS (pass_phiopt);
510 NEXT_PASS (pass_object_sizes);
511 NEXT_PASS (pass_store_ccp);
512 NEXT_PASS (pass_store_copy_prop);
513 NEXT_PASS (pass_fold_builtins);
514 /* FIXME: May alias should a TODO but for 4.0.0,
515 we add may_alias right after fold builtins
516 which can create arbitrary GIMPLE. */
517 NEXT_PASS (pass_may_alias);
518 NEXT_PASS (pass_cse_reciprocals);
519 NEXT_PASS (pass_split_crit_edges);
520 NEXT_PASS (pass_reassoc);
521 NEXT_PASS (pass_pre);
522 NEXT_PASS (pass_sink_code);
523 NEXT_PASS (pass_loop);
524 NEXT_PASS (pass_dominator);
525 NEXT_PASS (pass_copy_prop);
526 NEXT_PASS (pass_cd_dce);
527
528 /* FIXME: If DCE is not run before checking for uninitialized uses,
529 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
530 However, this also causes us to misdiagnose cases that should be
531 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
532
533 To fix the false positives in uninit-5.c, we would have to
534 account for the predicates protecting the set and the use of each
535 variable. Using a representation like Gated Single Assignment
536 may help. */
537 NEXT_PASS (pass_late_warn_uninitialized);
538 NEXT_PASS (pass_dse);
539 NEXT_PASS (pass_forwprop);
540 NEXT_PASS (pass_phiopt);
541 NEXT_PASS (pass_tail_calls);
542 NEXT_PASS (pass_rename_ssa_copies);
543 NEXT_PASS (pass_uncprop);
544 NEXT_PASS (pass_del_ssa);
545 NEXT_PASS (pass_nrv);
546 NEXT_PASS (pass_remove_useless_vars);
547 NEXT_PASS (pass_mark_used_blocks);
548 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
549 *p = NULL;
550
551 p = &pass_loop.sub;
552 NEXT_PASS (pass_loop_init);
553 NEXT_PASS (pass_copy_prop);
554 NEXT_PASS (pass_lim);
555 NEXT_PASS (pass_unswitch);
556 NEXT_PASS (pass_scev_cprop);
557 NEXT_PASS (pass_record_bounds);
558 NEXT_PASS (pass_linear_transform);
559 NEXT_PASS (pass_iv_canon);
560 NEXT_PASS (pass_if_conversion);
561 NEXT_PASS (pass_vectorize);
562 /* NEXT_PASS (pass_may_alias) cannot be done again because the
563 vectorizer creates alias relations that are not supported by
564 pass_may_alias. */
565 NEXT_PASS (pass_lower_vector_ssa);
566 NEXT_PASS (pass_complete_unroll);
567 NEXT_PASS (pass_iv_optimize);
568 NEXT_PASS (pass_loop_done);
569 *p = NULL;
570
571 p = &pass_rest_of_compilation.sub;
572 NEXT_PASS (pass_remove_unnecessary_notes);
573 NEXT_PASS (pass_init_function);
574 NEXT_PASS (pass_jump);
575 NEXT_PASS (pass_insn_locators_initialize);
576 NEXT_PASS (pass_rtl_eh);
577 NEXT_PASS (pass_initial_value_sets);
578 NEXT_PASS (pass_unshare_all_rtl);
579 NEXT_PASS (pass_instantiate_virtual_regs);
580 NEXT_PASS (pass_jump2);
581 NEXT_PASS (pass_cse);
582 NEXT_PASS (pass_gcse);
583 NEXT_PASS (pass_loop_optimize);
584 NEXT_PASS (pass_jump_bypass);
585 NEXT_PASS (pass_cfg);
586 NEXT_PASS (pass_profiling);
587 NEXT_PASS (pass_rtl_ifcvt);
588 NEXT_PASS (pass_tracer);
589 NEXT_PASS (pass_loop2);
590 NEXT_PASS (pass_web);
591 NEXT_PASS (pass_cse2);
592 NEXT_PASS (pass_life);
593 NEXT_PASS (pass_combine);
594 NEXT_PASS (pass_if_after_combine);
595 NEXT_PASS (pass_partition_blocks);
596 NEXT_PASS (pass_regmove);
597 NEXT_PASS (pass_split_all_insns);
598 NEXT_PASS (pass_mode_switching);
599 NEXT_PASS (pass_recompute_reg_usage);
600 NEXT_PASS (pass_sms);
601 NEXT_PASS (pass_sched);
602 NEXT_PASS (pass_local_alloc);
603 NEXT_PASS (pass_global_alloc);
604 NEXT_PASS (pass_postreload);
605 *p = NULL;
606
607 p = &pass_profiling.sub;
608 NEXT_PASS (pass_branch_prob);
609 NEXT_PASS (pass_value_profile_transformations);
610 NEXT_PASS (pass_remove_death_notes);
611 *p = NULL;
612
613 p = &pass_postreload.sub;
614 NEXT_PASS (pass_postreload_cse);
615 NEXT_PASS (pass_gcse2);
616 NEXT_PASS (pass_flow2);
617 NEXT_PASS (pass_stack_adjustments);
618 NEXT_PASS (pass_peephole2);
619 NEXT_PASS (pass_if_after_reload);
620 NEXT_PASS (pass_regrename);
621 NEXT_PASS (pass_reorder_blocks);
622 NEXT_PASS (pass_branch_target_load_optimize);
623 NEXT_PASS (pass_leaf_regs);
624 NEXT_PASS (pass_sched2);
625 NEXT_PASS (pass_split_before_regstack);
626 NEXT_PASS (pass_stack_regs);
627 NEXT_PASS (pass_compute_alignments);
628 NEXT_PASS (pass_duplicate_computed_gotos);
629 NEXT_PASS (pass_variable_tracking);
630 NEXT_PASS (pass_free_cfg);
631 NEXT_PASS (pass_machine_reorg);
632 NEXT_PASS (pass_purge_lineno_notes);
633 NEXT_PASS (pass_cleanup_barriers);
634 NEXT_PASS (pass_delay_slots);
635 NEXT_PASS (pass_split_for_shorten_branches);
636 NEXT_PASS (pass_convert_to_eh_region_ranges);
637 NEXT_PASS (pass_shorten_branches);
638 NEXT_PASS (pass_set_nothrow_function_flags);
639 NEXT_PASS (pass_final);
640 *p = NULL;
641
642 #undef NEXT_PASS
643
644 /* Register the passes with the tree dump code. */
645 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
646 register_dump_files (all_passes, false, PROP_gimple_leh
647 | PROP_cfg);
648 register_dump_files (all_ipa_passes, true, PROP_gimple_leh
649 | PROP_cfg);
650 }
651
652 static unsigned int last_verified;
653
654 static void
655 execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
656 {
657 int properties
658 = use_required ? pass->properties_required : pass->properties_provided;
659
660 #if defined ENABLE_CHECKING
661 if (need_ssa_update_p ())
662 gcc_assert (flags & TODO_update_ssa_any);
663 #endif
664
665 /* Always cleanup the CFG before doing anything else. */
666 if (flags & TODO_cleanup_cfg)
667 {
668 if (current_loops)
669 cleanup_tree_cfg_loop ();
670 else
671 cleanup_tree_cfg ();
672 }
673
674 if (flags & TODO_update_ssa_any)
675 {
676 unsigned update_flags = flags & TODO_update_ssa_any;
677 update_ssa (update_flags);
678 }
679
680 if ((flags & TODO_dump_func)
681 && dump_file && current_function_decl)
682 {
683 if (properties & PROP_trees)
684 dump_function_to_file (current_function_decl,
685 dump_file, dump_flags);
686 else if (properties & PROP_cfg)
687 print_rtl_with_bb (dump_file, get_insns ());
688 else
689 print_rtl (dump_file, get_insns ());
690
691 /* Flush the file. If verification fails, we won't be able to
692 close the file before aborting. */
693 fflush (dump_file);
694 }
695 if ((flags & TODO_dump_cgraph)
696 && dump_file && !current_function_decl)
697 {
698 dump_cgraph (dump_file);
699 /* Flush the file. If verification fails, we won't be able to
700 close the file before aborting. */
701 fflush (dump_file);
702 }
703
704 if (flags & TODO_ggc_collect)
705 {
706 ggc_collect ();
707 }
708
709 #if defined ENABLE_CHECKING
710 if ((pass->properties_required & PROP_ssa)
711 && !(pass->properties_destroyed & PROP_ssa))
712 verify_ssa (true);
713 if (flags & TODO_verify_flow)
714 verify_flow_info ();
715 if (flags & TODO_verify_stmts)
716 verify_stmts ();
717 if (flags & TODO_verify_loops)
718 verify_loop_closed_ssa ();
719 #endif
720 }
721
722 static bool
723 execute_one_pass (struct tree_opt_pass *pass)
724 {
725 unsigned int todo;
726
727 /* See if we're supposed to run this pass. */
728 if (pass->gate && !pass->gate ())
729 return false;
730
731 /* Note that the folders should only create gimple expressions.
732 This is a hack until the new folder is ready. */
733 in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
734
735 /* Run pre-pass verification. */
736 todo = pass->todo_flags_start & ~last_verified;
737 if (todo)
738 execute_todo (pass, todo, true);
739
740 /* If a dump file name is present, open it if enabled. */
741 if (pass->static_pass_number != -1)
742 {
743 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
744 dump_file_name = get_dump_file_name (pass->static_pass_number);
745 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
746 if (dump_file && current_function_decl)
747 {
748 const char *dname, *aname;
749 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
750 aname = (IDENTIFIER_POINTER
751 (DECL_ASSEMBLER_NAME (current_function_decl)));
752 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
753 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
754 ? " (hot)"
755 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
756 ? " (unlikely executed)"
757 : "");
758 }
759
760 if (initializing_dump
761 && graph_dump_format != no_graph
762 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
763 == (PROP_cfg | PROP_rtl))
764 clean_graph_dump_file (dump_file_name);
765 }
766
767 /* If a timevar is present, start it. */
768 if (pass->tv_id)
769 timevar_push (pass->tv_id);
770
771 /* Do it! */
772 if (pass->execute)
773 pass->execute ();
774
775 /* Stop timevar. */
776 if (pass->tv_id)
777 timevar_pop (pass->tv_id);
778
779 /* Run post-pass cleanup and verification. */
780 todo = pass->todo_flags_finish;
781 last_verified = todo & TODO_verify_all;
782 if (todo)
783 execute_todo (pass, todo, false);
784
785 /* Flush and close dump file. */
786 if (dump_file_name)
787 {
788 free ((char *) dump_file_name);
789 dump_file_name = NULL;
790 }
791 if (dump_file)
792 {
793 dump_end (pass->static_pass_number, dump_file);
794 dump_file = NULL;
795 }
796
797 return true;
798 }
799
800 void
801 execute_pass_list (struct tree_opt_pass *pass)
802 {
803 do
804 {
805 if (execute_one_pass (pass) && pass->sub)
806 execute_pass_list (pass->sub);
807 pass = pass->next;
808 }
809 while (pass);
810 }
811
812 /* Same as execute_pass_list but assume that subpasses of IPA passes
813 are local passes. */
814 void
815 execute_ipa_pass_list (struct tree_opt_pass *pass)
816 {
817 do
818 {
819 if (execute_one_pass (pass) && pass->sub)
820 {
821 struct cgraph_node *node;
822 for (node = cgraph_nodes; node; node = node->next)
823 if (node->analyzed)
824 {
825 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
826 current_function_decl = node->decl;
827 execute_pass_list (pass->sub);
828 free_dominance_info (CDI_DOMINATORS);
829 free_dominance_info (CDI_POST_DOMINATORS);
830 current_function_decl = NULL;
831 pop_cfun ();
832 ggc_collect ();
833 }
834 }
835 pass = pass->next;
836 }
837 while (pass);
838 }