Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / passes.c
blob4139880ec132ffc20e1ec65fd48e730f704f3088
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.
5 This file is part of GCC.
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.
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.
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. */
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. */
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>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
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"
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
88 #endif
90 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
91 #include "dbxout.h"
92 #endif
94 #ifdef SDB_DEBUGGING_INFO
95 #include "sdbout.h"
96 #endif
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h" /* Needed for external data
100 declarations for e.g. AIX 4.x. */
101 #endif
103 /* Global variables used to communicate with passes. */
104 int dump_flags;
105 bool in_gimple_form;
108 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
109 and TYPE_DECL nodes.
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).
117 DECL is the declaration. TOP_LEVEL is nonzero
118 if this declaration is not within a function. */
120 void
121 rest_of_decl_compilation (tree decl,
122 int top_level,
123 int at_end)
125 /* We deferred calling assemble_alias so that we could collect
126 other attributes such as visibility. Emit the alias now. */
128 tree alias;
129 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
130 if (alias)
132 alias = TREE_VALUE (TREE_VALUE (alias));
133 alias = get_identifier (TREE_STRING_POINTER (alias));
134 assemble_alias (decl, alias);
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);
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)
148 timevar_push (TV_VARCONST);
150 /* Don't output anything when a tentative file-scope definition
151 is seen. But at end of compilation, do output code for them.
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))
161 if (TREE_CODE (decl) != FUNCTION_DECL)
162 cgraph_varpool_finalize_decl (decl);
163 else
164 assemble_variable (decl, top_level, at_end, 0);
167 #ifdef ASM_FINISH_DECLARE_OBJECT
168 if (decl == last_assemble_variable_decl)
170 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
171 top_level, at_end);
173 #endif
175 timevar_pop (TV_VARCONST);
177 else if (TREE_CODE (decl) == TYPE_DECL
178 /* Like in rest_of_type_compilation, avoid confusing the debug
179 information machinery when there are errors. */
180 && !(sorrycount || errorcount))
182 timevar_push (TV_SYMOUT);
183 debug_hooks->type_decl (decl, !top_level);
184 timevar_pop (TV_SYMOUT);
187 /* Let cgraph know about the existence of variables. */
188 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
189 cgraph_varpool_node (decl);
192 /* Called after finishing a record, union or enumeral type. */
194 void
195 rest_of_type_compilation (tree type, int toplev)
197 /* Avoid confusing the debug information machinery when there are
198 errors. */
199 if (errorcount != 0 || sorrycount != 0)
200 return;
202 timevar_push (TV_SYMOUT);
203 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
204 timevar_pop (TV_SYMOUT);
209 void
210 finish_optimization_passes (void)
212 enum tree_dump_index i;
213 struct dump_file_info *dfi;
214 char *name;
216 timevar_push (TV_DUMP);
217 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
219 dump_file = dump_begin (pass_branch_prob.static_pass_number, NULL);
220 end_branch_prob ();
221 if (dump_file)
222 dump_end (pass_branch_prob.static_pass_number, dump_file);
225 if (optimize > 0)
227 dump_file = dump_begin (pass_combine.static_pass_number, NULL);
228 if (dump_file)
230 dump_combine_total_stats (dump_file);
231 dump_end (pass_combine.static_pass_number, dump_file);
235 /* Do whatever is necessary to finish printing the graphs. */
236 if (graph_dump_format != no_graph)
237 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
238 if (dump_initialized_p (i)
239 && (dfi->flags & TDF_GRAPH) != 0
240 && (name = get_dump_file_name (i)) != NULL)
242 finish_graph_dump_file (name);
243 free (name);
246 timevar_pop (TV_DUMP);
249 static bool
250 gate_rest_of_compilation (void)
252 /* Early return if there were errors. We can run afoul of our
253 consistency checks, and there's not really much point in fixing them. */
254 return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
257 struct tree_opt_pass pass_rest_of_compilation =
259 NULL, /* name */
260 gate_rest_of_compilation, /* gate */
261 NULL, /* execute */
262 NULL, /* sub */
263 NULL, /* next */
264 0, /* static_pass_number */
265 TV_REST_OF_COMPILATION, /* tv_id */
266 PROP_rtl, /* properties_required */
267 0, /* properties_provided */
268 0, /* properties_destroyed */
269 0, /* todo_flags_start */
270 TODO_ggc_collect, /* todo_flags_finish */
271 0 /* letter */
274 static bool
275 gate_postreload (void)
277 return reload_completed;
280 struct tree_opt_pass pass_postreload =
282 NULL, /* name */
283 gate_postreload, /* gate */
284 NULL, /* execute */
285 NULL, /* sub */
286 NULL, /* next */
287 0, /* static_pass_number */
288 0, /* tv_id */
289 PROP_rtl, /* properties_required */
290 0, /* properties_provided */
291 0, /* properties_destroyed */
292 0, /* todo_flags_start */
293 TODO_ggc_collect, /* todo_flags_finish */
294 0 /* letter */
299 /* The root of the compilation pass tree, once constructed. */
300 struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
302 /* Iterate over the pass tree allocating dump file numbers. We want
303 to do this depth first, and independent of whether the pass is
304 enabled or not. */
306 static void
307 register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int n)
309 char *dot_name, *flag_name, *glob_name;
310 char num[10];
312 /* See below in next_pass_1. */
313 num[0] = '\0';
314 if (pass->static_pass_number != -1)
315 sprintf (num, "%d", ((int) pass->static_pass_number < 0
316 ? 1 : pass->static_pass_number));
318 dot_name = concat (".", pass->name, num, NULL);
319 if (ipa)
321 flag_name = concat ("ipa-", pass->name, num, NULL);
322 glob_name = concat ("ipa-", pass->name, NULL);
323 /* First IPA dump is cgraph that is dumped via separate channels. */
324 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
325 TDF_IPA, n + 1, 0);
327 else if (pass->properties_provided & PROP_trees)
329 flag_name = concat ("tree-", pass->name, num, NULL);
330 glob_name = concat ("tree-", pass->name, NULL);
331 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
332 TDF_TREE, n + TDI_tree_all, 0);
334 else
336 flag_name = concat ("rtl-", pass->name, num, NULL);
337 glob_name = concat ("rtl-", pass->name, NULL);
338 pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
339 TDF_RTL, n, pass->letter);
343 static int
344 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
346 static int n = 0;
349 int new_properties;
350 int pass_number;
352 pass->properties_required = properties;
353 new_properties =
354 (properties | pass->properties_provided) & ~pass->properties_destroyed;
356 /* Reset the counter when we reach RTL-based passes. */
357 if ((new_properties ^ pass->properties_required) & PROP_rtl)
358 n = 0;
360 pass_number = n;
361 if (pass->name)
362 n++;
364 if (pass->sub)
365 new_properties = register_dump_files (pass->sub, false, new_properties);
367 /* If we have a gate, combine the properties that we could have with
368 and without the pass being examined. */
369 if (pass->gate)
370 properties &= new_properties;
371 else
372 properties = new_properties;
374 pass->properties_provided = properties;
375 if (pass->name)
376 register_one_dump_file (pass, ipa, pass_number);
378 pass = pass->next;
380 while (pass);
382 return properties;
385 /* Add a pass to the pass list. Duplicate the pass if it's already
386 in the list. */
388 static struct tree_opt_pass **
389 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
392 /* A nonzero static_pass_number indicates that the
393 pass is already in the list. */
394 if (pass->static_pass_number)
396 struct tree_opt_pass *new;
398 new = xmalloc (sizeof (*new));
399 memcpy (new, pass, sizeof (*new));
401 /* Indicate to register_dump_files that this pass has duplicates,
402 and so it should rename the dump file. The first instance will
403 be -1, and be number of duplicates = -static_pass_number - 1.
404 Subsequent instances will be > 0 and just the duplicate number. */
405 if (pass->name)
407 pass->static_pass_number -= 1;
408 new->static_pass_number = -pass->static_pass_number;
411 *list = new;
413 else
415 pass->static_pass_number = -1;
416 *list = pass;
419 return &(*list)->next;
423 /* Construct the pass tree. The sequencing of passes is driven by
424 the cgraph routines:
426 cgraph_finalize_compilation_unit ()
427 for each node N in the cgraph
428 cgraph_analyze_function (N)
429 cgraph_lower_function (N) -> all_lowering_passes
431 If we are optimizing, cgraph_optimize is then invoked:
433 cgraph_optimize ()
434 ipa_passes () -> all_ipa_passes
435 cgraph_expand_all_functions ()
436 for each node N in the cgraph
437 cgraph_expand_function (N)
438 cgraph_lower_function (N) -> Now a NOP.
439 lang_hooks.callgraph.expand_function (DECL (N))
440 tree_rest_of_compilation (DECL (N)) -> all_passes
443 void
444 init_optimization_passes (void)
446 struct tree_opt_pass **p;
448 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
449 /* Interprocedural optimization passes. */
450 p = &all_ipa_passes;
451 NEXT_PASS (pass_early_ipa_inline);
452 NEXT_PASS (pass_early_local_passes);
453 NEXT_PASS (pass_cv);
454 NEXT_PASS (pass_ipa_cp);
455 NEXT_PASS (pass_ipa_inline);
456 NEXT_PASS (pass_ipa_reference);
457 NEXT_PASS (pass_ipa_pure_const);
458 NEXT_PASS (pass_ipa_type_escape);
459 *p = NULL;
461 /* All passes needed to lower the function into shape optimizers can
462 operate on. */
463 p = &all_lowering_passes;
464 NEXT_PASS (pass_remove_useless_stmts);
465 NEXT_PASS (pass_mudflap_1);
466 NEXT_PASS (pass_lower_cf);
467 NEXT_PASS (pass_lower_eh);
468 NEXT_PASS (pass_build_cfg);
469 NEXT_PASS (pass_lower_complex_O0);
470 NEXT_PASS (pass_lower_vector);
471 NEXT_PASS (pass_warn_function_return);
472 NEXT_PASS (pass_early_tree_profile);
473 *p = NULL;
475 p = &pass_early_local_passes.sub;
476 NEXT_PASS (pass_tree_profile);
477 NEXT_PASS (pass_cleanup_cfg);
478 NEXT_PASS (pass_rebuild_cgraph_edges);
479 *p = NULL;
481 p = &all_passes;
482 NEXT_PASS (pass_fixup_cfg);
483 NEXT_PASS (pass_init_datastructures);
484 NEXT_PASS (pass_all_optimizations);
485 NEXT_PASS (pass_warn_function_noreturn);
486 NEXT_PASS (pass_mudflap_2);
487 NEXT_PASS (pass_free_datastructures);
488 NEXT_PASS (pass_free_cfg_annotations);
489 NEXT_PASS (pass_expand);
490 NEXT_PASS (pass_rest_of_compilation);
491 NEXT_PASS (pass_clean_state);
492 *p = NULL;
494 p = &pass_all_optimizations.sub;
495 NEXT_PASS (pass_referenced_vars);
496 NEXT_PASS (pass_create_structure_vars);
497 NEXT_PASS (pass_build_ssa);
499 NEXT_PASS (pass_may_alias);
500 NEXT_PASS (pass_return_slot);
501 NEXT_PASS (pass_rename_ssa_copies);
502 NEXT_PASS (pass_early_warn_uninitialized);
503 NEXT_PASS (pass_eliminate_useless_stores);
505 /* Initial scalar cleanups. */
506 NEXT_PASS (pass_ccp);
507 NEXT_PASS (pass_fre);
508 NEXT_PASS (pass_dce);
509 NEXT_PASS (pass_forwprop);
510 NEXT_PASS (pass_copy_prop);
511 NEXT_PASS (pass_vrp);
512 NEXT_PASS (pass_dce);
513 NEXT_PASS (pass_merge_phi);
514 NEXT_PASS (pass_dominator);
516 /* The only copy propagation opportunities left after DOM
517 should be due to degenerate PHI nodes. So rather than
518 run the full copy propagator, just discover and copy
519 propagate away the degenerate PHI nodes. */
520 NEXT_PASS (pass_phi_only_copy_prop);
522 NEXT_PASS (pass_phiopt);
523 NEXT_PASS (pass_may_alias);
524 NEXT_PASS (pass_tail_recursion);
526 NEXT_PASS (pass_profile);
527 NEXT_PASS (pass_ch);
528 NEXT_PASS (pass_tree_loop0);
529 NEXT_PASS (pass_stdarg);
530 NEXT_PASS (pass_lower_complex);
531 NEXT_PASS (pass_sra);
532 /* FIXME: SRA may generate arbitrary gimple code, exposing new
533 aliased and call-clobbered variables. As mentioned below,
534 pass_may_alias should be a TODO item. */
535 NEXT_PASS (pass_may_alias);
536 NEXT_PASS (pass_rename_ssa_copies);
537 NEXT_PASS (pass_dominator);
539 /* The only copy propagation opportunities left after DOM
540 should be due to degenerate PHI nodes. So rather than
541 run the full copy propagator, just discover and copy
542 propagate away the degenerate PHI nodes. */
543 NEXT_PASS (pass_phi_only_copy_prop);
545 NEXT_PASS (pass_reassoc);
546 NEXT_PASS (pass_dce);
547 NEXT_PASS (pass_dse);
548 NEXT_PASS (pass_may_alias);
549 NEXT_PASS (pass_forwprop);
550 NEXT_PASS (pass_phiopt);
551 NEXT_PASS (pass_object_sizes);
552 NEXT_PASS (pass_store_ccp);
553 NEXT_PASS (pass_store_copy_prop);
554 NEXT_PASS (pass_fold_builtins);
555 /* FIXME: May alias should a TODO but for 4.0.0,
556 we add may_alias right after fold builtins
557 which can create arbitrary GIMPLE. */
558 NEXT_PASS (pass_may_alias);
559 NEXT_PASS (pass_cse_reciprocals);
560 NEXT_PASS (pass_split_crit_edges);
561 NEXT_PASS (pass_pre);
562 NEXT_PASS (pass_sink_code);
563 NEXT_PASS (pass_tree_loop);
564 NEXT_PASS (pass_reassoc);
565 NEXT_PASS (pass_dominator);
567 /* The only copy propagation opportunities left after DOM
568 should be due to degenerate PHI nodes. So rather than
569 run the full copy propagator, just discover and copy
570 propagate away the degenerate PHI nodes. */
571 NEXT_PASS (pass_phi_only_copy_prop);
573 NEXT_PASS (pass_cd_dce);
575 /* FIXME: If DCE is not run before checking for uninitialized uses,
576 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
577 However, this also causes us to misdiagnose cases that should be
578 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
580 To fix the false positives in uninit-5.c, we would have to
581 account for the predicates protecting the set and the use of each
582 variable. Using a representation like Gated Single Assignment
583 may help. */
584 NEXT_PASS (pass_late_warn_uninitialized);
585 NEXT_PASS (pass_dse);
586 NEXT_PASS (pass_forwprop);
587 NEXT_PASS (pass_phiopt);
588 NEXT_PASS (pass_tail_calls);
589 NEXT_PASS (pass_rename_ssa_copies);
590 NEXT_PASS (pass_uncprop);
591 NEXT_PASS (pass_del_ssa);
592 NEXT_PASS (pass_nrv);
593 NEXT_PASS (pass_remove_useless_vars);
594 NEXT_PASS (pass_mark_used_blocks);
595 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
596 *p = NULL;
598 p = &pass_tree_loop0.sub;
599 NEXT_PASS (pass_tree_loop_init);
600 NEXT_PASS (pass_complete_unroll);
601 NEXT_PASS (pass_tree_loop_done);
602 NEXT_PASS (pass_dominator);
603 NEXT_PASS (pass_phi_only_copy_prop);
604 NEXT_PASS (pass_tree_loop_init);
605 NEXT_PASS (pass_complete_unroll);
606 NEXT_PASS (pass_tree_loop_done);
607 NEXT_PASS (pass_dominator);
608 NEXT_PASS (pass_phi_only_copy_prop);
609 NEXT_PASS (pass_dce);
610 NEXT_PASS (pass_ccp);
611 NEXT_PASS (pass_forwprop);
612 NEXT_PASS (pass_may_alias);
613 NEXT_PASS (pass_ch);
615 *p = NULL;
617 /****************************************************/
619 p = &pass_tree_loop.sub;
620 NEXT_PASS (pass_tree_loop_init);
621 NEXT_PASS (pass_copy_prop);
622 NEXT_PASS (pass_lim);
623 NEXT_PASS (pass_tree_unswitch);
624 #if 0 /* FORNOW. FIXME */
625 NEXT_PASS (pass_scev_cprop);
626 #endif
627 NEXT_PASS (pass_empty_loop);
628 NEXT_PASS (pass_record_bounds);
629 NEXT_PASS (pass_elim_checks);
630 NEXT_PASS (pass_check_data_deps);
631 NEXT_PASS (pass_linear_transform);
632 NEXT_PASS (pass_iv_canon);
633 NEXT_PASS (pass_if_conversion);
634 NEXT_PASS (pass_vectorize);
635 /* NEXT_PASS (pass_may_alias) cannot be done again because the
636 vectorizer creates alias relations that are not supported by
637 pass_may_alias. */
638 NEXT_PASS (pass_complete_unroll);
639 NEXT_PASS (pass_iv_optimize);
640 NEXT_PASS (pass_tree_loop_done);
641 *p = NULL;
643 p = &pass_vectorize.sub;
644 NEXT_PASS (pass_lower_vector_ssa);
645 NEXT_PASS (pass_dce_loop);
646 *p = NULL;
648 p = &pass_loop2.sub;
649 NEXT_PASS (pass_rtl_loop_init);
650 NEXT_PASS (pass_rtl_move_loop_invariants);
651 NEXT_PASS (pass_rtl_unswitch);
652 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
653 NEXT_PASS (pass_rtl_doloop);
654 NEXT_PASS (pass_rtl_loop_done);
655 *p = NULL;
657 p = &pass_rest_of_compilation.sub;
658 NEXT_PASS (pass_remove_unnecessary_notes);
659 NEXT_PASS (pass_init_function);
660 NEXT_PASS (pass_jump);
661 NEXT_PASS (pass_insn_locators_initialize);
662 NEXT_PASS (pass_rtl_eh);
663 NEXT_PASS (pass_initial_value_sets);
664 NEXT_PASS (pass_unshare_all_rtl);
665 NEXT_PASS (pass_instantiate_virtual_regs);
666 NEXT_PASS (pass_jump2);
667 NEXT_PASS (pass_cse);
668 NEXT_PASS (pass_gcse);
669 NEXT_PASS (pass_loop_optimize);
670 NEXT_PASS (pass_jump_bypass);
671 NEXT_PASS (pass_cfg);
672 NEXT_PASS (pass_branch_prob);
673 NEXT_PASS (pass_rtl_ifcvt);
674 NEXT_PASS (pass_tracer);
675 /* Perform loop optimizations. It might be better to do them a bit
676 sooner, but we want the profile feedback to work more
677 efficiently. */
678 NEXT_PASS (pass_loop2);
679 NEXT_PASS (pass_web);
680 NEXT_PASS (pass_cse2);
681 NEXT_PASS (pass_life);
682 NEXT_PASS (pass_combine);
683 NEXT_PASS (pass_if_after_combine);
684 NEXT_PASS (pass_partition_blocks);
685 NEXT_PASS (pass_regmove);
686 NEXT_PASS (pass_split_all_insns);
687 NEXT_PASS (pass_mode_switching);
688 NEXT_PASS (pass_recompute_reg_usage);
689 NEXT_PASS (pass_sms);
690 NEXT_PASS (pass_sched);
691 NEXT_PASS (pass_local_alloc);
692 NEXT_PASS (pass_global_alloc);
693 NEXT_PASS (pass_postreload);
694 *p = NULL;
696 p = &pass_postreload.sub;
697 NEXT_PASS (pass_postreload_cse);
698 NEXT_PASS (pass_gcse2);
699 NEXT_PASS (pass_flow2);
700 NEXT_PASS (pass_stack_adjustments);
701 NEXT_PASS (pass_peephole2);
702 NEXT_PASS (pass_if_after_reload);
703 NEXT_PASS (pass_regrename);
704 NEXT_PASS (pass_reorder_blocks);
705 NEXT_PASS (pass_branch_target_load_optimize);
706 NEXT_PASS (pass_leaf_regs);
707 NEXT_PASS (pass_sched2);
708 NEXT_PASS (pass_split_before_regstack);
709 NEXT_PASS (pass_stack_regs);
710 NEXT_PASS (pass_compute_alignments);
711 NEXT_PASS (pass_duplicate_computed_gotos);
712 NEXT_PASS (pass_variable_tracking);
713 NEXT_PASS (pass_free_cfg);
714 NEXT_PASS (pass_machine_reorg);
715 NEXT_PASS (pass_purge_lineno_notes);
716 NEXT_PASS (pass_cleanup_barriers);
717 NEXT_PASS (pass_delay_slots);
718 NEXT_PASS (pass_split_for_shorten_branches);
719 NEXT_PASS (pass_convert_to_eh_region_ranges);
720 NEXT_PASS (pass_shorten_branches);
721 NEXT_PASS (pass_set_nothrow_function_flags);
722 NEXT_PASS (pass_final);
723 *p = NULL;
725 #undef NEXT_PASS
727 /* Register the passes with the tree dump code. */
728 register_dump_files (all_ipa_passes, true, PROP_gimple_leh | PROP_cfg);
729 register_dump_files (all_lowering_passes, false, PROP_gimple_any);
730 register_dump_files (all_passes, false, PROP_gimple_leh | PROP_cfg);
733 static unsigned int last_verified;
735 static void
736 execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
738 int properties
739 = use_required ? pass->properties_required : pass->properties_provided;
741 #if defined ENABLE_CHECKING
742 if (need_ssa_update_p ())
743 gcc_assert (flags & TODO_update_ssa_any);
744 #endif
746 /* Always cleanup the CFG before doing anything else. */
747 if (flags & TODO_cleanup_cfg)
749 if (current_loops)
750 cleanup_tree_cfg_loop ();
751 else
752 cleanup_tree_cfg ();
754 /* When cleanup_tree_cfg merges consecutive blocks, it may
755 perform some simplistic propagation when removing single
756 valued PHI nodes. This propagation may, in turn, cause the
757 SSA form to become out-of-date (see PR 22037). So, even
758 if the parent pass had not scheduled an SSA update, we may
759 still need to do one. */
760 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
761 flags |= TODO_update_ssa;
764 if (flags & TODO_update_ssa_any)
766 unsigned update_flags = flags & TODO_update_ssa_any;
767 update_ssa (update_flags);
770 if ((flags & TODO_dump_func)
771 && dump_file && current_function_decl)
773 if (properties & PROP_trees)
774 dump_function_to_file (current_function_decl,
775 dump_file, dump_flags);
776 else if (properties & PROP_cfg)
778 print_rtl_with_bb (dump_file, get_insns ());
780 if (graph_dump_format != no_graph
781 && (dump_flags & TDF_GRAPH))
782 print_rtl_graph_with_bb (dump_file_name, get_insns ());
784 else
785 print_rtl (dump_file, get_insns ());
787 /* Flush the file. If verification fails, we won't be able to
788 close the file before aborting. */
789 fflush (dump_file);
791 if ((flags & TODO_dump_cgraph)
792 && dump_file && !current_function_decl)
794 dump_cgraph (dump_file);
795 /* Flush the file. If verification fails, we won't be able to
796 close the file before aborting. */
797 fflush (dump_file);
800 if (flags & TODO_ggc_collect)
802 ggc_collect ();
805 #if defined ENABLE_CHECKING
806 if ((pass->properties_required & PROP_ssa)
807 && !(pass->properties_destroyed & PROP_ssa))
808 verify_ssa (true);
809 if (flags & TODO_verify_flow)
810 verify_flow_info ();
811 if (flags & TODO_verify_stmts)
812 verify_stmts ();
813 if (flags & TODO_verify_loops)
814 verify_loop_closed_ssa ();
815 #endif
818 static bool
819 execute_one_pass (struct tree_opt_pass *pass)
821 unsigned int todo;
823 /* See if we're supposed to run this pass. */
824 if (pass->gate && !pass->gate ())
825 return false;
827 /* Note that the folders should only create gimple expressions.
828 This is a hack until the new folder is ready. */
829 in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
831 /* Run pre-pass verification. */
832 todo = pass->todo_flags_start & ~last_verified;
833 if (todo)
834 execute_todo (pass, todo, true);
836 /* If a dump file name is present, open it if enabled. */
837 if (pass->static_pass_number != -1)
839 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
840 dump_file_name = get_dump_file_name (pass->static_pass_number);
841 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
842 if (dump_file && current_function_decl)
844 const char *dname, *aname;
845 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
846 aname = (IDENTIFIER_POINTER
847 (DECL_ASSEMBLER_NAME (current_function_decl)));
848 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
849 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
850 ? " (hot)"
851 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
852 ? " (unlikely executed)"
853 : "");
856 if (initializing_dump
857 && dump_file
858 && graph_dump_format != no_graph
859 && (pass->properties_provided & (PROP_cfg | PROP_rtl))
860 == (PROP_cfg | PROP_rtl))
862 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
863 dump_flags |= TDF_GRAPH;
864 clean_graph_dump_file (dump_file_name);
868 /* If a timevar is present, start it. */
869 if (pass->tv_id)
870 timevar_push (pass->tv_id);
872 /* Do it! */
873 if (pass->execute)
874 pass->execute ();
876 /* Stop timevar. */
877 if (pass->tv_id)
878 timevar_pop (pass->tv_id);
880 /* Run post-pass cleanup and verification. */
881 todo = pass->todo_flags_finish;
882 last_verified = todo & TODO_verify_all;
883 if (todo)
884 execute_todo (pass, todo, false);
886 /* Flush and close dump file. */
887 if (dump_file_name)
889 free ((char *) dump_file_name);
890 dump_file_name = NULL;
892 if (dump_file)
894 dump_end (pass->static_pass_number, dump_file);
895 dump_file = NULL;
898 return true;
901 void
902 execute_pass_list (struct tree_opt_pass *pass)
906 if (execute_one_pass (pass) && pass->sub)
907 execute_pass_list (pass->sub);
908 pass = pass->next;
910 while (pass);
913 /* Same as execute_pass_list but assume that subpasses of IPA passes
914 are local passes. */
915 void
916 execute_ipa_pass_list (struct tree_opt_pass *pass)
920 if (execute_one_pass (pass) && pass->sub)
922 struct cgraph_node *node;
923 for (node = cgraph_nodes; node; node = node->next)
924 if (node->analyzed)
926 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
927 current_function_decl = node->decl;
928 execute_pass_list (pass->sub);
929 free_dominance_info (CDI_DOMINATORS);
930 free_dominance_info (CDI_POST_DOMINATORS);
931 current_function_decl = NULL;
932 pop_cfun ();
933 ggc_collect ();
936 pass = pass->next;
938 while (pass);