OSDN Git Service

* passes.c (init_optimization_passes): Tidy comment.
[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, 2006, 2007
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.  */
22
23 /* This is the top level of cc1/c++.
24    It parses command args, opens files, invokes the various passes
25    in the proper order, and counts the time used by each.
26    Error messages and low-level interface to malloc also handled here.  */
27
28 #include "config.h"
29 #undef FLOAT /* This is for hpux. They should change hpux.  */
30 #undef FFS  /* Some systems define this in param.h.  */
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include <signal.h>
35
36 #ifdef HAVE_SYS_RESOURCE_H
37 # include <sys/resource.h>
38 #endif
39
40 #ifdef HAVE_SYS_TIMES_H
41 # include <sys/times.h>
42 #endif
43
44 #include "line-map.h"
45 #include "input.h"
46 #include "tree.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "regs.h"
65 #include "timevar.h"
66 #include "diagnostic.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
81 #include "value-prof.h"
82 #include "tree-inline.h"
83 #include "tree-flow.h"
84 #include "tree-pass.h"
85 #include "tree-dump.h"
86
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
89 #endif
90
91 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
92 #include "dbxout.h"
93 #endif
94
95 #ifdef SDB_DEBUGGING_INFO
96 #include "sdbout.h"
97 #endif
98
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h"           /* Needed for external data
101                                    declarations for e.g. AIX 4.x.  */
102 #endif
103
104 /* Global variables used to communicate with passes.  */
105 int dump_flags;
106 bool in_gimple_form;
107
108
109 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
110    and TYPE_DECL nodes.
111
112    This does nothing for local (non-static) variables, unless the
113    variable is a register variable with DECL_ASSEMBLER_NAME set.  In
114    that case, or if the variable is not an automatic, it sets up the
115    RTL and outputs any assembler code (label definition, storage
116    allocation and initialization).
117
118    DECL is the declaration.  TOP_LEVEL is nonzero
119    if this declaration is not within a function.  */
120
121 void
122 rest_of_decl_compilation (tree decl,
123                           int top_level,
124                           int at_end)
125 {
126   /* We deferred calling assemble_alias so that we could collect
127      other attributes such as visibility.  Emit the alias now.  */
128   {
129     tree alias;
130     alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
131     if (alias)
132       {
133         alias = TREE_VALUE (TREE_VALUE (alias));
134         alias = get_identifier (TREE_STRING_POINTER (alias));
135         assemble_alias (decl, alias);
136       }
137   }
138
139   /* Can't defer this, because it needs to happen before any
140      later function definitions are processed.  */
141   if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
142     make_decl_rtl (decl);
143
144   /* Forward declarations for nested functions are not "external",
145      but we need to treat them as if they were.  */
146   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
147       || TREE_CODE (decl) == FUNCTION_DECL)
148     {
149       timevar_push (TV_VARCONST);
150
151       /* Don't output anything when a tentative file-scope definition
152          is seen.  But at end of compilation, do output code for them.
153
154          We do output all variables when unit-at-a-time is active and rely on
155          callgraph code to defer them except for forward declarations
156          (see gcc.c-torture/compile/920624-1.c) */
157       if ((at_end
158            || !DECL_DEFER_OUTPUT (decl)
159            || DECL_INITIAL (decl))
160           && !DECL_EXTERNAL (decl))
161         {
162           if (TREE_CODE (decl) != FUNCTION_DECL)
163             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     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_profile.static_pass_number, NULL);
221       end_branch_prob ();
222       if (dump_file)
223         dump_end (pass_profile.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_GRAPH) != 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 properties)
309 {
310   char *dot_name, *flag_name, *glob_name;
311   const char *prefix;
312   char num[10];
313   int flags;
314
315   /* See below in next_pass_1.  */
316   num[0] = '\0';
317   if (pass->static_pass_number != -1)
318     sprintf (num, "%d", ((int) pass->static_pass_number < 0
319                          ? 1 : pass->static_pass_number));
320
321   dot_name = concat (".", pass->name, num, NULL);
322   if (ipa)
323     prefix = "ipa-", flags = TDF_IPA;
324   else if (properties & PROP_trees)
325     prefix = "tree-", flags = TDF_TREE;
326   else
327     prefix = "rtl-", flags = TDF_RTL;
328
329   flag_name = concat (prefix, pass->name, num, NULL);
330   glob_name = concat (prefix, pass->name, NULL);
331   pass->static_pass_number = dump_register (dot_name, flag_name, glob_name,
332                                             flags, pass->letter);
333 }
334
335 /* Recursive worker function for register_dump_files.  */
336
337 static int 
338 register_dump_files_1 (struct tree_opt_pass *pass, bool ipa, int properties)
339 {
340   do
341     {
342       int new_properties = (properties | pass->properties_provided)
343                            & ~pass->properties_destroyed;
344
345       if (pass->name)
346         register_one_dump_file (pass, ipa, new_properties);
347
348       if (pass->sub)
349         new_properties = register_dump_files_1 (pass->sub, false,
350                                                 new_properties);
351
352       /* If we have a gate, combine the properties that we could have with
353          and without the pass being examined.  */
354       if (pass->gate)
355         properties &= new_properties;
356       else
357         properties = new_properties;
358
359       pass = pass->next;
360     }
361   while (pass);
362
363   return properties;
364 }
365
366 /* Register the dump files for the pipeline starting at PASS.  IPA is
367    true if the pass is inter-procedural, and PROPERTIES reflects the
368    properties that are guaranteed to be available at the beginning of
369    the pipeline.  */
370
371 static void 
372 register_dump_files (struct tree_opt_pass *pass, bool ipa, int properties)
373 {
374   pass->properties_required |= properties;
375   register_dump_files_1 (pass, ipa, properties);
376 }
377
378 /* Add a pass to the pass list. Duplicate the pass if it's already
379    in the list.  */
380
381 static struct tree_opt_pass **
382 next_pass_1 (struct tree_opt_pass **list, struct tree_opt_pass *pass)
383 {
384   /* A nonzero static_pass_number indicates that the
385      pass is already in the list.  */
386   if (pass->static_pass_number)
387     {
388       struct tree_opt_pass *new;
389
390       new = xmalloc (sizeof (*new));
391       memcpy (new, pass, sizeof (*new));
392
393       /* Indicate to register_dump_files that this pass has duplicates,
394          and so it should rename the dump file.  The first instance will
395          be -1, and be number of duplicates = -static_pass_number - 1.
396          Subsequent instances will be > 0 and just the duplicate number.  */
397       if (pass->name)
398         {
399           pass->static_pass_number -= 1;
400           new->static_pass_number = -pass->static_pass_number;
401         }
402       
403       *list = new;
404     }
405   else
406     {
407       pass->static_pass_number = -1;
408       *list = pass;
409     }  
410   
411   return &(*list)->next;
412           
413 }
414
415 /* Construct the pass tree.  The sequencing of passes is driven by
416    the cgraph routines:
417
418    cgraph_finalize_compilation_unit ()
419        for each node N in the cgraph
420            cgraph_analyze_function (N)
421                cgraph_lower_function (N) -> all_lowering_passes
422
423    If we are optimizing, cgraph_optimize is then invoked:
424
425    cgraph_optimize ()
426        ipa_passes ()                    -> all_ipa_passes
427        cgraph_expand_all_functions ()
428            for each node N in the cgraph
429                cgraph_expand_function (N)
430                    lang_hooks.callgraph.expand_function (DECL (N))
431                         tree_rest_of_compilation (DECL (N))  -> all_passes
432 */
433
434 void
435 init_optimization_passes (void)
436 {
437   struct tree_opt_pass **p;
438
439 #define NEXT_PASS(PASS)  (p = next_pass_1 (p, &PASS))
440
441  /* All passes needed to lower the function into shape optimizers can
442     operate on.  These passes are always run first on the function, but
443     backend might produce already lowered functions that are not processed
444     by these passes.  */
445   p = &all_lowering_passes;
446   NEXT_PASS (pass_remove_useless_stmts);
447   NEXT_PASS (pass_mudflap_1);
448   NEXT_PASS (pass_lower_omp);
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_build_cgraph_edges);
456   NEXT_PASS (pass_inline_parameters);
457   *p = NULL;
458
459   /* Interprocedural optimization passes. 
460      All these passes are ignored in -fno-unit-at-a-time
461      except for subpases of early_local_pases.  */
462   p = &all_ipa_passes;
463   NEXT_PASS (pass_ipa_function_and_variable_visibility);
464   NEXT_PASS (pass_ipa_early_inline);
465     {
466       struct tree_opt_pass **p = &pass_ipa_early_inline.sub;
467       NEXT_PASS (pass_early_inline);
468       NEXT_PASS (pass_inline_parameters);
469       NEXT_PASS (pass_rebuild_cgraph_edges);
470     }
471   NEXT_PASS (pass_early_local_passes);
472     {
473       struct tree_opt_pass **p = &pass_early_local_passes.sub;
474       NEXT_PASS (pass_tree_profile);
475       NEXT_PASS (pass_cleanup_cfg);
476       NEXT_PASS (pass_init_datastructures);
477       NEXT_PASS (pass_expand_omp);
478       NEXT_PASS (pass_all_early_optimizations);
479         {
480           struct tree_opt_pass **p = &pass_all_early_optimizations.sub;
481           NEXT_PASS (pass_referenced_vars);
482           NEXT_PASS (pass_reset_cc_flags);
483           NEXT_PASS (pass_build_ssa);
484           NEXT_PASS (pass_early_warn_uninitialized);
485           NEXT_PASS (pass_rebuild_cgraph_edges);
486           NEXT_PASS (pass_early_inline);
487           NEXT_PASS (pass_cleanup_cfg);
488           NEXT_PASS (pass_rename_ssa_copies);
489           NEXT_PASS (pass_ccp);
490           NEXT_PASS (pass_forwprop);
491           NEXT_PASS (pass_sra);
492           NEXT_PASS (pass_copy_prop);
493           NEXT_PASS (pass_merge_phi);
494           NEXT_PASS (pass_dce);
495           NEXT_PASS (pass_tail_recursion);
496           NEXT_PASS (pass_release_ssa_names);
497         }
498       NEXT_PASS (pass_rebuild_cgraph_edges);
499       NEXT_PASS (pass_inline_parameters);
500     }
501   NEXT_PASS (pass_ipa_increase_alignment);
502   NEXT_PASS (pass_ipa_cp);
503   NEXT_PASS (pass_ipa_inline);
504   NEXT_PASS (pass_ipa_reference);
505   NEXT_PASS (pass_ipa_pure_const); 
506   NEXT_PASS (pass_ipa_type_escape);
507   NEXT_PASS (pass_ipa_pta);
508   *p = NULL;
509
510   /* These passes are run after IPA passes on every function that is being
511      output to the assembler file.  */
512   p = &all_passes;
513   NEXT_PASS (pass_apply_inline);
514   NEXT_PASS (pass_all_optimizations);
515     {
516       struct tree_opt_pass **p = &pass_all_optimizations.sub;
517       NEXT_PASS (pass_create_structure_vars);
518       NEXT_PASS (pass_may_alias);
519       NEXT_PASS (pass_return_slot);
520       NEXT_PASS (pass_rename_ssa_copies);
521
522       /* Initial scalar cleanups.  */
523       NEXT_PASS (pass_ccp);
524       NEXT_PASS (pass_fre);
525       NEXT_PASS (pass_dce);
526       NEXT_PASS (pass_forwprop);
527       NEXT_PASS (pass_copy_prop);
528       NEXT_PASS (pass_merge_phi);
529       NEXT_PASS (pass_vrp);
530       NEXT_PASS (pass_dce);
531       NEXT_PASS (pass_dominator);
532
533       /* The only const/copy propagation opportunities left after
534          DOM should be due to degenerate PHI nodes.  So rather than
535          run the full propagators, run a specialized pass which
536          only examines PHIs to discover const/copy propagation
537          opportunities.  */
538       NEXT_PASS (pass_phi_only_cprop);
539
540       NEXT_PASS (pass_phiopt);
541       NEXT_PASS (pass_may_alias);
542       NEXT_PASS (pass_tail_recursion);
543       NEXT_PASS (pass_profile);
544       NEXT_PASS (pass_ch);
545       NEXT_PASS (pass_stdarg);
546       NEXT_PASS (pass_lower_complex);
547       NEXT_PASS (pass_sra);
548       /* FIXME: SRA may generate arbitrary gimple code, exposing new
549          aliased and call-clobbered variables.  As mentioned below,
550          pass_may_alias should be a TODO item.  */
551       NEXT_PASS (pass_may_alias);
552       NEXT_PASS (pass_rename_ssa_copies);
553       NEXT_PASS (pass_dominator);
554
555       /* The only const/copy propagation opportunities left after
556          DOM should be due to degenerate PHI nodes.  So rather than
557          run the full propagators, run a specialized pass which
558          only examines PHIs to discover const/copy propagation
559          opportunities.  */
560       NEXT_PASS (pass_phi_only_cprop);
561
562       NEXT_PASS (pass_reassoc);
563       NEXT_PASS (pass_dce);
564       NEXT_PASS (pass_dse);
565       NEXT_PASS (pass_may_alias);
566       NEXT_PASS (pass_forwprop);
567       NEXT_PASS (pass_phiopt);
568       NEXT_PASS (pass_object_sizes);
569       NEXT_PASS (pass_store_ccp);
570       NEXT_PASS (pass_store_copy_prop);
571       NEXT_PASS (pass_fold_builtins);
572       NEXT_PASS (pass_cse_sincos);
573       /* FIXME: May alias should a TODO but for 4.0.0,
574          we add may_alias right after fold builtins
575          which can create arbitrary GIMPLE.  */
576       NEXT_PASS (pass_may_alias);
577       NEXT_PASS (pass_split_crit_edges);
578       NEXT_PASS (pass_pre);
579       NEXT_PASS (pass_may_alias);
580       NEXT_PASS (pass_sink_code);
581       NEXT_PASS (pass_tree_loop);
582         {
583           struct tree_opt_pass **p = &pass_tree_loop.sub;
584           NEXT_PASS (pass_tree_loop_init);
585           NEXT_PASS (pass_copy_prop);
586           NEXT_PASS (pass_lim);
587           NEXT_PASS (pass_tree_unswitch);
588           NEXT_PASS (pass_scev_cprop);
589           NEXT_PASS (pass_empty_loop);
590           NEXT_PASS (pass_record_bounds);
591           NEXT_PASS (pass_linear_transform);
592           NEXT_PASS (pass_iv_canon);
593           NEXT_PASS (pass_if_conversion);
594           NEXT_PASS (pass_vectorize);
595             {
596               struct tree_opt_pass **p = &pass_vectorize.sub;
597               NEXT_PASS (pass_lower_vector_ssa);
598               NEXT_PASS (pass_dce_loop);
599             }
600           /* NEXT_PASS (pass_may_alias) cannot be done again because the
601              vectorizer creates alias relations that are not supported by
602              pass_may_alias.  */
603           NEXT_PASS (pass_complete_unroll);
604           NEXT_PASS (pass_loop_prefetch);
605           NEXT_PASS (pass_iv_optimize);
606           NEXT_PASS (pass_tree_loop_done);
607         }
608       NEXT_PASS (pass_cse_reciprocals);
609       NEXT_PASS (pass_reassoc);
610       NEXT_PASS (pass_vrp);
611       NEXT_PASS (pass_dominator);
612
613       /* The only const/copy propagation opportunities left after
614          DOM should be due to degenerate PHI nodes.  So rather than
615          run the full propagators, run a specialized pass which
616          only examines PHIs to discover const/copy propagation
617          opportunities.  */
618       NEXT_PASS (pass_phi_only_cprop);
619
620       NEXT_PASS (pass_cd_dce);
621
622       /* FIXME: If DCE is not run before checking for uninitialized uses,
623          we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
624          However, this also causes us to misdiagnose cases that should be
625          real warnings (e.g., testsuite/gcc.dg/pr18501.c).
626          
627          To fix the false positives in uninit-5.c, we would have to
628          account for the predicates protecting the set and the use of each
629          variable.  Using a representation like Gated Single Assignment
630          may help.  */
631       NEXT_PASS (pass_late_warn_uninitialized);
632       NEXT_PASS (pass_dse);
633       NEXT_PASS (pass_forwprop);
634       NEXT_PASS (pass_phiopt);
635       NEXT_PASS (pass_tail_calls);
636       NEXT_PASS (pass_rename_ssa_copies);
637       NEXT_PASS (pass_uncprop);
638       NEXT_PASS (pass_del_ssa);
639       NEXT_PASS (pass_nrv);
640       NEXT_PASS (pass_mark_used_blocks);
641       NEXT_PASS (pass_cleanup_cfg_post_optimizing);
642     }
643   NEXT_PASS (pass_warn_function_noreturn);
644   NEXT_PASS (pass_free_datastructures);
645   NEXT_PASS (pass_mudflap_2);
646   NEXT_PASS (pass_free_cfg_annotations);
647   NEXT_PASS (pass_expand);
648   NEXT_PASS (pass_rest_of_compilation);
649     {
650       struct tree_opt_pass **p = &pass_rest_of_compilation.sub;
651       NEXT_PASS (pass_init_function);
652       NEXT_PASS (pass_jump);
653       NEXT_PASS (pass_insn_locators_initialize);
654       NEXT_PASS (pass_rtl_eh);
655       NEXT_PASS (pass_initial_value_sets);
656       NEXT_PASS (pass_unshare_all_rtl);
657       NEXT_PASS (pass_instantiate_virtual_regs);
658       NEXT_PASS (pass_jump2);
659       NEXT_PASS (pass_lower_subreg);
660       NEXT_PASS (pass_cse);
661       NEXT_PASS (pass_rtl_fwprop);
662       NEXT_PASS (pass_gcse);
663       NEXT_PASS (pass_jump_bypass);
664       NEXT_PASS (pass_rtl_ifcvt);
665       NEXT_PASS (pass_tracer);
666       /* Perform loop optimizations.  It might be better to do them a bit
667          sooner, but we want the profile feedback to work more
668          efficiently.  */
669       NEXT_PASS (pass_loop2);
670         {
671           struct tree_opt_pass **p = &pass_loop2.sub;
672           NEXT_PASS (pass_rtl_loop_init);
673           NEXT_PASS (pass_rtl_move_loop_invariants);
674           NEXT_PASS (pass_rtl_unswitch);
675           NEXT_PASS (pass_rtl_unroll_and_peel_loops);
676           NEXT_PASS (pass_rtl_doloop);
677           NEXT_PASS (pass_rtl_loop_done);
678           *p = NULL;
679         }
680       NEXT_PASS (pass_web);
681       NEXT_PASS (pass_cse2);
682       NEXT_PASS (pass_rtl_fwprop_addr);
683       NEXT_PASS (pass_life);
684       NEXT_PASS (pass_combine);
685       NEXT_PASS (pass_if_after_combine);
686       NEXT_PASS (pass_partition_blocks);
687       NEXT_PASS (pass_regmove);
688       NEXT_PASS (pass_split_all_insns);
689       NEXT_PASS (pass_lower_subreg2);
690       NEXT_PASS (pass_mode_switching);
691       NEXT_PASS (pass_see);
692       NEXT_PASS (pass_recompute_reg_usage);
693       NEXT_PASS (pass_sms);
694       NEXT_PASS (pass_sched);
695       NEXT_PASS (pass_local_alloc);
696       NEXT_PASS (pass_global_alloc);
697       NEXT_PASS (pass_postreload);
698         {
699           struct tree_opt_pass **p = &pass_postreload.sub;
700           NEXT_PASS (pass_postreload_cse);
701           NEXT_PASS (pass_gcse2);
702           NEXT_PASS (pass_flow2);
703           NEXT_PASS (pass_rtl_seqabstr);
704           NEXT_PASS (pass_stack_adjustments);
705           NEXT_PASS (pass_peephole2);
706           NEXT_PASS (pass_if_after_reload);
707           NEXT_PASS (pass_regrename);
708           NEXT_PASS (pass_reorder_blocks);
709           NEXT_PASS (pass_branch_target_load_optimize);
710           NEXT_PASS (pass_leaf_regs);
711           NEXT_PASS (pass_sched2);
712           NEXT_PASS (pass_split_before_regstack);
713           NEXT_PASS (pass_stack_regs);
714           NEXT_PASS (pass_compute_alignments);
715           NEXT_PASS (pass_duplicate_computed_gotos);
716           NEXT_PASS (pass_variable_tracking);
717           NEXT_PASS (pass_free_cfg);
718           NEXT_PASS (pass_machine_reorg);
719           NEXT_PASS (pass_cleanup_barriers);
720           NEXT_PASS (pass_delay_slots);
721           NEXT_PASS (pass_split_for_shorten_branches);
722           NEXT_PASS (pass_convert_to_eh_region_ranges);
723           NEXT_PASS (pass_shorten_branches);
724           NEXT_PASS (pass_set_nothrow_function_flags);
725           NEXT_PASS (pass_final);
726         }
727     }
728   NEXT_PASS (pass_clean_state);
729   *p = NULL;
730
731 #undef NEXT_PASS
732
733   /* Register the passes with the tree dump code.  */
734   register_dump_files (all_lowering_passes, false, PROP_gimple_any);
735   all_lowering_passes->todo_flags_start |= TODO_set_props;
736   register_dump_files (all_ipa_passes, true,
737                        PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
738                        | PROP_cfg);
739   register_dump_files (all_passes, false,
740                        PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
741                        | PROP_cfg);
742 }
743
744 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
745    function CALLBACK for every function in the call graph.  Otherwise,
746    call CALLBACK on the current function.  */ 
747
748 static void
749 do_per_function (void (*callback) (void *data), void *data)
750 {
751   if (current_function_decl)
752     callback (data);
753   else
754     {
755       struct cgraph_node *node;
756       for (node = cgraph_nodes; node; node = node->next)
757         if (node->analyzed)
758           {
759             push_cfun (DECL_STRUCT_FUNCTION (node->decl));
760             current_function_decl = node->decl;
761             callback (data);
762             free_dominance_info (CDI_DOMINATORS);
763             free_dominance_info (CDI_POST_DOMINATORS);
764             current_function_decl = NULL;
765             pop_cfun ();
766             ggc_collect ();
767           }
768     }
769 }
770
771 /* Because inlining might remove no-longer reachable nodes, we need to
772    keep the array visible to garbage collector to avoid reading collected
773    out nodes.  */
774 static int nnodes;
775 static GTY ((length ("nnodes"))) struct cgraph_node **order;
776
777 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
778    function CALLBACK for every function in the call graph.  Otherwise,
779    call CALLBACK on the current function.  */ 
780
781 static void
782 do_per_function_toporder (void (*callback) (void *data), void *data)
783 {
784   int i;
785
786   if (current_function_decl)
787     callback (data);
788   else
789     {
790       gcc_assert (!order);
791       order = ggc_alloc (sizeof (*order) * cgraph_n_nodes);
792       nnodes = cgraph_postorder (order);
793       for (i = nnodes - 1; i >= 0; i--)
794         {
795           struct cgraph_node *node = order[i];
796
797           /* Allow possibly removed nodes to be garbage collected.  */
798           order[i] = NULL;
799           if (node->analyzed && (node->needed || node->reachable))
800             {
801               push_cfun (DECL_STRUCT_FUNCTION (node->decl));
802               current_function_decl = node->decl;
803               callback (data);
804               free_dominance_info (CDI_DOMINATORS);
805               free_dominance_info (CDI_POST_DOMINATORS);
806               current_function_decl = NULL;
807               pop_cfun ();
808               ggc_collect ();
809             }
810         }
811     }
812   ggc_free (order);
813   order = NULL;
814   nnodes = 0;
815 }
816
817 /* Perform all TODO actions that ought to be done on each function.  */
818
819 static void
820 execute_function_todo (void *data)
821 {
822   unsigned int flags = (size_t)data;
823   if (cfun->curr_properties & PROP_ssa)
824     flags |= TODO_verify_ssa;
825   flags &= ~cfun->last_verified;
826   if (!flags)
827     return;
828   
829   /* Always cleanup the CFG before trying to update SSA.  */
830   if (flags & TODO_cleanup_cfg)
831     {
832       bool cleanup;
833
834       if (current_loops)
835         cleanup = cleanup_tree_cfg_loop ();
836       else
837         cleanup = cleanup_tree_cfg ();
838
839       if (cleanup && (cfun->curr_properties & PROP_ssa))
840         flags |= TODO_remove_unused_locals;
841         
842       /* When cleanup_tree_cfg merges consecutive blocks, it may
843          perform some simplistic propagation when removing single
844          valued PHI nodes.  This propagation may, in turn, cause the
845          SSA form to become out-of-date (see PR 22037).  So, even
846          if the parent pass had not scheduled an SSA update, we may
847          still need to do one.  */
848       if (!(flags & TODO_update_ssa_any) && need_ssa_update_p ())
849         flags |= TODO_update_ssa;
850     }
851
852   if (flags & TODO_update_ssa_any)
853     {
854       unsigned update_flags = flags & TODO_update_ssa_any;
855       update_ssa (update_flags);
856       cfun->last_verified &= ~TODO_verify_ssa;
857     }
858
859   if (flags & TODO_remove_unused_locals)
860     remove_unused_locals ();
861
862   if ((flags & TODO_dump_func)
863       && dump_file && current_function_decl)
864     {
865       if (cfun->curr_properties & PROP_trees)
866         dump_function_to_file (current_function_decl,
867                                dump_file, dump_flags);
868       else
869         {
870           if (dump_flags & TDF_SLIM)
871             print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
872           else if ((cfun->curr_properties & PROP_cfg)
873                    && (dump_flags & TDF_BLOCKS))
874             print_rtl_with_bb (dump_file, get_insns ());
875           else
876             print_rtl (dump_file, get_insns ());
877
878           if (cfun->curr_properties & PROP_cfg
879               && graph_dump_format != no_graph
880               && (dump_flags & TDF_GRAPH))
881             print_rtl_graph_with_bb (dump_file_name, get_insns ());
882         }
883
884       /* Flush the file.  If verification fails, we won't be able to
885          close the file before aborting.  */
886       fflush (dump_file);
887     }
888
889 #if defined ENABLE_CHECKING
890   if (flags & TODO_verify_ssa)
891     verify_ssa (true);
892   if (flags & TODO_verify_flow)
893     verify_flow_info ();
894   if (flags & TODO_verify_stmts)
895     verify_stmts ();
896   if (flags & TODO_verify_loops)
897     verify_loop_closed_ssa ();
898 #endif
899
900   cfun->last_verified = flags & TODO_verify_all;
901 }
902
903 /* Perform all TODO actions.  */
904 static void
905 execute_todo (unsigned int flags)
906 {
907 #if defined ENABLE_CHECKING
908   if (need_ssa_update_p ())
909     gcc_assert (flags & TODO_update_ssa_any);
910 #endif
911
912   do_per_function (execute_function_todo, (void *)(size_t) flags);
913
914   /* Always remove functions just as before inlining: IPA passes might be
915      interested to see bodies of extern inline functions that are not inlined
916      to analyze side effects.  The full removal is done just at the end
917      of IPA pass queue.  */
918   if (flags & TODO_remove_functions)
919     cgraph_remove_unreachable_nodes (true, dump_file);
920
921   if ((flags & TODO_dump_cgraph)
922       && dump_file && !current_function_decl)
923     {
924       dump_cgraph (dump_file);
925       /* Flush the file.  If verification fails, we won't be able to
926          close the file before aborting.  */
927       fflush (dump_file);
928     }
929
930   if (flags & TODO_ggc_collect)
931     {
932       ggc_collect ();
933     }
934 }
935
936 /* Clear the last verified flag.  */
937
938 static void
939 clear_last_verified (void *data ATTRIBUTE_UNUSED)
940 {
941   cfun->last_verified = 0;
942 }
943
944 /* Helper function. Verify that the properties has been turn into the
945    properties expected by the pass.  */
946
947 #ifdef ENABLE_CHECKING
948 static void
949 verify_curr_properties (void *data)
950 {
951   unsigned int props = (size_t)data;
952   gcc_assert ((cfun->curr_properties & props) == props);
953 }
954 #endif
955
956 /* After executing the pass, apply expected changes to the function
957    properties. */
958 static void
959 update_properties_after_pass (void *data)
960 {
961   struct tree_opt_pass *pass = data;
962   cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
963                            & ~pass->properties_destroyed;
964 }
965
966 static bool
967 execute_one_pass (struct tree_opt_pass *pass)
968 {
969   bool initializing_dump;
970   unsigned int todo_after = 0;
971
972   /* See if we're supposed to run this pass.  */
973   if (pass->gate && !pass->gate ())
974     return false;
975
976   if (!quiet_flag && !cfun)
977     fprintf (stderr, " <%s>", pass->name ? pass->name : "");
978
979   if (pass->todo_flags_start & TODO_set_props)
980     cfun->curr_properties = pass->properties_required;
981
982   /* Note that the folders should only create gimple expressions.
983      This is a hack until the new folder is ready.  */
984   in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
985
986   /* Run pre-pass verification.  */
987   execute_todo (pass->todo_flags_start);
988
989 #ifdef ENABLE_CHECKING
990   do_per_function (verify_curr_properties,
991                    (void *)(size_t)pass->properties_required);
992 #endif
993
994   /* If a dump file name is present, open it if enabled.  */
995   if (pass->static_pass_number != -1)
996     {
997       initializing_dump = !dump_initialized_p (pass->static_pass_number);
998       dump_file_name = get_dump_file_name (pass->static_pass_number);
999       dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1000       if (dump_file && current_function_decl)
1001         {
1002           const char *dname, *aname;
1003           dname = lang_hooks.decl_printable_name (current_function_decl, 2);
1004           aname = (IDENTIFIER_POINTER
1005                    (DECL_ASSEMBLER_NAME (current_function_decl)));
1006           fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
1007              cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1008              ? " (hot)"
1009              : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1010              ? " (unlikely executed)"
1011              : "");
1012         }
1013     }
1014   else
1015     initializing_dump = false;
1016
1017   /* If a timevar is present, start it.  */
1018   if (pass->tv_id)
1019     timevar_push (pass->tv_id);
1020
1021   /* Do it!  */
1022   if (pass->execute)
1023     {
1024       todo_after = pass->execute ();
1025       do_per_function (clear_last_verified, NULL);
1026     }
1027
1028   /* Stop timevar.  */
1029   if (pass->tv_id)
1030     timevar_pop (pass->tv_id);
1031
1032   do_per_function (update_properties_after_pass, pass);
1033
1034   if (initializing_dump
1035       && dump_file
1036       && graph_dump_format != no_graph
1037       && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
1038           == (PROP_cfg | PROP_rtl))
1039     {
1040       get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
1041       dump_flags |= TDF_GRAPH;
1042       clean_graph_dump_file (dump_file_name);
1043     }
1044
1045   /* Run post-pass cleanup and verification.  */
1046   execute_todo (todo_after | pass->todo_flags_finish);
1047
1048   if (!current_function_decl)
1049     cgraph_process_new_functions ();
1050
1051   /* Flush and close dump file.  */
1052   if (dump_file_name)
1053     {
1054       free ((char *) dump_file_name);
1055       dump_file_name = NULL;
1056     }
1057
1058   if (dump_file)
1059     {
1060       dump_end (pass->static_pass_number, dump_file);
1061       dump_file = NULL;
1062     }
1063
1064   /* Reset in_gimple_form to not break non-unit-at-a-time mode.  */
1065   in_gimple_form = false;
1066
1067   return true;
1068 }
1069
1070 void
1071 execute_pass_list (struct tree_opt_pass *pass)
1072 {
1073   do
1074     {
1075       if (execute_one_pass (pass) && pass->sub)
1076         execute_pass_list (pass->sub);
1077       pass = pass->next;
1078     }
1079   while (pass);
1080 }
1081
1082 /* Same as execute_pass_list but assume that subpasses of IPA passes
1083    are local passes.  */
1084 void
1085 execute_ipa_pass_list (struct tree_opt_pass *pass)
1086 {
1087   do
1088     {
1089       gcc_assert (!current_function_decl);
1090       gcc_assert (!cfun);
1091       if (execute_one_pass (pass) && pass->sub)
1092         do_per_function_toporder ((void (*)(void *))execute_pass_list,
1093                                   pass->sub);
1094       if (!current_function_decl)
1095         cgraph_process_new_functions ();
1096       pass = pass->next;
1097     }
1098   while (pass);
1099 }
1100 #include "gt-passes.h"