1/* Description of pass structure
2   Copyright (C) 1987-2014 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3.  If not see
18<http://www.gnu.org/licenses/>.  */
19
20/*
21 Macros that should be defined when using this file:
22   INSERT_PASSES_AFTER (PASS)
23   PUSH_INSERT_PASSES_WITHIN (PASS)
24   POP_INSERT_PASSES ()
25   NEXT_PASS (PASS)
26   TERMINATE_PASS_LIST ()
27 */
28
29 /* All passes needed to lower the function into shape optimizers can
30    operate on.  These passes are always run first on the function, but
31    backend might produce already lowered functions that are not processed
32    by these passes.  */
33  INSERT_PASSES_AFTER (all_lowering_passes)
34  NEXT_PASS (pass_warn_unused_result);
35  NEXT_PASS (pass_diagnose_omp_blocks);
36  NEXT_PASS (pass_diagnose_tm_blocks);
37  NEXT_PASS (pass_lower_omp);
38  NEXT_PASS (pass_lower_cf);
39  NEXT_PASS (pass_lower_tm);
40  NEXT_PASS (pass_refactor_eh);
41  NEXT_PASS (pass_lower_eh);
42  NEXT_PASS (pass_build_cfg);
43  NEXT_PASS (pass_warn_function_return);
44  NEXT_PASS (pass_expand_omp);
45  NEXT_PASS (pass_build_cgraph_edges);
46  TERMINATE_PASS_LIST ()
47
48  /* Interprocedural optimization passes.  */
49  INSERT_PASSES_AFTER (all_small_ipa_passes)
50  NEXT_PASS (pass_ipa_free_lang_data);
51  NEXT_PASS (pass_ipa_function_and_variable_visibility);
52  NEXT_PASS (pass_early_local_passes);
53  PUSH_INSERT_PASSES_WITHIN (pass_early_local_passes)
54      NEXT_PASS (pass_fixup_cfg);
55      NEXT_PASS (pass_init_datastructures);
56
57      NEXT_PASS (pass_build_ssa);
58      NEXT_PASS (pass_ubsan);
59      NEXT_PASS (pass_early_warn_uninitialized);
60      NEXT_PASS (pass_rebuild_cgraph_edges);
61      NEXT_PASS (pass_inline_parameters);
62      NEXT_PASS (pass_early_inline);
63      NEXT_PASS (pass_all_early_optimizations);
64      PUSH_INSERT_PASSES_WITHIN (pass_all_early_optimizations)
65	  NEXT_PASS (pass_remove_cgraph_callee_edges);
66	  NEXT_PASS (pass_rename_ssa_copies);
67	  NEXT_PASS (pass_ccp);
68	  /* After CCP we rewrite no longer addressed locals into SSA
69	     form if possible.  */
70	  NEXT_PASS (pass_forwprop);
71	  /* pass_build_ealias is a dummy pass that ensures that we
72	     execute TODO_rebuild_alias at this point.  */
73	  NEXT_PASS (pass_build_ealias);
74	  NEXT_PASS (pass_sra_early);
75	  NEXT_PASS (pass_fre);
76	  NEXT_PASS (pass_copy_prop);
77	  NEXT_PASS (pass_merge_phi);
78	  NEXT_PASS (pass_cd_dce);
79	  NEXT_PASS (pass_early_ipa_sra);
80	  NEXT_PASS (pass_tail_recursion);
81	  NEXT_PASS (pass_convert_switch);
82          NEXT_PASS (pass_cleanup_eh);
83          NEXT_PASS (pass_profile);
84          NEXT_PASS (pass_local_pure_const);
85	  /* Split functions creates parts that are not run through
86	     early optimizations again.  It is thus good idea to do this
87	     late.  */
88          NEXT_PASS (pass_split_functions);
89      POP_INSERT_PASSES ()
90      NEXT_PASS (pass_release_ssa_names);
91      NEXT_PASS (pass_rebuild_cgraph_edges);
92      NEXT_PASS (pass_inline_parameters);
93  POP_INSERT_PASSES ()
94  NEXT_PASS (pass_ipa_free_inline_summary);
95  NEXT_PASS (pass_ipa_tree_profile);
96  PUSH_INSERT_PASSES_WITHIN (pass_ipa_tree_profile)
97      NEXT_PASS (pass_feedback_split_functions);
98  POP_INSERT_PASSES ()
99  NEXT_PASS (pass_ipa_increase_alignment);
100  NEXT_PASS (pass_ipa_tm);
101  NEXT_PASS (pass_ipa_lower_emutls);
102  TERMINATE_PASS_LIST ()
103
104  INSERT_PASSES_AFTER (all_regular_ipa_passes)
105  NEXT_PASS (pass_ipa_whole_program_visibility);
106  NEXT_PASS (pass_ipa_profile);
107  NEXT_PASS (pass_ipa_devirt);
108  NEXT_PASS (pass_ipa_cp);
109  NEXT_PASS (pass_ipa_cdtor_merge);
110  NEXT_PASS (pass_ipa_inline);
111  NEXT_PASS (pass_ipa_pure_const);
112  NEXT_PASS (pass_ipa_reference);
113  TERMINATE_PASS_LIST ()
114
115  /* Simple IPA passes executed after the regular passes.  In WHOPR mode the
116     passes are executed after partitioning and thus see just parts of the
117     compiled unit.  */
118  INSERT_PASSES_AFTER (all_late_ipa_passes)
119  NEXT_PASS (pass_ipa_pta);
120  NEXT_PASS (pass_omp_simd_clone);
121  TERMINATE_PASS_LIST ()
122
123  /* These passes are run after IPA passes on every function that is being
124     output to the assembler file.  */
125  INSERT_PASSES_AFTER (all_passes)
126  NEXT_PASS (pass_fixup_cfg);
127  NEXT_PASS (pass_lower_eh_dispatch);
128  NEXT_PASS (pass_all_optimizations);
129  PUSH_INSERT_PASSES_WITHIN (pass_all_optimizations)
130      NEXT_PASS (pass_remove_cgraph_callee_edges);
131      /* Initial scalar cleanups before alias computation.
132	 They ensure memory accesses are not indirect wherever possible.  */
133      NEXT_PASS (pass_strip_predict_hints);
134      NEXT_PASS (pass_rename_ssa_copies);
135      NEXT_PASS (pass_ccp);
136      /* After CCP we rewrite no longer addressed locals into SSA
137	 form if possible.  */
138      NEXT_PASS (pass_copy_prop);
139      NEXT_PASS (pass_complete_unrolli);
140      NEXT_PASS (pass_phiprop);
141      NEXT_PASS (pass_forwprop);
142      NEXT_PASS (pass_object_sizes);
143      /* pass_build_alias is a dummy pass that ensures that we
144	 execute TODO_rebuild_alias at this point.  */
145      NEXT_PASS (pass_build_alias);
146      NEXT_PASS (pass_return_slot);
147      NEXT_PASS (pass_fre);
148      NEXT_PASS (pass_copy_prop);
149      NEXT_PASS (pass_merge_phi);
150      NEXT_PASS (pass_vrp);
151      NEXT_PASS (pass_dce);
152      NEXT_PASS (pass_call_cdce);
153      NEXT_PASS (pass_cselim);
154      NEXT_PASS (pass_tree_ifcombine);
155      NEXT_PASS (pass_phiopt);
156      NEXT_PASS (pass_tail_recursion);
157      NEXT_PASS (pass_ch);
158      NEXT_PASS (pass_stdarg);
159      NEXT_PASS (pass_lower_complex);
160      NEXT_PASS (pass_sra);
161      NEXT_PASS (pass_rename_ssa_copies);
162      /* The dom pass will also resolve all __builtin_constant_p calls
163         that are still there to 0.  This has to be done after some
164	 propagations have already run, but before some more dead code
165	 is removed, and this place fits nicely.  Remember this when
166	 trying to move or duplicate pass_dominator somewhere earlier.  */
167      NEXT_PASS (pass_dominator);
168      /* At this point the majority of const/copy propagations
169	 are exposed.  Go ahead and identify paths that should never
170	 be executed in a conforming program and isolate those paths.
171
172	 This will expose more degenerate PHIs in the main path and
173	 expose more PRE/DOM optimization opportunities.  */
174      NEXT_PASS (pass_isolate_erroneous_paths);
175      /* The only const/copy propagation opportunities left after
176	 DOM and erroneous path isolation should be due to degenerate PHI nodes.
177	 So rather than run the full propagators, run a specialized pass which
178	 only examines PHIs to discover const/copy propagation
179	 opportunities.  */
180      NEXT_PASS (pass_phi_only_cprop);
181      NEXT_PASS (pass_dse);
182      NEXT_PASS (pass_reassoc);
183      NEXT_PASS (pass_dce);
184      NEXT_PASS (pass_forwprop);
185      NEXT_PASS (pass_phiopt);
186      NEXT_PASS (pass_strlen);
187      NEXT_PASS (pass_ccp);
188      /* After CCP we rewrite no longer addressed locals into SSA
189	 form if possible.  */
190      NEXT_PASS (pass_copy_prop);
191      NEXT_PASS (pass_cse_sincos);
192      NEXT_PASS (pass_optimize_bswap);
193      NEXT_PASS (pass_split_crit_edges);
194      NEXT_PASS (pass_pre);
195      NEXT_PASS (pass_sink_code);
196      NEXT_PASS (pass_asan);
197      NEXT_PASS (pass_tsan);
198      NEXT_PASS (pass_tree_loop);
199      PUSH_INSERT_PASSES_WITHIN (pass_tree_loop)
200	  NEXT_PASS (pass_tree_loop_init);
201	  NEXT_PASS (pass_lim);
202	  NEXT_PASS (pass_copy_prop);
203	  NEXT_PASS (pass_dce_loop);
204	  NEXT_PASS (pass_tree_unswitch);
205	  NEXT_PASS (pass_scev_cprop);
206	  NEXT_PASS (pass_record_bounds);
207	  NEXT_PASS (pass_check_data_deps);
208	  NEXT_PASS (pass_loop_distribution);
209	  NEXT_PASS (pass_copy_prop);
210	  NEXT_PASS (pass_graphite);
211	  PUSH_INSERT_PASSES_WITHIN (pass_graphite)
212	      NEXT_PASS (pass_graphite_transforms);
213	      NEXT_PASS (pass_lim);
214	      NEXT_PASS (pass_copy_prop);
215	      NEXT_PASS (pass_dce_loop);
216	  POP_INSERT_PASSES ()
217	  NEXT_PASS (pass_iv_canon);
218	  NEXT_PASS (pass_parallelize_loops);
219	  NEXT_PASS (pass_if_conversion);
220	  /* pass_vectorize must immediately follow pass_if_conversion.
221	     Please do not add any other passes in between.  */
222	  NEXT_PASS (pass_vectorize);
223          PUSH_INSERT_PASSES_WITHIN (pass_vectorize)
224	      NEXT_PASS (pass_dce_loop);
225          POP_INSERT_PASSES ()
226          NEXT_PASS (pass_predcom);
227	  NEXT_PASS (pass_complete_unroll);
228	  NEXT_PASS (pass_slp_vectorize);
229	  NEXT_PASS (pass_loop_prefetch);
230	  NEXT_PASS (pass_iv_optimize);
231	  NEXT_PASS (pass_lim);
232	  NEXT_PASS (pass_tree_loop_done);
233      POP_INSERT_PASSES ()
234      NEXT_PASS (pass_lower_vector_ssa);
235      NEXT_PASS (pass_cse_reciprocals);
236      NEXT_PASS (pass_reassoc);
237      NEXT_PASS (pass_strength_reduction);
238      NEXT_PASS (pass_dominator);
239      /* The only const/copy propagation opportunities left after
240	 DOM should be due to degenerate PHI nodes.  So rather than
241	 run the full propagators, run a specialized pass which
242	 only examines PHIs to discover const/copy propagation
243	 opportunities.  */
244      NEXT_PASS (pass_phi_only_cprop);
245      NEXT_PASS (pass_vrp);
246      NEXT_PASS (pass_cd_dce);
247      NEXT_PASS (pass_tracer);
248      NEXT_PASS (pass_dse);
249      NEXT_PASS (pass_forwprop);
250      NEXT_PASS (pass_phiopt);
251      NEXT_PASS (pass_fold_builtins);
252      NEXT_PASS (pass_optimize_widening_mul);
253      NEXT_PASS (pass_tail_calls);
254      NEXT_PASS (pass_rename_ssa_copies);
255      /* FIXME: If DCE is not run before checking for uninitialized uses,
256	 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
257	 However, this also causes us to misdiagnose cases that should be
258	 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
259
260	 To fix the false positives in uninit-5.c, we would have to
261	 account for the predicates protecting the set and the use of each
262	 variable.  Using a representation like Gated Single Assignment
263	 may help.  */
264      /* Split critical edges before late uninit warning to reduce the
265         number of false positives from it.  */
266      NEXT_PASS (pass_split_crit_edges);
267      NEXT_PASS (pass_late_warn_uninitialized);
268      NEXT_PASS (pass_uncprop);
269      NEXT_PASS (pass_local_pure_const);
270  POP_INSERT_PASSES ()
271  NEXT_PASS (pass_all_optimizations_g);
272  PUSH_INSERT_PASSES_WITHIN (pass_all_optimizations_g)
273      NEXT_PASS (pass_remove_cgraph_callee_edges);
274      NEXT_PASS (pass_strip_predict_hints);
275      /* Lower remaining pieces of GIMPLE.  */
276      NEXT_PASS (pass_lower_complex);
277      NEXT_PASS (pass_lower_vector_ssa);
278      /* Perform simple scalar cleanup which is constant/copy propagation.  */
279      NEXT_PASS (pass_ccp);
280      NEXT_PASS (pass_object_sizes);
281      /* Fold remaining builtins.  */
282      NEXT_PASS (pass_fold_builtins);
283      /* Copy propagation also copy-propagates constants, this is necessary
284         to forward object-size and builtin folding results properly.  */
285      NEXT_PASS (pass_copy_prop);
286      NEXT_PASS (pass_dce);
287      NEXT_PASS (pass_asan);
288      NEXT_PASS (pass_tsan);
289      NEXT_PASS (pass_rename_ssa_copies);
290      /* ???  We do want some kind of loop invariant motion, but we possibly
291         need to adjust LIM to be more friendly towards preserving accurate
292	 debug information here.  */
293      /* Split critical edges before late uninit warning to reduce the
294         number of false positives from it.  */
295      NEXT_PASS (pass_split_crit_edges);
296      NEXT_PASS (pass_late_warn_uninitialized);
297      NEXT_PASS (pass_uncprop);
298      NEXT_PASS (pass_local_pure_const);
299  POP_INSERT_PASSES ()
300  NEXT_PASS (pass_tm_init);
301  PUSH_INSERT_PASSES_WITHIN (pass_tm_init)
302      NEXT_PASS (pass_tm_mark);
303      NEXT_PASS (pass_tm_memopt);
304      NEXT_PASS (pass_tm_edges);
305  POP_INSERT_PASSES ()
306  NEXT_PASS (pass_vtable_verify);
307  NEXT_PASS (pass_lower_vector);
308  NEXT_PASS (pass_lower_complex_O0);
309  NEXT_PASS (pass_asan_O0);
310  NEXT_PASS (pass_tsan_O0);
311  NEXT_PASS (pass_sanopt);
312  NEXT_PASS (pass_cleanup_eh);
313  NEXT_PASS (pass_lower_resx);
314  NEXT_PASS (pass_nrv);
315  NEXT_PASS (pass_cleanup_cfg_post_optimizing);
316  NEXT_PASS (pass_warn_function_noreturn);
317
318  NEXT_PASS (pass_expand);
319
320  NEXT_PASS (pass_rest_of_compilation);
321  PUSH_INSERT_PASSES_WITHIN (pass_rest_of_compilation)
322      NEXT_PASS (pass_instantiate_virtual_regs);
323      NEXT_PASS (pass_into_cfg_layout_mode);
324      NEXT_PASS (pass_jump);
325      NEXT_PASS (pass_lower_subreg);
326      NEXT_PASS (pass_df_initialize_opt);
327      NEXT_PASS (pass_cse);
328      NEXT_PASS (pass_rtl_fwprop);
329      NEXT_PASS (pass_rtl_cprop);
330      NEXT_PASS (pass_rtl_pre);
331      NEXT_PASS (pass_rtl_hoist);
332      NEXT_PASS (pass_rtl_cprop);
333      NEXT_PASS (pass_rtl_store_motion);
334      NEXT_PASS (pass_cse_after_global_opts);
335      NEXT_PASS (pass_rtl_ifcvt);
336      NEXT_PASS (pass_reginfo_init);
337      /* Perform loop optimizations.  It might be better to do them a bit
338	 sooner, but we want the profile feedback to work more
339	 efficiently.  */
340      NEXT_PASS (pass_loop2);
341      PUSH_INSERT_PASSES_WITHIN (pass_loop2)
342	  NEXT_PASS (pass_rtl_loop_init);
343	  NEXT_PASS (pass_rtl_move_loop_invariants);
344	  NEXT_PASS (pass_rtl_unswitch);
345	  NEXT_PASS (pass_rtl_unroll_and_peel_loops);
346	  NEXT_PASS (pass_rtl_doloop);
347	  NEXT_PASS (pass_rtl_loop_done);
348	  TERMINATE_PASS_LIST ()
349      POP_INSERT_PASSES ()
350      NEXT_PASS (pass_web);
351      NEXT_PASS (pass_rtl_cprop);
352      NEXT_PASS (pass_cse2);
353      NEXT_PASS (pass_rtl_dse1);
354      NEXT_PASS (pass_rtl_fwprop_addr);
355      NEXT_PASS (pass_inc_dec);
356      NEXT_PASS (pass_initialize_regs);
357      NEXT_PASS (pass_ud_rtl_dce);
358      NEXT_PASS (pass_combine);
359      NEXT_PASS (pass_if_after_combine);
360      NEXT_PASS (pass_partition_blocks);
361      NEXT_PASS (pass_outof_cfg_layout_mode);
362      NEXT_PASS (pass_split_all_insns);
363      NEXT_PASS (pass_lower_subreg2);
364      NEXT_PASS (pass_df_initialize_no_opt);
365      NEXT_PASS (pass_stack_ptr_mod);
366      NEXT_PASS (pass_mode_switching);
367      NEXT_PASS (pass_match_asm_constraints);
368      NEXT_PASS (pass_sms);
369      NEXT_PASS (pass_live_range_shrinkage);
370      NEXT_PASS (pass_sched);
371      NEXT_PASS (pass_ira);
372      NEXT_PASS (pass_reload);
373      NEXT_PASS (pass_postreload);
374      PUSH_INSERT_PASSES_WITHIN (pass_postreload)
375	  NEXT_PASS (pass_postreload_cse);
376	  NEXT_PASS (pass_gcse2);
377	  NEXT_PASS (pass_split_after_reload);
378	  NEXT_PASS (pass_ree);
379	  NEXT_PASS (pass_compare_elim_after_reload);
380	  NEXT_PASS (pass_branch_target_load_optimize1);
381	  NEXT_PASS (pass_thread_prologue_and_epilogue);
382	  NEXT_PASS (pass_rtl_dse2);
383	  NEXT_PASS (pass_stack_adjustments);
384	  NEXT_PASS (pass_jump2);
385	  NEXT_PASS (pass_peephole2);
386	  NEXT_PASS (pass_if_after_reload);
387	  NEXT_PASS (pass_regrename);
388	  NEXT_PASS (pass_cprop_hardreg);
389	  NEXT_PASS (pass_fast_rtl_dce);
390	  NEXT_PASS (pass_duplicate_computed_gotos);
391	  NEXT_PASS (pass_reorder_blocks);
392	  NEXT_PASS (pass_branch_target_load_optimize2);
393	  NEXT_PASS (pass_leaf_regs);
394	  NEXT_PASS (pass_split_before_sched2);
395	  NEXT_PASS (pass_sched2);
396	  NEXT_PASS (pass_stack_regs);
397	  PUSH_INSERT_PASSES_WITHIN (pass_stack_regs)
398	      NEXT_PASS (pass_split_before_regstack);
399	      NEXT_PASS (pass_stack_regs_run);
400	  POP_INSERT_PASSES ()
401	  NEXT_PASS (pass_compute_alignments);
402	  NEXT_PASS (pass_variable_tracking);
403	  NEXT_PASS (pass_free_cfg);
404	  NEXT_PASS (pass_machine_reorg);
405	  NEXT_PASS (pass_cleanup_barriers);
406	  NEXT_PASS (pass_delay_slots);
407	  NEXT_PASS (pass_split_for_shorten_branches);
408	  NEXT_PASS (pass_convert_to_eh_region_ranges);
409	  NEXT_PASS (pass_shorten_branches);
410	  NEXT_PASS (pass_set_nothrow_function_flags);
411	  NEXT_PASS (pass_dwarf2_frame);
412	  NEXT_PASS (pass_final);
413      POP_INSERT_PASSES ()
414      NEXT_PASS (pass_df_finish);
415  POP_INSERT_PASSES ()
416  NEXT_PASS (pass_clean_state);
417  TERMINATE_PASS_LIST ()
418