OSDN Git Service

* Makefile.in: Add ipcp.c, ipa-prop.h, ipa-prop.c. Remove integrate.h
[pf3gnuchains/gcc-fork.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            /* Like in rest_of_type_compilation, avoid confusing the debug
180               information machinery when there are errors.  */
181            && !(sorrycount || errorcount))
182     {
183       timevar_push (TV_SYMOUT);
184       debug_hooks->type_decl (decl, !top_level);
185       timevar_pop (TV_SYMOUT);
186     }
187
188   /* Let cgraph know about the existence of variables.  */
189   if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
190     cgraph_varpool_node (decl);
191 }
192
193 /* Called after finishing a record, union or enumeral type.  */
194
195 void
196 rest_of_type_compilation (tree type, int toplev)
197 {
198   /* Avoid confusing the debug information machinery when there are
199      errors.  */
200   if (errorcount != 0 || sorrycount != 0)
201     return;
202
203   timevar_push (TV_SYMOUT);
204   debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
205   timevar_pop (TV_SYMOUT);
206 }
207
208 \f
209
210 void
211 finish_optimization_passes (void)
212 {
213   enum tree_dump_index i;
214   struct dump_file_info *dfi;
215   char *name;
216
217   timevar_push (TV_DUMP);
218   if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
219     {
220       dump_file = dump_begin (pass_branch_prob.static_pass_number, NULL);
221       end_branch_prob ();
222       if (dump_file)
223         dump_end (pass_branch_prob.static_pass_number, dump_file);
224     }
225
226   if (optimize > 0)
227     {
228       dump_file = dump_begin (pass_combine.static_pass_number, NULL);
229       if (dump_file)
230         {
231           dump_combine_total_stats (dump_file);
232           dump_end (pass_combine.static_pass_number, dump_file);
233         }
234     }
235
236   /* Do whatever is necessary to finish printing the graphs.  */
237   if (graph_dump_format != no_graph)
238     for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
239       if (dump_initialized_p (i)
240           && (dfi->flags & TDF_RTL) != 0
241           && (name = get_dump_file_name (i)) != NULL)
242         {
243           finish_graph_dump_file (name);
244           free (name);
245         }
246
247   timevar_pop (TV_DUMP);
248 }
249
250 static bool
251 gate_rest_of_compilation (void)
252 {
253   /* Early return if there were errors.  We can run afoul of our
254      consistency checks, and there's not really much point in fixing them.  */
255   return !(rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount);
256 }
257
258 struct tree_opt_pass pass_rest_of_compilation =
259 {
260   NULL,                                 /* name */
261   gate_rest_of_compilation,             /* gate */
262   NULL,                                 /* execute */
263   NULL,                                 /* sub */
264   NULL,                                 /* next */
265   0,                                    /* static_pass_number */
266   TV_REST_OF_COMPILATION,               /* tv_id */
267   PROP_rtl,                             /* properties_required */
268   0,                                    /* properties_provided */
269   0,                                    /* properties_destroyed */
270   0,                                    /* todo_flags_start */
271   TODO_ggc_collect,                     /* todo_flags_finish */
272   0                                     /* letter */
273 };
274
275 static bool
276 gate_postreload (void)
277 {
278   return reload_completed;
279 }
280
281 struct tree_opt_pass pass_postreload =
282 {
283   NULL,                                 /* name */
284   gate_postreload,                      /* gate */
285   NULL,                                 /* execute */
286   NULL,                                 /* sub */
287   NULL,                                 /* next */
288   0,                                    /* static_pass_number */
289   0,                                    /* tv_id */
290   PROP_rtl,                             /* properties_required */
291   0,                                    /* properties_provided */
292   0,                                    /* properties_destroyed */
293   0,                                    /* todo_flags_start */
294   TODO_ggc_collect,                     /* todo_flags_finish */
295   0                                     /* letter */
296 };
297
298
299
300 /* The root of the compilation pass tree, once constructed.  */
301 struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes;
302
303 /* Iterate over the pass tree allocating dump file numbers.  We want
304    to do this depth first, and independent of whether the pass is
305    enabled or not.  */
306
307 static void
308 register_one_dump_file (struct tree_opt_pass *pass, bool ipa, int n)
309 {
310   char *dot_name, *flag_name, *glob_name;
311   char num[10];
312
313   /* See below in next_pass_1.  */
314   num[0] = '\0';
315   if (pass->static_pass_number != -1)
316     sprintf (num, "%d", ((int) pass->static_pass_number < 0
317                          ? 1 : pass->static_pass_number));
318
319   dot_name = concat (".", pass->name, num, NULL);
320   if (ipa)
321     {
322       flag_name = concat ("ipa-", pass->name, num, NULL);
323       glob_name = concat ("ipa-", pass->name, NULL);
324       /* First IPA dump is cgraph that is dumped via separate channels.  */
325       pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
326                                                 TDF_IPA, n + 1, 0);
327     }
328   else if (pass->properties_provided & PROP_trees)
329     {
330       flag_name = concat ("tree-", pass->name, num, NULL);
331       glob_name = concat ("tree-", pass->name, NULL);
332       pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
333                                                 TDF_TREE, n + TDI_tree_all, 0);
334     }
335   else
336     {
337       flag_name = concat ("rtl-", pass->name, num, NULL);
338       glob_name = concat ("rtl-", pass->name, NULL);
339       pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
340                                                 TDF_RTL, n, pass->letter);
341     }
342 }
343
344 static int 
345 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
346 {
347   static int n = 0;
348   do
349     {
350       int new_properties;
351       int pass_number;
352
353       pass->properties_required = properties;
354       new_properties =
355         (properties | pass->properties_provided) & ~pass->properties_destroyed;
356
357       /* Reset the counter when we reach RTL-based passes.  */
358       if ((new_properties ^ pass->properties_required) & PROP_rtl)
359         n = 0;
360
361       pass_number = n;
362       if (pass->name)
363         n++;
364
365       if (pass->sub)
366         new_properties = register_dump_files (pass->sub, false, new_properties);
367
368       /* If we have a gate, combine the properties that we could have with
369          and without the pass being examined.  */
370       if (pass->gate)
371         properties &= new_properties;
372       else
373         properties = new_properties;
374
375       pass->properties_provided = properties;
376       if (pass->name)
377         register_one_dump_file (pass, ipa, pass_number);
378
379       pass = pass->next;
380     }
381   while (pass);
382
383   return properties;
384 }
385
386 /* Add a pass to the pass list. Duplicate the pass if it's already
387    in the list.  */
388
389 static struct tree_opt_pass **
390 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
391 {
392
393   /* A nonzero static_pass_number indicates that the
394      pass is already in the list.  */
395   if (pass->static_pass_number)
396     {
397       struct tree_opt_pass *new;
398
399       new = xmalloc (sizeof (*new));
400       memcpy (new, pass, sizeof (*new));
401
402       /* Indicate to register_dump_files that this pass has duplicates,
403          and so it should rename the dump file.  The first instance will
404          be -1, and be number of duplicates = -static_pass_number - 1.
405          Subsequent instances will be > 0 and just the duplicate number.  */
406       if (pass->name)
407         {
408           pass->static_pass_number -= 1;
409           new->static_pass_number = -pass->static_pass_number;
410         }
411       
412       *list = new;
413     }
414   else
415     {
416       pass->static_pass_number = -1;
417       *list = pass;
418     }  
419   
420   return &(*list)->next;
421           
422 }
423
424 /* Construct the pass tree.  */
425
426 void
427 init_optimization_passes (void)
428 {
429   struct tree_opt_pass **p;
430
431 #define NEXT_PASS(PASS)  (p = next_pass_1 (p, &PASS))
432   /* Interprocedural optimization passes.  */
433   p = &all_ipa_passes;
434   NEXT_PASS (pass_early_ipa_inline);
435   NEXT_PASS (pass_early_local_passes);
436   NEXT_PASS (pass_ipa_cp);
437   NEXT_PASS (pass_ipa_inline);
438   NEXT_PASS (pass_ipa_reference);
439   NEXT_PASS (pass_ipa_pure_const); 
440   NEXT_PASS (pass_ipa_type_escape);
441   *p = NULL;
442
443   /* All passes needed to lower the function into shape optimizers can operate
444      on.  These passes are performed before interprocedural passes, unlike rest
445      of local passes (all_passes).  */
446   p = &all_lowering_passes;
447   NEXT_PASS (pass_remove_useless_stmts);
448   NEXT_PASS (pass_mudflap_1);
449   NEXT_PASS (pass_lower_cf);
450   NEXT_PASS (pass_lower_eh);
451   NEXT_PASS (pass_build_cfg);
452   NEXT_PASS (pass_lower_complex_O0);
453   NEXT_PASS (pass_lower_vector);
454   NEXT_PASS (pass_warn_function_return);
455   NEXT_PASS (pass_early_tree_profile);
456   *p = NULL;
457
458   p = &pass_early_local_passes.sub;
459   NEXT_PASS (pass_tree_profile);
460   NEXT_PASS (pass_cleanup_cfg);
461   NEXT_PASS (pass_rebuild_cgraph_edges);
462   *p = NULL;
463
464   p = &all_passes;
465   NEXT_PASS (pass_fixup_cfg);
466   NEXT_PASS (pass_init_datastructures);
467   NEXT_PASS (pass_all_optimizations);
468   NEXT_PASS (pass_warn_function_noreturn);
469   NEXT_PASS (pass_mudflap_2);
470   NEXT_PASS (pass_free_datastructures);
471   NEXT_PASS (pass_free_cfg_annotations);
472   NEXT_PASS (pass_expand);
473   NEXT_PASS (pass_rest_of_compilation);
474   NEXT_PASS (pass_clean_state);
475   *p = NULL;
476
477   p = &pass_all_optimizations.sub;
478   NEXT_PASS (pass_referenced_vars);
479   NEXT_PASS (pass_create_structure_vars);
480   NEXT_PASS (pass_build_ssa);
481   NEXT_PASS (pass_may_alias);
482   NEXT_PASS (pass_return_slot);
483   NEXT_PASS (pass_rename_ssa_copies);
484   NEXT_PASS (pass_early_warn_uninitialized);
485   NEXT_PASS (pass_eliminate_useless_stores);
486
487   /* Initial scalar cleanups.  */
488   NEXT_PASS (pass_ccp);
489   NEXT_PASS (pass_fre);
490   NEXT_PASS (pass_dce);
491   NEXT_PASS (pass_forwprop);
492   NEXT_PASS (pass_copy_prop);
493   NEXT_PASS (pass_vrp);
494   NEXT_PASS (pass_dce);
495   NEXT_PASS (pass_merge_phi);
496   NEXT_PASS (pass_dominator);
497
498   NEXT_PASS (pass_phiopt);
499   NEXT_PASS (pass_may_alias);
500   NEXT_PASS (pass_tail_recursion);
501   NEXT_PASS (pass_profile);
502   NEXT_PASS (pass_ch);
503   NEXT_PASS (pass_stdarg);
504   NEXT_PASS (pass_lower_complex);
505   NEXT_PASS (pass_sra);
506   /* FIXME: SRA may generate arbitrary gimple code, exposing new
507      aliased and call-clobbered variables.  As mentioned below,
508      pass_may_alias should be a TODO item.  */
509   NEXT_PASS (pass_may_alias);
510   NEXT_PASS (pass_rename_ssa_copies);
511   NEXT_PASS (pass_dominator);
512   NEXT_PASS (pass_copy_prop);
513   NEXT_PASS (pass_dce);
514   NEXT_PASS (pass_dse);
515   NEXT_PASS (pass_may_alias);
516   NEXT_PASS (pass_forwprop);
517   NEXT_PASS (pass_phiopt);
518   NEXT_PASS (pass_object_sizes);
519   NEXT_PASS (pass_store_ccp);
520   NEXT_PASS (pass_store_copy_prop);
521   NEXT_PASS (pass_fold_builtins);
522   /* FIXME: May alias should a TODO but for 4.0.0,
523      we add may_alias right after fold builtins
524      which can create arbitrary GIMPLE.  */
525   NEXT_PASS (pass_may_alias);
526   NEXT_PASS (pass_cse_reciprocals);
527   NEXT_PASS (pass_split_crit_edges);
528   NEXT_PASS (pass_reassoc);
529   NEXT_PASS (pass_pre);
530   NEXT_PASS (pass_sink_code);
531   NEXT_PASS (pass_tree_loop);
532   NEXT_PASS (pass_dominator);
533   NEXT_PASS (pass_copy_prop);
534   NEXT_PASS (pass_cd_dce);
535
536   /* FIXME: If DCE is not run before checking for uninitialized uses,
537      we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
538      However, this also causes us to misdiagnose cases that should be
539      real warnings (e.g., testsuite/gcc.dg/pr18501.c).
540      
541      To fix the false positives in uninit-5.c, we would have to
542      account for the predicates protecting the set and the use of each
543      variable.  Using a representation like Gated Single Assignment
544      may help.  */
545   NEXT_PASS (pass_late_warn_uninitialized);
546   NEXT_PASS (pass_dse);
547   NEXT_PASS (pass_forwprop);
548   NEXT_PASS (pass_phiopt);
549   NEXT_PASS (pass_tail_calls);
550   NEXT_PASS (pass_rename_ssa_copies);
551   NEXT_PASS (pass_uncprop);
552   NEXT_PASS (pass_del_ssa);
553   NEXT_PASS (pass_nrv);
554   NEXT_PASS (pass_remove_useless_vars);
555   NEXT_PASS (pass_mark_used_blocks);
556   NEXT_PASS (pass_cleanup_cfg_post_optimizing);
557   *p = NULL;
558
559   p = &pass_tree_loop.sub;
560   NEXT_PASS (pass_tree_loop_init);
561   NEXT_PASS (pass_copy_prop);
562   NEXT_PASS (pass_lim);
563   NEXT_PASS (pass_tree_unswitch);
564   NEXT_PASS (pass_scev_cprop);
565   NEXT_PASS (pass_empty_loop);
566   NEXT_PASS (pass_record_bounds);
567   NEXT_PASS (pass_linear_transform);
568   NEXT_PASS (pass_iv_canon);
569   NEXT_PASS (pass_if_conversion);
570   NEXT_PASS (pass_vectorize);
571   /* NEXT_PASS (pass_may_alias) cannot be done again because the
572      vectorizer creates alias relations that are not supported by
573      pass_may_alias.  */
574   NEXT_PASS (pass_lower_vector_ssa);
575   NEXT_PASS (pass_complete_unroll);
576   NEXT_PASS (pass_iv_optimize);
577   NEXT_PASS (pass_tree_loop_done);
578   *p = NULL;
579
580   p = &pass_loop2.sub;
581   NEXT_PASS (pass_rtl_loop_init);
582   NEXT_PASS (pass_rtl_move_loop_invariants);
583   NEXT_PASS (pass_rtl_unswitch);
584   NEXT_PASS (pass_rtl_unroll_and_peel_loops);
585   NEXT_PASS (pass_rtl_doloop);
586   NEXT_PASS (pass_rtl_loop_done);
587   *p = NULL;
588   
589   p = &pass_rest_of_compilation.sub;
590   NEXT_PASS (pass_remove_unnecessary_notes);
591   NEXT_PASS (pass_init_function);
592   NEXT_PASS (pass_jump);
593   NEXT_PASS (pass_insn_locators_initialize);
594   NEXT_PASS (pass_rtl_eh);
595   NEXT_PASS (pass_initial_value_sets);
596   NEXT_PASS (pass_unshare_all_rtl);
597   NEXT_PASS (pass_instantiate_virtual_regs);
598   NEXT_PASS (pass_jump2);
599   NEXT_PASS (pass_cse);
600   NEXT_PASS (pass_gcse);
601   NEXT_PASS (pass_loop_optimize);
602   NEXT_PASS (pass_jump_bypass);
603   NEXT_PASS (pass_cfg);
604   NEXT_PASS (pass_branch_prob);
605   NEXT_PASS (pass_rtl_ifcvt);
606   NEXT_PASS (pass_tracer);
607   /* Perform loop optimizations.  It might be better to do them a bit
608      sooner, but we want the profile feedback to work more
609      efficiently.  */
610   NEXT_PASS (pass_loop2);
611   NEXT_PASS (pass_web);
612   NEXT_PASS (pass_cse2);
613   NEXT_PASS (pass_life);
614   NEXT_PASS (pass_combine);
615   NEXT_PASS (pass_if_after_combine);
616   NEXT_PASS (pass_partition_blocks);
617   NEXT_PASS (pass_regmove);
618   NEXT_PASS (pass_split_all_insns);
619   NEXT_PASS (pass_mode_switching);
620   NEXT_PASS (pass_recompute_reg_usage);
621   NEXT_PASS (pass_sms);
622   NEXT_PASS (pass_sched);
623   NEXT_PASS (pass_local_alloc);
624   NEXT_PASS (pass_global_alloc);
625   NEXT_PASS (pass_postreload);
626   *p = NULL;
627
628   p = &pass_postreload.sub;
629   NEXT_PASS (pass_postreload_cse);
630   NEXT_PASS (pass_gcse2);
631   NEXT_PASS (pass_flow2);
632   NEXT_PASS (pass_stack_adjustments);
633   NEXT_PASS (pass_peephole2);
634   NEXT_PASS (pass_if_after_reload);
635   NEXT_PASS (pass_regrename);
636   NEXT_PASS (pass_reorder_blocks);
637   NEXT_PASS (pass_branch_target_load_optimize);
638   NEXT_PASS (pass_leaf_regs);
639   NEXT_PASS (pass_sched2);
640   NEXT_PASS (pass_split_before_regstack);
641   NEXT_PASS (pass_stack_regs);
642   NEXT_PASS (pass_compute_alignments);
643   NEXT_PASS (pass_duplicate_computed_gotos);
644   NEXT_PASS (pass_variable_tracking);
645   NEXT_PASS (pass_free_cfg);
646   NEXT_PASS (pass_machine_reorg);
647   NEXT_PASS (pass_purge_lineno_notes);
648   NEXT_PASS (pass_cleanup_barriers);
649   NEXT_PASS (pass_delay_slots);
650   NEXT_PASS (pass_split_for_shorten_branches);
651   NEXT_PASS (pass_convert_to_eh_region_ranges);
652   NEXT_PASS (pass_shorten_branches);
653   NEXT_PASS (pass_set_nothrow_function_flags);
654   NEXT_PASS (pass_final);
655   *p = NULL;
656
657 #undef NEXT_PASS
658
659   /* Register the passes with the tree dump code.  */
660   register_dump_files (all_lowering_passes, false, PROP_gimple_any);
661   register_dump_files (all_passes, false, PROP_gimple_leh
662                                           | PROP_cfg);
663   register_dump_files (all_ipa_passes, true, PROP_gimple_leh
664                                              | PROP_cfg);
665 }
666
667 static unsigned int last_verified;
668
669 static void
670 execute_todo (struct tree_opt_pass *pass, unsigned int flags, bool use_required)
671 {
672   int properties 
673     = use_required ? pass->properties_required : pass->properties_provided;
674
675 #if defined ENABLE_CHECKING
676   if (need_ssa_update_p ())
677     gcc_assert (flags & TODO_update_ssa_any);
678 #endif
679
680   /* Always cleanup the CFG before doing anything else.  */
681   if (flags & TODO_cleanup_cfg)
682     {
683       if (current_loops)
684         cleanup_tree_cfg_loop ();
685       else
686         cleanup_tree_cfg ();
687     }
688
689   if (flags & TODO_update_ssa_any)
690     {
691       unsigned update_flags = flags & TODO_update_ssa_any;
692       update_ssa (update_flags);
693     }
694
695   if ((flags & TODO_dump_func)
696       && dump_file && current_function_decl)
697     {
698       if (properties & PROP_trees)
699         dump_function_to_file (current_function_decl,
700                                dump_file, dump_flags);
701       else if (properties & PROP_cfg)
702         print_rtl_with_bb (dump_file, get_insns ());
703       else
704         print_rtl (dump_file, get_insns ());
705
706       /* Flush the file.  If verification fails, we won't be able to
707          close the file before aborting.  */
708       fflush (dump_file);
709     }
710   if ((flags & TODO_dump_cgraph)
711       && dump_file && !current_function_decl)
712     {
713       dump_cgraph (dump_file);
714       /* Flush the file.  If verification fails, we won't be able to
715          close the file before aborting.  */
716       fflush (dump_file);
717     }
718
719   if (flags & TODO_ggc_collect)
720     {
721       ggc_collect ();
722     }
723
724 #if defined ENABLE_CHECKING
725   if ((pass->properties_required & PROP_ssa)
726       && !(pass->properties_destroyed & PROP_ssa))
727     verify_ssa (true);
728   if (flags & TODO_verify_flow)
729     verify_flow_info ();
730   if (flags & TODO_verify_stmts)
731     verify_stmts ();
732   if (flags & TODO_verify_loops)
733     verify_loop_closed_ssa ();
734 #endif
735 }
736
737 static bool
738 execute_one_pass (struct tree_opt_pass *pass)
739 {
740   unsigned int todo; 
741
742   /* See if we're supposed to run this pass.  */
743   if (pass->gate && !pass->gate ())
744     return false;
745
746   /* Note that the folders should only create gimple expressions.
747      This is a hack until the new folder is ready.  */
748   in_gimple_form = (pass->properties_provided & PROP_trees) != 0;
749
750   /* Run pre-pass verification.  */
751   todo = pass->todo_flags_start & ~last_verified;
752   if (todo)
753     execute_todo (pass, todo, true);
754
755   /* If a dump file name is present, open it if enabled.  */
756   if (pass->static_pass_number != -1)
757     {
758       bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
759       dump_file_name = get_dump_file_name (pass->static_pass_number);
760       dump_file = dump_begin (pass->static_pass_number, &dump_flags);
761       if (dump_file && current_function_decl)
762         {
763           const char *dname, *aname;
764           dname = lang_hooks.decl_printable_name (current_function_decl, 2);
765           aname = (IDENTIFIER_POINTER
766                    (DECL_ASSEMBLER_NAME (current_function_decl)));
767           fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
768              cfun->function_frequency == FUNCTION_FREQUENCY_HOT
769              ? " (hot)"
770              : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
771              ? " (unlikely executed)"
772              : "");
773         }
774
775       if (initializing_dump
776           && graph_dump_format != no_graph
777           && (pass->properties_provided & (PROP_cfg | PROP_rtl))
778               == (PROP_cfg | PROP_rtl))
779         clean_graph_dump_file (dump_file_name);
780     }
781
782   /* If a timevar is present, start it.  */
783   if (pass->tv_id)
784     timevar_push (pass->tv_id);
785
786   /* Do it!  */
787   if (pass->execute)
788     pass->execute ();
789
790   /* Stop timevar.  */
791   if (pass->tv_id)
792     timevar_pop (pass->tv_id);
793
794   /* Run post-pass cleanup and verification.  */
795   todo = pass->todo_flags_finish;
796   last_verified = todo & TODO_verify_all;
797   if (todo)
798     execute_todo (pass, todo, false);
799
800   /* Flush and close dump file.  */
801   if (dump_file_name)
802     {
803       free ((char *) dump_file_name);
804       dump_file_name = NULL;
805     }
806   if (dump_file)
807     {
808       dump_end (pass->static_pass_number, dump_file);
809       dump_file = NULL;
810     }
811
812   return true;
813 }
814
815 void
816 execute_pass_list (struct tree_opt_pass *pass)
817 {
818   do
819     {
820       if (execute_one_pass (pass) && pass->sub)
821         execute_pass_list (pass->sub);
822       pass = pass->next;
823     }
824   while (pass);
825 }
826
827 /* Same as execute_pass_list but assume that subpasses of IPA passes
828    are local passes.  */
829 void
830 execute_ipa_pass_list (struct tree_opt_pass *pass)
831 {
832   do
833     {
834       if (execute_one_pass (pass) && pass->sub)
835         {
836           struct cgraph_node *node;
837           for (node = cgraph_nodes; node; node = node->next)
838             if (node->analyzed)
839               {
840                 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
841                 current_function_decl = node->decl;
842                 execute_pass_list (pass->sub);
843                 free_dominance_info (CDI_DOMINATORS);
844                 free_dominance_info (CDI_POST_DOMINATORS);
845                 current_function_decl = NULL;
846                 pop_cfun ();
847                 ggc_collect ();
848               }
849         }
850       pass = pass->next;
851     }
852   while (pass);
853 }