1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This is the top level of cc1/c++.
21 It parses command args, opens files, invokes the various passes
22 in the proper order, and counts the time used by each.
23 Error messages and low-level interface to malloc also handled here. */
27 #include "coretypes.h"
40 #include "lto-streamer.h"
41 #include "fold-const.h"
47 #include "value-prof.h"
49 #include "tree-ssa-loop-manip.h"
50 #include "tree-into-ssa.h"
53 #include "tree-pass.h"
55 #include "ipa-utils.h"
56 #include "tree-pretty-print.h" /* for dump_function_header */
58 #include "pass_manager.h"
60 #include "tree-ssa-live.h" /* For remove_unused_locals. */
61 #include "tree-cfgcleanup.h"
62 #include "insn-addr.h" /* for INSN_ADDRESSES_ALLOC. */
63 #include "diagnostic-core.h" /* for fnotice */
64 #include "stringpool.h"
69 /* This is used for debugging. It allows the current pass to printed
70 from anywhere in compilation.
71 The variable current_pass is also used for statistics and plugins. */
72 opt_pass
*current_pass
;
74 /* Most passes are single-instance (within their context) and thus don't
75 need to implement cloning, but passes that support multiple instances
76 *must* provide their own implementation of the clone method.
78 Handle this by providing a default implemenation, but make it a fatal
84 internal_error ("pass %s does not support cloning", name
);
88 opt_pass::set_pass_param (unsigned int, bool)
90 internal_error ("pass %s needs a set_pass_param implementation to handle the"
91 " extra argument in NEXT_PASS", name
);
95 opt_pass::gate (function
*)
101 opt_pass::execute (function
*)
106 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
110 static_pass_number (0),
117 pass_manager::execute_early_local_passes ()
119 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
120 if (flag_check_pointer_bounds
)
121 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
122 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
126 pass_manager::execute_pass_mode_switching ()
128 return pass_mode_switching_1
->execute (cfun
);
132 /* Call from anywhere to find out what pass this is. Useful for
133 printing out debugging information deep inside an service
136 print_current_pass (FILE *file
)
139 fprintf (file
, "current pass = %s (%d)\n",
140 current_pass
->name
, current_pass
->static_pass_number
);
142 fprintf (file
, "no current pass.\n");
146 /* Call from the debugger to get the current pass name. */
150 print_current_pass (stderr
);
155 /* Global variables used to communicate with passes. */
159 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
162 This does nothing for local (non-static) variables, unless the
163 variable is a register variable with DECL_ASSEMBLER_NAME set. In
164 that case, or if the variable is not an automatic, it sets up the
165 RTL and outputs any assembler code (label definition, storage
166 allocation and initialization).
168 DECL is the declaration. TOP_LEVEL is nonzero
169 if this declaration is not within a function. */
172 rest_of_decl_compilation (tree decl
,
176 bool finalize
= true;
178 /* We deferred calling assemble_alias so that we could collect
179 other attributes such as visibility. Emit the alias now. */
183 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
186 alias
= TREE_VALUE (TREE_VALUE (alias
));
187 alias
= get_identifier (TREE_STRING_POINTER (alias
));
188 /* A quirk of the initial implementation of aliases required that the
189 user add "extern" to all of them. Which is silly, but now
190 historical. Do note that the symbol is in fact locally defined. */
191 DECL_EXTERNAL (decl
) = 0;
192 TREE_STATIC (decl
) = 1;
193 assemble_alias (decl
, alias
);
198 /* Can't defer this, because it needs to happen before any
199 later function definitions are processed. */
200 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
201 make_decl_rtl (decl
);
203 /* Forward declarations for nested functions are not "external",
204 but we need to treat them as if they were. */
205 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
206 || TREE_CODE (decl
) == FUNCTION_DECL
)
208 timevar_push (TV_VARCONST
);
210 /* Don't output anything when a tentative file-scope definition
211 is seen. But at end of compilation, do output code for them.
213 We do output all variables and rely on
214 callgraph code to defer them except for forward declarations
215 (see gcc.c-torture/compile/920624-1.c) */
217 || !DECL_DEFER_OUTPUT (decl
)
218 || DECL_INITIAL (decl
))
219 && (!VAR_P (decl
) || !DECL_HAS_VALUE_EXPR_P (decl
))
220 && !DECL_EXTERNAL (decl
))
222 /* When reading LTO unit, we also read varpool, so do not
224 if (in_lto_p
&& !at_end
)
226 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
227 varpool_node::finalize_decl (decl
);
230 #ifdef ASM_FINISH_DECLARE_OBJECT
231 if (decl
== last_assemble_variable_decl
)
233 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
238 /* Now that we have activated any function-specific attributes
239 that might affect function decl, particularly align, relayout it. */
240 if (TREE_CODE (decl
) == FUNCTION_DECL
)
241 targetm
.target_option
.relayout_function (decl
);
243 timevar_pop (TV_VARCONST
);
245 else if (TREE_CODE (decl
) == TYPE_DECL
246 /* Like in rest_of_type_compilation, avoid confusing the debug
247 information machinery when there are errors. */
250 timevar_push (TV_SYMOUT
);
251 debug_hooks
->type_decl (decl
, !top_level
);
252 timevar_pop (TV_SYMOUT
);
255 /* Let cgraph know about the existence of variables. */
256 if (in_lto_p
&& !at_end
)
258 else if (VAR_P (decl
) && !DECL_EXTERNAL (decl
)
259 && TREE_STATIC (decl
))
260 varpool_node::get_create (decl
);
262 /* Generate early debug for global variables. Any local variables will
263 be handled by either handling reachable functions from
264 finalize_compilation_unit (and by consequence, locally scoped
265 symbols), or by rest_of_type_compilation below.
267 For Go's hijack of the debug_hooks to implement -fdump-go-spec, pick up
268 function prototypes. Go's debug_hooks will not forward them to the
271 && (TREE_CODE (decl
) != FUNCTION_DECL
272 /* This will pick up function prototypes with no bodies,
273 which are not visible in finalize_compilation_unit()
274 while iterating with FOR_EACH_*_FUNCTION through the
276 || (flag_dump_go_spec
!= NULL
277 && !DECL_SAVED_TREE (decl
)
278 && DECL_STRUCT_FUNCTION (decl
) == NULL
))
280 /* We need to check both decl_function_context and
281 current_function_decl here to make sure local extern
282 declarations end up with the correct context.
284 For local extern declarations, decl_function_context is
285 empty, but current_function_decl is set to the function where
286 the extern was declared . Without the check for
287 !current_function_decl below, the local extern ends up
288 incorrectly with a top-level context.
300 extern int i; // Local extern declaration.
307 && !decl_function_context (decl
)
308 && !current_function_decl
309 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
310 && (!decl_type_context (decl
)
311 /* If we created a varpool node for the decl make sure to
312 call early_global_decl. Otherwise we miss changes
313 introduced by member definitions like
314 struct A { static int staticdatamember; };
315 int A::staticdatamember;
316 and thus have incomplete early debug and late debug
317 called from varpool node removal fails to handle it
321 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
322 /* Avoid confusing the debug information machinery when there are
325 (*debug_hooks
->early_global_decl
) (decl
);
328 /* Called after finishing a record, union or enumeral type. */
331 rest_of_type_compilation (tree type
, int toplev
)
333 /* Avoid confusing the debug information machinery when there are
338 timevar_push (TV_SYMOUT
);
339 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
340 timevar_pop (TV_SYMOUT
);
347 finish_optimization_passes (void)
350 struct dump_file_info
*dfi
;
352 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
354 timevar_push (TV_DUMP
);
355 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
357 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
359 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
364 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
365 print_combine_total_stats ();
366 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
369 /* Do whatever is necessary to finish printing the graphs. */
370 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
371 if (dfi
->graph_dump_initialized
)
373 name
= dumps
->get_dump_file_name (dfi
);
374 finish_graph_dump_file (name
);
378 timevar_pop (TV_DUMP
);
382 execute_build_ssa_passes (void)
384 /* Once this pass (and its sub-passes) are complete, all functions
385 will be in SSA form. Technically this state change is happening
386 a tad early, since the sub-passes have not yet run, but since
387 none of the sub-passes are IPA passes and do not create new
388 functions, this is ok. We're setting this value for the benefit
389 of IPA passes that follow. */
390 if (symtab
->state
< IPA_SSA
)
391 symtab
->state
= IPA_SSA
;
397 const pass_data pass_data_build_ssa_passes
=
399 SIMPLE_IPA_PASS
, /* type */
400 "build_ssa_passes", /* name */
401 OPTGROUP_NONE
, /* optinfo_flags */
402 TV_EARLY_LOCAL
, /* tv_id */
403 0, /* properties_required */
404 0, /* properties_provided */
405 0, /* properties_destroyed */
406 0, /* todo_flags_start */
407 /* todo_flags_finish is executed before subpases. For this reason
408 it makes no sense to remove unreachable functions here. */
409 0, /* todo_flags_finish */
412 class pass_build_ssa_passes
: public simple_ipa_opt_pass
415 pass_build_ssa_passes (gcc::context
*ctxt
)
416 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
419 /* opt_pass methods: */
420 virtual bool gate (function
*)
422 /* Don't bother doing anything if the program has errors. */
423 return (!seen_error () && !in_lto_p
);
426 virtual unsigned int execute (function
*)
428 return execute_build_ssa_passes ();
431 }; // class pass_build_ssa_passes
433 const pass_data pass_data_chkp_instrumentation_passes
=
435 SIMPLE_IPA_PASS
, /* type */
436 "chkp_passes", /* name */
437 OPTGROUP_NONE
, /* optinfo_flags */
439 0, /* properties_required */
440 0, /* properties_provided */
441 0, /* properties_destroyed */
442 0, /* todo_flags_start */
443 0, /* todo_flags_finish */
446 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
449 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
450 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
453 /* opt_pass methods: */
454 virtual bool gate (function
*)
456 /* Don't bother doing anything if the program has errors. */
457 return (flag_check_pointer_bounds
458 && !seen_error () && !in_lto_p
);
461 }; // class pass_chkp_instrumentation_passes
463 const pass_data pass_data_local_optimization_passes
=
465 SIMPLE_IPA_PASS
, /* type */
466 "opt_local_passes", /* name */
467 OPTGROUP_NONE
, /* optinfo_flags */
469 0, /* properties_required */
470 0, /* properties_provided */
471 0, /* properties_destroyed */
472 0, /* todo_flags_start */
473 0, /* todo_flags_finish */
476 class pass_local_optimization_passes
: public simple_ipa_opt_pass
479 pass_local_optimization_passes (gcc::context
*ctxt
)
480 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
483 /* opt_pass methods: */
484 virtual bool gate (function
*)
486 /* Don't bother doing anything if the program has errors. */
487 return (!seen_error () && !in_lto_p
);
490 }; // class pass_local_optimization_passes
494 simple_ipa_opt_pass
*
495 make_pass_build_ssa_passes (gcc::context
*ctxt
)
497 return new pass_build_ssa_passes (ctxt
);
500 simple_ipa_opt_pass
*
501 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
503 return new pass_chkp_instrumentation_passes (ctxt
);
506 simple_ipa_opt_pass
*
507 make_pass_local_optimization_passes (gcc::context
*ctxt
)
509 return new pass_local_optimization_passes (ctxt
);
514 const pass_data pass_data_all_early_optimizations
=
516 GIMPLE_PASS
, /* type */
517 "early_optimizations", /* name */
518 OPTGROUP_NONE
, /* optinfo_flags */
520 0, /* properties_required */
521 0, /* properties_provided */
522 0, /* properties_destroyed */
523 0, /* todo_flags_start */
524 0, /* todo_flags_finish */
527 class pass_all_early_optimizations
: public gimple_opt_pass
530 pass_all_early_optimizations (gcc::context
*ctxt
)
531 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
534 /* opt_pass methods: */
535 virtual bool gate (function
*)
537 return (optimize
>= 1
538 /* Don't bother doing anything if the program has errors. */
542 }; // class pass_all_early_optimizations
546 static gimple_opt_pass
*
547 make_pass_all_early_optimizations (gcc::context
*ctxt
)
549 return new pass_all_early_optimizations (ctxt
);
554 const pass_data pass_data_all_optimizations
=
556 GIMPLE_PASS
, /* type */
557 "*all_optimizations", /* name */
558 OPTGROUP_NONE
, /* optinfo_flags */
559 TV_OPTIMIZE
, /* tv_id */
560 0, /* properties_required */
561 0, /* properties_provided */
562 0, /* properties_destroyed */
563 0, /* todo_flags_start */
564 0, /* todo_flags_finish */
567 class pass_all_optimizations
: public gimple_opt_pass
570 pass_all_optimizations (gcc::context
*ctxt
)
571 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
574 /* opt_pass methods: */
575 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
577 }; // class pass_all_optimizations
581 static gimple_opt_pass
*
582 make_pass_all_optimizations (gcc::context
*ctxt
)
584 return new pass_all_optimizations (ctxt
);
589 const pass_data pass_data_all_optimizations_g
=
591 GIMPLE_PASS
, /* type */
592 "*all_optimizations_g", /* name */
593 OPTGROUP_NONE
, /* optinfo_flags */
594 TV_OPTIMIZE
, /* tv_id */
595 0, /* properties_required */
596 0, /* properties_provided */
597 0, /* properties_destroyed */
598 0, /* todo_flags_start */
599 0, /* todo_flags_finish */
602 class pass_all_optimizations_g
: public gimple_opt_pass
605 pass_all_optimizations_g (gcc::context
*ctxt
)
606 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
609 /* opt_pass methods: */
610 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
612 }; // class pass_all_optimizations_g
616 static gimple_opt_pass
*
617 make_pass_all_optimizations_g (gcc::context
*ctxt
)
619 return new pass_all_optimizations_g (ctxt
);
624 const pass_data pass_data_rest_of_compilation
=
627 "*rest_of_compilation", /* name */
628 OPTGROUP_NONE
, /* optinfo_flags */
629 TV_REST_OF_COMPILATION
, /* tv_id */
630 PROP_rtl
, /* properties_required */
631 0, /* properties_provided */
632 0, /* properties_destroyed */
633 0, /* todo_flags_start */
634 0, /* todo_flags_finish */
637 class pass_rest_of_compilation
: public rtl_opt_pass
640 pass_rest_of_compilation (gcc::context
*ctxt
)
641 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
644 /* opt_pass methods: */
645 virtual bool gate (function
*)
647 /* Early return if there were errors. We can run afoul of our
648 consistency checks, and there's not really much point in fixing them. */
649 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
652 }; // class pass_rest_of_compilation
656 static rtl_opt_pass
*
657 make_pass_rest_of_compilation (gcc::context
*ctxt
)
659 return new pass_rest_of_compilation (ctxt
);
664 const pass_data pass_data_postreload
=
667 "*all-postreload", /* name */
668 OPTGROUP_NONE
, /* optinfo_flags */
669 TV_POSTRELOAD
, /* tv_id */
670 PROP_rtl
, /* properties_required */
671 0, /* properties_provided */
672 0, /* properties_destroyed */
673 0, /* todo_flags_start */
674 0, /* todo_flags_finish */
677 class pass_postreload
: public rtl_opt_pass
680 pass_postreload (gcc::context
*ctxt
)
681 : rtl_opt_pass (pass_data_postreload
, ctxt
)
684 /* opt_pass methods: */
685 virtual bool gate (function
*) { return reload_completed
; }
687 }; // class pass_postreload
691 static rtl_opt_pass
*
692 make_pass_postreload (gcc::context
*ctxt
)
694 return new pass_postreload (ctxt
);
699 const pass_data pass_data_late_compilation
=
702 "*all-late_compilation", /* name */
703 OPTGROUP_NONE
, /* optinfo_flags */
704 TV_LATE_COMPILATION
, /* tv_id */
705 PROP_rtl
, /* properties_required */
706 0, /* properties_provided */
707 0, /* properties_destroyed */
708 0, /* todo_flags_start */
709 0, /* todo_flags_finish */
712 class pass_late_compilation
: public rtl_opt_pass
715 pass_late_compilation (gcc::context
*ctxt
)
716 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
719 /* opt_pass methods: */
720 virtual bool gate (function
*)
722 return reload_completed
|| targetm
.no_register_allocation
;
725 }; // class pass_late_compilation
729 static rtl_opt_pass
*
730 make_pass_late_compilation (gcc::context
*ctxt
)
732 return new pass_late_compilation (ctxt
);
737 /* Set the static pass number of pass PASS to ID and record that
738 in the mapping from static pass number to pass. */
742 set_pass_for_id (int id
, opt_pass
*pass
)
744 pass
->static_pass_number
= id
;
745 if (passes_by_id_size
<= id
)
747 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
748 memset (passes_by_id
+ passes_by_id_size
, 0,
749 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
750 passes_by_id_size
= id
+ 1;
752 passes_by_id
[id
] = pass
;
755 /* Return the pass with the static pass number ID. */
758 pass_manager::get_pass_for_id (int id
) const
760 if (id
>= passes_by_id_size
)
762 return passes_by_id
[id
];
765 /* Iterate over the pass tree allocating dump file numbers. We want
766 to do this depth first, and independent of whether the pass is
770 register_one_dump_file (opt_pass
*pass
)
772 g
->get_passes ()->register_one_dump_file (pass
);
776 pass_manager::register_one_dump_file (opt_pass
*pass
)
778 char *dot_name
, *flag_name
, *glob_name
;
779 const char *name
, *full_name
, *prefix
;
781 /* Buffer big enough to format a 32-bit UINT_MAX into. */
785 int optgroup_flags
= OPTGROUP_NONE
;
786 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
788 /* See below in next_pass_1. */
790 if (pass
->static_pass_number
!= -1)
791 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
792 ? 1 : pass
->static_pass_number
));
794 /* The name is both used to identify the pass for the purposes of plugins,
795 and to specify dump file name and option.
796 The latter two might want something short which is not quite unique; for
797 that reason, we may have a disambiguating prefix, followed by a space
798 to mark the start of the following dump file name / option string. */
799 name
= strchr (pass
->name
, ' ');
800 name
= name
? name
+ 1 : pass
->name
;
801 dot_name
= concat (".", name
, num
, NULL
);
802 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
806 optgroup_flags
|= OPTGROUP_IPA
;
808 else if (pass
->type
== GIMPLE_PASS
)
819 flag_name
= concat (prefix
, name
, num
, NULL
);
820 glob_name
= concat (prefix
, name
, NULL
);
821 optgroup_flags
|= pass
->optinfo_flags
;
822 /* For any passes that do not have an optgroup set, and which are not
823 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
824 any dump messages are emitted properly under -fopt-info(-optall). */
825 if (optgroup_flags
== OPTGROUP_NONE
)
826 optgroup_flags
= OPTGROUP_OTHER
;
827 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, dkind
,
830 set_pass_for_id (id
, pass
);
831 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
832 register_pass_name (pass
, full_name
);
833 free (CONST_CAST (char *, full_name
));
836 /* Register the dump files for the pass_manager starting at PASS. */
839 pass_manager::register_dump_files (opt_pass
*pass
)
843 if (pass
->name
&& pass
->name
[0] != '*')
844 register_one_dump_file (pass
);
847 register_dump_files (pass
->sub
);
854 /* Register PASS with NAME. */
857 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
859 if (!m_name_to_pass_map
)
860 m_name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
862 if (m_name_to_pass_map
->get (name
))
863 return; /* Ignore plugin passes. */
865 const char *unique_name
= xstrdup (name
);
866 m_name_to_pass_map
->put (unique_name
, pass
);
869 /* Map from pass id to canonicalized pass name. */
871 typedef const char *char_ptr
;
872 static vec
<char_ptr
> pass_tab
;
874 /* Callback function for traversing NAME_TO_PASS_MAP. */
877 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
879 gcc_assert (pass
->static_pass_number
> 0);
880 gcc_assert (pass_tab
.exists ());
882 pass_tab
[pass
->static_pass_number
] = name
;
887 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
888 table for dumping purpose. */
891 pass_manager::create_pass_tab (void) const
893 if (!flag_dump_passes
)
896 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
897 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
900 static bool override_gate_status (opt_pass
*, tree
, bool);
902 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
903 is turned on or not. */
906 dump_one_pass (opt_pass
*pass
, int pass_indent
)
908 int indent
= 3 * pass_indent
;
910 bool is_on
, is_really_on
;
912 is_on
= pass
->gate (cfun
);
913 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
915 if (pass
->static_pass_number
<= 0)
918 pn
= pass_tab
[pass
->static_pass_number
];
920 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
921 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
922 is_on
? " ON" : " OFF",
923 ((!is_on
) == (!is_really_on
) ? ""
924 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
927 /* Dump pass list PASS with indentation INDENT. */
930 dump_pass_list (opt_pass
*pass
, int indent
)
934 dump_one_pass (pass
, indent
);
936 dump_pass_list (pass
->sub
, indent
+ 1);
942 /* Dump all optimization passes. */
947 g
->get_passes ()->dump_passes ();
951 pass_manager::dump_passes () const
953 push_dummy_function (true);
957 dump_pass_list (all_lowering_passes
, 1);
958 dump_pass_list (all_small_ipa_passes
, 1);
959 dump_pass_list (all_regular_ipa_passes
, 1);
960 dump_pass_list (all_late_ipa_passes
, 1);
961 dump_pass_list (all_passes
, 1);
963 pop_dummy_function ();
966 /* Returns the pass with NAME. */
969 pass_manager::get_pass_by_name (const char *name
)
971 opt_pass
**p
= m_name_to_pass_map
->get (name
);
979 /* Range [start, last]. */
985 const char *assem_name
;
986 struct uid_range
*next
;
989 typedef struct uid_range
*uid_range_p
;
992 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
993 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
996 /* Parse option string for -fdisable- and -fenable-
997 The syntax of the options:
1000 -fdisable-<pass_name>
1002 -fenable-<pass_name>=s1:e1,s2:e2,...
1003 -fdisable-<pass_name>=s1:e1,s2:e2,...
1007 enable_disable_pass (const char *arg
, bool is_enable
)
1010 char *range_str
, *phase_name
;
1011 char *argstr
= xstrdup (arg
);
1012 vec
<uid_range_p
> *tab
= 0;
1014 range_str
= strchr (argstr
,'=');
1021 phase_name
= argstr
;
1025 error ("unrecognized option -fenable");
1027 error ("unrecognized option -fdisable");
1031 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1032 if (!pass
|| pass
->static_pass_number
== -1)
1035 error ("unknown pass %s specified in -fenable", phase_name
);
1037 error ("unknown pass %s specified in -fdisable", phase_name
);
1043 tab
= &enabled_pass_uid_range_tab
;
1045 tab
= &disabled_pass_uid_range_tab
;
1047 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1048 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1053 uid_range_p new_range
= XCNEW (struct uid_range
);
1055 new_range
->start
= 0;
1056 new_range
->last
= (unsigned)-1;
1058 slot
= (*tab
)[pass
->static_pass_number
];
1059 new_range
->next
= slot
;
1060 (*tab
)[pass
->static_pass_number
] = new_range
;
1062 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1063 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1065 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1066 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1070 char *next_range
= NULL
;
1071 char *one_range
= range_str
;
1072 char *end_val
= NULL
;
1077 uid_range_p new_range
;
1078 char *invalid
= NULL
;
1080 char *func_name
= NULL
;
1082 next_range
= strchr (one_range
, ',');
1089 end_val
= strchr (one_range
, ':');
1095 start
= strtol (one_range
, &invalid
, 10);
1096 if (*invalid
|| start
< 0)
1098 if (end_val
|| (one_range
[0] >= '0'
1099 && one_range
[0] <= '9'))
1101 error ("Invalid range %s in option %s",
1103 is_enable
? "-fenable" : "-fdisable");
1107 func_name
= one_range
;
1111 new_range
= XCNEW (struct uid_range
);
1114 new_range
->start
= (unsigned) start
;
1115 new_range
->last
= (unsigned) start
;
1119 new_range
->start
= (unsigned) -1;
1120 new_range
->last
= (unsigned) -1;
1121 new_range
->assem_name
= xstrdup (func_name
);
1126 long last
= strtol (end_val
, &invalid
, 10);
1127 if (*invalid
|| last
< start
)
1129 error ("Invalid range %s in option %s",
1131 is_enable
? "-fenable" : "-fdisable");
1135 new_range
= XCNEW (struct uid_range
);
1136 new_range
->start
= (unsigned) start
;
1137 new_range
->last
= (unsigned) last
;
1140 slot
= (*tab
)[pass
->static_pass_number
];
1141 new_range
->next
= slot
;
1142 (*tab
)[pass
->static_pass_number
] = new_range
;
1145 if (new_range
->assem_name
)
1146 inform (UNKNOWN_LOCATION
,
1147 "enable pass %s for function %s",
1148 phase_name
, new_range
->assem_name
);
1150 inform (UNKNOWN_LOCATION
,
1151 "enable pass %s for functions in the range of [%u, %u]",
1152 phase_name
, new_range
->start
, new_range
->last
);
1156 if (new_range
->assem_name
)
1157 inform (UNKNOWN_LOCATION
,
1158 "disable pass %s for function %s",
1159 phase_name
, new_range
->assem_name
);
1161 inform (UNKNOWN_LOCATION
,
1162 "disable pass %s for functions in the range of [%u, %u]",
1163 phase_name
, new_range
->start
, new_range
->last
);
1166 one_range
= next_range
;
1167 } while (next_range
);
1173 /* Enable pass specified by ARG. */
1176 enable_pass (const char *arg
)
1178 enable_disable_pass (arg
, true);
1181 /* Disable pass specified by ARG. */
1184 disable_pass (const char *arg
)
1186 enable_disable_pass (arg
, false);
1189 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1192 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1194 vec
<uid_range_p
> tab
)
1196 uid_range_p slot
, range
;
1198 const char *aname
= NULL
;
1201 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1202 || pass
->static_pass_number
== -1)
1205 slot
= tab
[pass
->static_pass_number
];
1209 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1210 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1211 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1216 if ((unsigned) cgraph_uid
>= range
->start
1217 && (unsigned) cgraph_uid
<= range
->last
)
1219 if (range
->assem_name
&& aname
1220 && !strcmp (range
->assem_name
, aname
))
1222 range
= range
->next
;
1229 /* Update static_pass_number for passes (and the flag
1230 TODO_mark_first_instance).
1232 Passes are constructed with static_pass_number preinitialized to 0
1234 This field is used in two different ways: initially as instance numbers
1235 of their kind, and then as ids within the entire pass manager.
1237 Within pass_manager::pass_manager:
1239 * In add_pass_instance(), as called by next_pass_1 in
1240 NEXT_PASS in init_optimization_passes
1242 * When the initial instance of a pass within a pass manager is seen,
1243 it is flagged, and its static_pass_number is set to -1
1245 * On subsequent times that it is seen, the static pass number
1246 is decremented each time, so that if there are e.g. 4 dups,
1247 they have static_pass_number -4, 2, 3, 4 respectively (note
1248 how the initial one is negative and gives the count); these
1249 can be thought of as instance numbers of the specific pass
1251 * Within the register_dump_files () traversal, set_pass_for_id()
1252 is called on each pass, using these instance numbers to create
1253 dumpfile switches, and then overwriting them with a pass id,
1254 which are global to the whole pass manager (based on
1255 (TDI_end + current value of extra_dump_files_in_use) ) */
1258 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1259 opt_pass
*initial_pass
)
1261 /* Are we dealing with the first pass of its kind, or a clone? */
1262 if (new_pass
!= initial_pass
)
1264 /* We're dealing with a clone. */
1265 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1267 /* Indicate to register_dump_files that this pass has duplicates,
1268 and so it should rename the dump file. The first instance will
1269 be -1, and be number of duplicates = -static_pass_number - 1.
1270 Subsequent instances will be > 0 and just the duplicate number. */
1271 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1273 initial_pass
->static_pass_number
-= 1;
1274 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1279 /* We're dealing with the first pass of its kind. */
1280 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1281 new_pass
->static_pass_number
= -1;
1283 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1287 /* Add a pass to the pass list. Duplicate the pass if it's already
1291 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1293 /* Every pass should have a name so that plugins can refer to them. */
1294 gcc_assert (pass
->name
!= NULL
);
1296 add_pass_instance (pass
, false, initial_pass
);
1299 return &(*list
)->next
;
1302 /* List node for an inserted pass instance. We need to keep track of all
1303 the newly-added pass instances (with 'added_pass_nodes' defined below)
1304 so that we can register their dump files after pass-positioning is finished.
1305 Registering dumping files needs to be post-processed or the
1306 static_pass_number of the opt_pass object would be modified and mess up
1307 the dump file names of future pass instances to be added. */
1309 struct pass_list_node
1312 struct pass_list_node
*next
;
1315 static struct pass_list_node
*added_pass_nodes
= NULL
;
1316 static struct pass_list_node
*prev_added_pass_node
;
1318 /* Insert the pass at the proper position. Return true if the pass
1319 is successfully added.
1321 NEW_PASS_INFO - new pass to be inserted
1322 PASS_LIST - root of the pass list to insert the new pass to */
1325 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1327 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1328 bool success
= false;
1330 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1332 /* Check if the current pass is of the same type as the new pass and
1333 matches the name and the instance number of the reference pass. */
1334 if (pass
->type
== new_pass_info
->pass
->type
1336 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1337 && ((new_pass_info
->ref_pass_instance_number
== 0)
1338 || (new_pass_info
->ref_pass_instance_number
==
1339 pass
->static_pass_number
)
1340 || (new_pass_info
->ref_pass_instance_number
== 1
1341 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1344 struct pass_list_node
*new_pass_node
;
1346 if (new_pass_info
->ref_pass_instance_number
== 0)
1348 new_pass
= new_pass_info
->pass
->clone ();
1349 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1353 new_pass
= new_pass_info
->pass
;
1354 add_pass_instance (new_pass
, true, new_pass
);
1357 /* Insert the new pass instance based on the positioning op. */
1358 switch (new_pass_info
->pos_op
)
1360 case PASS_POS_INSERT_AFTER
:
1361 new_pass
->next
= pass
->next
;
1362 pass
->next
= new_pass
;
1364 /* Skip newly inserted pass to avoid repeated
1365 insertions in the case where the new pass and the
1366 existing one have the same name. */
1369 case PASS_POS_INSERT_BEFORE
:
1370 new_pass
->next
= pass
;
1372 prev_pass
->next
= new_pass
;
1374 *pass_list
= new_pass
;
1376 case PASS_POS_REPLACE
:
1377 new_pass
->next
= pass
->next
;
1379 prev_pass
->next
= new_pass
;
1381 *pass_list
= new_pass
;
1382 new_pass
->sub
= pass
->sub
;
1383 new_pass
->tv_id
= pass
->tv_id
;
1387 error ("invalid pass positioning operation");
1391 /* Save the newly added pass (instance) in the added_pass_nodes
1392 list so that we can register its dump file later. Note that
1393 we cannot register the dump file now because doing so will modify
1394 the static_pass_number of the opt_pass object and therefore
1395 mess up the dump file name of future instances. */
1396 new_pass_node
= XCNEW (struct pass_list_node
);
1397 new_pass_node
->pass
= new_pass
;
1398 if (!added_pass_nodes
)
1399 added_pass_nodes
= new_pass_node
;
1401 prev_added_pass_node
->next
= new_pass_node
;
1402 prev_added_pass_node
= new_pass_node
;
1407 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1414 /* Hooks a new pass into the pass lists.
1416 PASS_INFO - pass information that specifies the opt_pass object,
1417 reference pass, instance number, and how to position
1421 register_pass (struct register_pass_info
*pass_info
)
1423 g
->get_passes ()->register_pass (pass_info
);
1427 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1428 const char* ref_pass_name
, int ref_pass_inst_number
)
1430 register_pass_info i
;
1432 i
.reference_pass_name
= ref_pass_name
;
1433 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1436 g
->get_passes ()->register_pass (&i
);
1440 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1442 bool all_instances
, success
;
1443 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1445 /* The checks below could fail in buggy plugins. Existing GCC
1446 passes should never fail these checks, so we mention plugin in
1448 if (!pass_info
->pass
)
1449 fatal_error (input_location
, "plugin cannot register a missing pass");
1451 if (!pass_info
->pass
->name
)
1452 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1454 if (!pass_info
->reference_pass_name
)
1457 "plugin cannot register pass %qs without reference pass name",
1458 pass_info
->pass
->name
);
1460 /* Try to insert the new pass to the pass lists. We need to check
1461 all five lists as the reference pass could be in one (or all) of
1463 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1464 success
= position_pass (pass_info
, &all_lowering_passes
);
1465 if (!success
|| all_instances
)
1466 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1467 if (!success
|| all_instances
)
1468 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1469 if (!success
|| all_instances
)
1470 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1471 if (!success
|| all_instances
)
1472 success
|= position_pass (pass_info
, &all_passes
);
1476 "pass %qs not found but is referenced by new pass %qs",
1477 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1479 /* OK, we have successfully inserted the new pass. We need to register
1480 the dump files for the newly added pass and its duplicates (if any).
1481 Because the registration of plugin/backend passes happens after the
1482 command-line options are parsed, the options that specify single
1483 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1484 passes. Therefore we currently can only enable dumping of
1485 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1486 are specified. While doing so, we also delete the pass_list_node
1487 objects created during pass positioning. */
1488 while (added_pass_nodes
)
1490 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1491 enum tree_dump_index tdi
;
1492 register_one_dump_file (added_pass_nodes
->pass
);
1493 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1494 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1496 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1500 /* Check if dump-all flag is specified. */
1501 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1503 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1504 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1505 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1506 ->pflags
= dumps
->get_dump_file_info (tdi
)->pflags
;
1508 XDELETE (added_pass_nodes
);
1509 added_pass_nodes
= next_node
;
1513 /* Construct the pass tree. The sequencing of passes is driven by
1514 the cgraph routines:
1516 finalize_compilation_unit ()
1517 for each node N in the cgraph
1518 cgraph_analyze_function (N)
1519 cgraph_lower_function (N) -> all_lowering_passes
1521 If we are optimizing, compile is then invoked:
1524 ipa_passes () -> all_small_ipa_passes
1525 -> Analysis of all_regular_ipa_passes
1526 * possible LTO streaming at copmilation time *
1527 -> Execution of all_regular_ipa_passes
1528 * possible LTO streaming at link time *
1529 -> all_late_ipa_passes
1530 expand_all_functions ()
1531 for each node N in the cgraph
1532 expand_function (N) -> Transformation of all_regular_ipa_passes
1536 pass_manager::pass_manager (context
*ctxt
)
1537 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1538 all_regular_ipa_passes (NULL
),
1539 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1540 m_ctxt (ctxt
), m_name_to_pass_map (NULL
)
1544 /* Zero-initialize pass members. */
1545 #define INSERT_PASSES_AFTER(PASS)
1546 #define PUSH_INSERT_PASSES_WITHIN(PASS)
1547 #define POP_INSERT_PASSES()
1548 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
1549 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
1550 #define TERMINATE_PASS_LIST(PASS)
1551 #include "pass-instances.def"
1552 #undef INSERT_PASSES_AFTER
1553 #undef PUSH_INSERT_PASSES_WITHIN
1554 #undef POP_INSERT_PASSES
1556 #undef NEXT_PASS_WITH_ARG
1557 #undef TERMINATE_PASS_LIST
1559 /* Initialize the pass_lists array. */
1560 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1562 #undef DEF_PASS_LIST
1564 /* Build the tree of passes. */
1566 #define INSERT_PASSES_AFTER(PASS) \
1568 opt_pass **p_start; \
1569 p_start = p = &(PASS);
1571 #define TERMINATE_PASS_LIST(PASS) \
1572 gcc_assert (p_start == &PASS); \
1576 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1578 opt_pass **p = &(PASS ## _1)->sub;
1580 #define POP_INSERT_PASSES() \
1583 #define NEXT_PASS(PASS, NUM) \
1585 gcc_assert (NULL == PASS ## _ ## NUM); \
1587 PASS ## _1 = make_##PASS (m_ctxt); \
1590 gcc_assert (PASS ## _1); \
1591 PASS ## _ ## NUM = PASS ## _1->clone (); \
1593 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1596 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1598 NEXT_PASS (PASS, NUM); \
1599 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1602 #include "pass-instances.def"
1604 #undef INSERT_PASSES_AFTER
1605 #undef PUSH_INSERT_PASSES_WITHIN
1606 #undef POP_INSERT_PASSES
1608 #undef NEXT_PASS_WITH_ARG
1609 #undef TERMINATE_PASS_LIST
1611 /* Register the passes with the tree dump code. */
1612 register_dump_files (all_lowering_passes
);
1613 register_dump_files (all_small_ipa_passes
);
1614 register_dump_files (all_regular_ipa_passes
);
1615 register_dump_files (all_late_ipa_passes
);
1616 register_dump_files (all_passes
);
1620 delete_pass_tree (opt_pass
*pass
)
1624 /* Recurse into child passes. */
1625 delete_pass_tree (pass
->sub
);
1627 opt_pass
*next
= pass
->next
;
1629 /* Delete this pass. */
1632 /* Iterate onto sibling passes. */
1637 pass_manager::~pass_manager ()
1639 XDELETEVEC (passes_by_id
);
1641 /* Call delete_pass_tree on each of the pass_lists. */
1642 #define DEF_PASS_LIST(LIST) \
1643 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1645 #undef DEF_PASS_LIST
1649 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1650 function CALLBACK for every function in the call graph. Otherwise,
1651 call CALLBACK on the current function. */
1654 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1656 if (current_function_decl
)
1657 callback (cfun
, data
);
1660 struct cgraph_node
*node
;
1661 FOR_EACH_DEFINED_FUNCTION (node
)
1662 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1663 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1664 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1668 /* Because inlining might remove no-longer reachable nodes, we need to
1669 keep the array visible to garbage collector to avoid reading collected
1672 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1674 /* Hook called when NODE is removed and therefore should be
1675 excluded from order vector. DATA is an array of integers.
1676 DATA[0] holds max index it may be accessed by. For cgraph
1677 node DATA[node->uid + 1] holds index of this node in order
1680 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1682 int *order_idx
= (int *)data
;
1684 if (node
->uid
>= order_idx
[0])
1687 int idx
= order_idx
[node
->uid
+ 1];
1688 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1692 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1693 function CALLBACK for every function in the call graph. Otherwise,
1694 call CALLBACK on the current function.
1695 This function is global so that plugins can use it. */
1697 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1701 if (current_function_decl
)
1702 callback (cfun
, data
);
1705 cgraph_node_hook_list
*hook
;
1707 gcc_assert (!order
);
1708 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1710 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1711 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1712 order_idx
[0] = symtab
->cgraph_max_uid
;
1714 nnodes
= ipa_reverse_postorder (order
);
1715 for (i
= nnodes
- 1; i
>= 0; i
--)
1717 order
[i
]->process
= 1;
1718 order_idx
[order
[i
]->uid
+ 1] = i
;
1720 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1722 for (i
= nnodes
- 1; i
>= 0; i
--)
1724 /* Function could be inlined and removed as unreachable. */
1728 struct cgraph_node
*node
= order
[i
];
1730 /* Allow possibly removed nodes to be garbage collected. */
1733 if (node
->has_gimple_body_p ())
1735 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1737 callback (fn
, data
);
1741 symtab
->remove_cgraph_removal_hook (hook
);
1748 /* Helper function to perform function body dump. */
1751 execute_function_dump (function
*fn
, void *data
)
1753 opt_pass
*pass
= (opt_pass
*)data
;
1759 if (fn
->curr_properties
& PROP_trees
)
1760 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1762 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1764 /* Flush the file. If verification fails, we won't be able to
1765 close the file before aborting. */
1768 if ((fn
->curr_properties
& PROP_cfg
)
1769 && (dump_flags
& TDF_GRAPH
))
1771 gcc::dump_manager
*dumps
= g
->get_dumps ();
1772 struct dump_file_info
*dfi
1773 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1774 if (!dfi
->graph_dump_initialized
)
1776 clean_graph_dump_file (dump_file_name
);
1777 dfi
->graph_dump_initialized
= true;
1779 print_graph_cfg (dump_file_name
, fn
);
1786 /* This function is called when an internal compiler error is encountered.
1787 Ensure that function dump is made available before compiler is aborted. */
1790 emergency_dump_function ()
1794 enum opt_pass_type pt
= current_pass
->type
;
1795 fnotice (stderr
, "during %s pass: %s\n",
1796 pt
== GIMPLE_PASS
? "GIMPLE" : pt
== RTL_PASS
? "RTL" : "IPA",
1797 current_pass
->name
);
1798 if (!dump_file
|| !cfun
)
1800 fnotice (stderr
, "dump file: %s\n", dump_file_name
);
1801 fprintf (dump_file
, "\n\n\nEMERGENCY DUMP:\n\n");
1802 execute_function_dump (cfun
, current_pass
);
1805 static struct profile_record
*profile_record
;
1807 /* Do profile consistency book-keeping for the pass with static number INDEX.
1808 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1809 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1810 if we are only book-keeping on passes that may have selectively disabled
1811 themselves on a given function. */
1813 check_profile_consistency (int index
, int subpass
, bool run
)
1815 pass_manager
*passes
= g
->get_passes ();
1818 if (!profile_record
)
1819 profile_record
= XCNEWVEC (struct profile_record
,
1820 passes
->passes_by_id_size
);
1821 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1822 gcc_assert (subpass
< 2);
1823 profile_record
[index
].run
|= run
;
1824 account_profile_record (&profile_record
[index
], subpass
);
1827 /* Output profile consistency. */
1830 dump_profile_report (void)
1832 g
->get_passes ()->dump_profile_report ();
1836 pass_manager::dump_profile_report () const
1839 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1840 gcov_type last_time
= 0, last_size
= 0;
1841 double rel_time_change
, rel_size_change
;
1842 int last_reported
= 0;
1844 if (!profile_record
)
1846 fprintf (stderr
, "\nProfile consistency report:\n\n");
1847 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1848 fprintf (stderr
, " |freq count |freq count |size time\n");
1850 for (i
= 0; i
< passes_by_id_size
; i
++)
1851 for (j
= 0 ; j
< 2; j
++)
1852 if (profile_record
[i
].run
)
1855 rel_time_change
= (profile_record
[i
].time
[j
]
1856 - (double)last_time
) * 100 / (double)last_time
;
1858 rel_time_change
= 0;
1860 rel_size_change
= (profile_record
[i
].size
[j
]
1861 - (double)last_size
) * 100 / (double)last_size
;
1863 rel_size_change
= 0;
1865 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1866 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1867 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1868 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1869 || rel_time_change
|| rel_size_change
)
1872 fprintf (stderr
, "%-20s %s",
1873 passes_by_id
[i
]->name
,
1874 j
? "(after TODO)" : " ");
1875 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1876 fprintf (stderr
, "| %+5i",
1877 profile_record
[i
].num_mismatched_freq_in
[j
]
1880 fprintf (stderr
, "| ");
1881 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1882 fprintf (stderr
, " %+5i",
1883 profile_record
[i
].num_mismatched_count_in
[j
]
1886 fprintf (stderr
, " ");
1887 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1888 fprintf (stderr
, "| %+5i",
1889 profile_record
[i
].num_mismatched_freq_out
[j
]
1892 fprintf (stderr
, "| ");
1893 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1894 fprintf (stderr
, " %+5i",
1895 profile_record
[i
].num_mismatched_count_out
[j
]
1898 fprintf (stderr
, " ");
1900 /* Size/time units change across gimple and RTL. */
1901 if (i
== pass_expand_1
->static_pass_number
)
1902 fprintf (stderr
, "|----------");
1905 if (rel_size_change
)
1906 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1908 fprintf (stderr
, "| ");
1909 if (rel_time_change
)
1910 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1912 fprintf (stderr
, "\n");
1913 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1914 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1915 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1916 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1918 else if (j
&& last_reported
!= i
)
1921 fprintf (stderr
, "%-20s ------------| | |\n",
1922 passes_by_id
[i
]->name
);
1924 last_time
= profile_record
[i
].time
[j
];
1925 last_size
= profile_record
[i
].size
[j
];
1929 /* Perform all TODO actions that ought to be done on each function. */
1932 execute_function_todo (function
*fn
, void *data
)
1934 bool from_ipa_pass
= (cfun
== NULL
);
1935 unsigned int flags
= (size_t)data
;
1936 flags
&= ~fn
->last_verified
;
1942 /* Always cleanup the CFG before trying to update SSA. */
1943 if (flags
& TODO_cleanup_cfg
)
1945 cleanup_tree_cfg ();
1947 /* When cleanup_tree_cfg merges consecutive blocks, it may
1948 perform some simplistic propagation when removing single
1949 valued PHI nodes. This propagation may, in turn, cause the
1950 SSA form to become out-of-date (see PR 22037). So, even
1951 if the parent pass had not scheduled an SSA update, we may
1952 still need to do one. */
1953 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1954 flags
|= TODO_update_ssa
;
1957 if (flags
& TODO_update_ssa_any
)
1959 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1960 update_ssa (update_flags
);
1963 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1964 compute_may_aliases ();
1966 if (optimize
&& (flags
& TODO_update_address_taken
))
1967 execute_update_addresses_taken ();
1969 if (flags
& TODO_remove_unused_locals
)
1970 remove_unused_locals ();
1972 if (flags
& TODO_rebuild_frequencies
)
1973 rebuild_frequencies ();
1975 if (flags
& TODO_rebuild_cgraph_edges
)
1976 cgraph_edge::rebuild_edges ();
1978 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1979 /* If we've seen errors do not bother running any verifiers. */
1980 if (flag_checking
&& !seen_error ())
1982 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1983 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1985 if (flags
& TODO_verify_il
)
1987 if (cfun
->curr_properties
& PROP_trees
)
1989 if (cfun
->curr_properties
& PROP_cfg
)
1990 /* IPA passes leave stmts to be fixed up, so make sure to
1991 not verify stmts really throw. */
1992 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1994 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1996 if (cfun
->curr_properties
& PROP_ssa
)
1997 /* IPA passes leave stmts to be fixed up, so make sure to
1998 not verify SSA operands whose verifier will choke on that. */
1999 verify_ssa (true, !from_ipa_pass
);
2000 /* IPA passes leave basic-blocks unsplit, so make sure to
2001 not trip on that. */
2002 if ((cfun
->curr_properties
& PROP_cfg
)
2004 verify_flow_info ();
2006 && ! loops_state_satisfies_p (LOOPS_NEED_FIXUP
))
2008 verify_loop_structure ();
2009 if (loops_state_satisfies_p (LOOP_CLOSED_SSA
))
2010 verify_loop_closed_ssa (false);
2012 if (cfun
->curr_properties
& PROP_rtl
)
2013 verify_rtl_sharing ();
2016 /* Make sure verifiers don't change dominator state. */
2017 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
2018 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
2021 fn
->last_verified
= flags
& TODO_verify_all
;
2025 /* For IPA passes make sure to release dominator info, it can be
2026 computed by non-verifying TODOs. */
2029 free_dominance_info (fn
, CDI_DOMINATORS
);
2030 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2034 /* Perform all TODO actions. */
2036 execute_todo (unsigned int flags
)
2040 && need_ssa_update_p (cfun
))
2041 gcc_assert (flags
& TODO_update_ssa_any
);
2043 statistics_fini_pass ();
2046 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2048 /* At this point we should not have any unreachable code in the
2049 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2050 if (cfun
&& cfun
->gimple_df
)
2051 flush_ssaname_freelist ();
2053 /* Always remove functions just as before inlining: IPA passes might be
2054 interested to see bodies of extern inline functions that are not inlined
2055 to analyze side effects. The full removal is done just at the end
2056 of IPA pass queue. */
2057 if (flags
& TODO_remove_functions
)
2060 symtab
->remove_unreachable_nodes (dump_file
);
2063 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2066 symtab
->dump (dump_file
);
2067 /* Flush the file. If verification fails, we won't be able to
2068 close the file before aborting. */
2072 /* Now that the dumping has been done, we can get rid of the optional
2074 if (flags
& TODO_df_finish
)
2075 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2078 /* Verify invariants that should hold between passes. This is a place
2079 to put simple sanity checks. */
2082 verify_interpass_invariants (void)
2084 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2087 /* Clear the last verified flag. */
2090 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2092 fn
->last_verified
= 0;
2095 /* Helper function. Verify that the properties has been turn into the
2096 properties expected by the pass. */
2099 verify_curr_properties (function
*fn
, void *data
)
2101 unsigned int props
= (size_t)data
;
2102 gcc_assert ((fn
->curr_properties
& props
) == props
);
2105 /* Release dump file name if set. */
2108 release_dump_file_name (void)
2112 free (CONST_CAST (char *, dump_file_name
));
2113 dump_file_name
= NULL
;
2117 /* Initialize pass dump file. */
2118 /* This is non-static so that the plugins can use it. */
2121 pass_init_dump_file (opt_pass
*pass
)
2123 /* If a dump file name is present, open it if enabled. */
2124 if (pass
->static_pass_number
!= -1)
2126 timevar_push (TV_DUMP
);
2127 gcc::dump_manager
*dumps
= g
->get_dumps ();
2128 bool initializing_dump
=
2129 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2130 release_dump_file_name ();
2131 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2132 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2133 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2134 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2135 if (initializing_dump
2136 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2137 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2139 clean_graph_dump_file (dump_file_name
);
2140 struct dump_file_info
*dfi
2141 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2142 dfi
->graph_dump_initialized
= true;
2144 timevar_pop (TV_DUMP
);
2145 return initializing_dump
;
2151 /* Flush PASS dump file. */
2152 /* This is non-static so that plugins can use it. */
2155 pass_fini_dump_file (opt_pass
*pass
)
2157 timevar_push (TV_DUMP
);
2159 /* Flush and close dump file. */
2160 release_dump_file_name ();
2162 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2163 timevar_pop (TV_DUMP
);
2166 /* After executing the pass, apply expected changes to the function
2170 update_properties_after_pass (function
*fn
, void *data
)
2172 opt_pass
*pass
= (opt_pass
*) data
;
2173 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2174 & ~pass
->properties_destroyed
;
2177 /* Execute summary generation for all of the passes in IPA_PASS. */
2180 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2184 opt_pass
*pass
= ipa_pass
;
2186 /* Execute all of the IPA_PASSes in the list. */
2187 if (ipa_pass
->type
== IPA_PASS
2188 && pass
->gate (cfun
)
2189 && ipa_pass
->generate_summary
)
2191 pass_init_dump_file (pass
);
2193 /* If a timevar is present, start it. */
2195 timevar_push (pass
->tv_id
);
2197 current_pass
= pass
;
2198 ipa_pass
->generate_summary ();
2202 timevar_pop (pass
->tv_id
);
2204 pass_fini_dump_file (pass
);
2206 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2210 /* Execute IPA_PASS function transform on NODE. */
2213 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2214 ipa_opt_pass_d
*ipa_pass
)
2216 opt_pass
*pass
= ipa_pass
;
2217 unsigned int todo_after
= 0;
2219 current_pass
= pass
;
2220 if (!ipa_pass
->function_transform
)
2223 /* Note that the folders should only create gimple expressions.
2224 This is a hack until the new folder is ready. */
2225 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2227 pass_init_dump_file (pass
);
2229 /* If a timevar is present, start it. */
2230 if (pass
->tv_id
!= TV_NONE
)
2231 timevar_push (pass
->tv_id
);
2233 /* Run pre-pass verification. */
2234 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2237 todo_after
= ipa_pass
->function_transform (node
);
2239 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2240 check_profile_consistency (pass
->static_pass_number
, 0, true);
2242 /* Run post-pass cleanup and verification. */
2243 execute_todo (todo_after
);
2244 verify_interpass_invariants ();
2245 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2246 check_profile_consistency (pass
->static_pass_number
, 1, true);
2249 if (pass
->tv_id
!= TV_NONE
)
2250 timevar_pop (pass
->tv_id
);
2253 do_per_function (execute_function_dump
, pass
);
2254 pass_fini_dump_file (pass
);
2256 current_pass
= NULL
;
2257 redirect_edge_var_map_empty ();
2259 /* Signal this is a suitable GC collection point. */
2260 if (!(todo_after
& TODO_do_not_ggc_collect
))
2264 /* For the current function, execute all ipa transforms. */
2267 execute_all_ipa_transforms (void)
2269 struct cgraph_node
*node
;
2272 node
= cgraph_node::get (current_function_decl
);
2274 if (node
->ipa_transforms_to_apply
.exists ())
2278 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2279 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2280 node
->ipa_transforms_to_apply
.release ();
2284 /* Check if PASS is explicitly disabled or enabled and return
2285 the gate status. FUNC is the function to be processed, and
2286 GATE_STATUS is the gate status determined by pass manager by
2290 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2292 bool explicitly_enabled
= false;
2293 bool explicitly_disabled
= false;
2296 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2297 enabled_pass_uid_range_tab
);
2299 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2300 disabled_pass_uid_range_tab
);
2302 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2307 /* Determine if PASS_NAME matches CRITERION.
2308 Not a pure predicate, since it can update CRITERION, to support
2309 matching the Nth invocation of a pass.
2310 Subroutine of should_skip_pass_p. */
2313 determine_pass_name_match (const char *pass_name
, char *criterion
)
2315 size_t namelen
= strlen (pass_name
);
2316 if (! strncmp (pass_name
, criterion
, namelen
))
2318 /* The following supports starting with the Nth invocation
2319 of a pass (where N does not necessarily is equal to the
2320 dump file suffix). */
2321 if (criterion
[namelen
] == '\0'
2322 || (criterion
[namelen
] == '1'
2323 && criterion
[namelen
+ 1] == '\0'))
2327 if (criterion
[namelen
+ 1] == '\0')
2328 --criterion
[namelen
];
2336 /* For skipping passes until "startwith" pass.
2337 Return true iff PASS should be skipped.
2338 Clear cfun->pass_startwith when encountering the "startwith" pass,
2339 so that all subsequent passes are run. */
2342 should_skip_pass_p (opt_pass
*pass
)
2346 if (!cfun
->pass_startwith
)
2349 /* For __GIMPLE functions, we have to at least start when we leave
2350 SSA. Hence, we need to detect the "expand" pass, and stop skipping
2351 when we encounter it. A cheap way to identify "expand" is it to
2352 detect the destruction of PROP_ssa.
2353 For __RTL functions, we invoke "rest_of_compilation" directly, which
2354 is after "expand", and hence we don't reach this conditional. */
2355 if (pass
->properties_destroyed
& PROP_ssa
)
2358 fprintf (stderr
, "starting anyway when leaving SSA: %s\n", pass
->name
);
2359 cfun
->pass_startwith
= NULL
;
2363 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2366 fprintf (stderr
, "found starting pass: %s\n", pass
->name
);
2367 cfun
->pass_startwith
= NULL
;
2371 /* For GIMPLE passes, run any property provider (but continue skipping
2373 We don't want to force running RTL passes that are property providers:
2374 "expand" is covered above, and the only pass other than "expand" that
2375 provides a property is "into_cfglayout" (PROP_cfglayout), which does
2376 too much for a dumped __RTL function. */
2377 if (pass
->type
== GIMPLE_PASS
2378 && pass
->properties_provided
!= 0)
2381 /* Don't skip df init; later RTL passes need it. */
2382 if (strstr (pass
->name
, "dfinit") != NULL
)
2386 fprintf (stderr
, "skipping pass: %s\n", pass
->name
);
2388 /* If we get here, then we have a "startwith" that we haven't seen yet;
2393 /* Skip the given pass, for handling passes before "startwith"
2394 in __GIMPLE and__RTL-marked functions.
2395 In theory, this ought to be a no-op, but some of the RTL passes
2396 need additional processing here. */
2399 skip_pass (opt_pass
*pass
)
2401 /* Pass "reload" sets the global "reload_completed", and many
2402 things depend on this (e.g. instructions in .md files). */
2403 if (strcmp (pass
->name
, "reload") == 0)
2404 reload_completed
= 1;
2406 /* The INSN_ADDRESSES vec is normally set up by
2407 shorten_branches; set it up for the benefit of passes that
2409 if (strcmp (pass
->name
, "shorten") == 0)
2410 INSN_ADDRESSES_ALLOC (get_max_uid ());
2412 /* Update the cfg hooks as appropriate. */
2413 if (strcmp (pass
->name
, "into_cfglayout") == 0)
2415 cfg_layout_rtl_register_cfg_hooks ();
2416 cfun
->curr_properties
|= PROP_cfglayout
;
2418 if (strcmp (pass
->name
, "outof_cfglayout") == 0)
2420 rtl_register_cfg_hooks ();
2421 cfun
->curr_properties
&= ~PROP_cfglayout
;
2428 execute_one_pass (opt_pass
*pass
)
2430 unsigned int todo_after
= 0;
2434 /* IPA passes are executed on whole program, so cfun should be NULL.
2435 Other passes need function context set. */
2436 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2437 gcc_assert (!cfun
&& !current_function_decl
);
2439 gcc_assert (cfun
&& current_function_decl
);
2441 current_pass
= pass
;
2443 /* Check whether gate check should be avoided.
2444 User controls the value of the gate through the parameter "gate_status". */
2445 gate_status
= pass
->gate (cfun
);
2446 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2448 /* Override gate with plugin. */
2449 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2453 /* Run so passes selectively disabling themselves on a given function
2454 are not miscounted. */
2455 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2457 check_profile_consistency (pass
->static_pass_number
, 0, false);
2458 check_profile_consistency (pass
->static_pass_number
, 1, false);
2460 current_pass
= NULL
;
2464 if (should_skip_pass_p (pass
))
2470 /* Pass execution event trigger: useful to identify passes being
2472 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2474 if (!quiet_flag
&& !cfun
)
2475 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2477 /* Note that the folders should only create gimple expressions.
2478 This is a hack until the new folder is ready. */
2479 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2481 pass_init_dump_file (pass
);
2483 /* If a timevar is present, start it. */
2484 if (pass
->tv_id
!= TV_NONE
)
2485 timevar_push (pass
->tv_id
);
2487 /* Run pre-pass verification. */
2488 execute_todo (pass
->todo_flags_start
);
2491 do_per_function (verify_curr_properties
,
2492 (void *)(size_t)pass
->properties_required
);
2495 todo_after
= pass
->execute (cfun
);
2497 if (todo_after
& TODO_discard_function
)
2500 if (pass
->tv_id
!= TV_NONE
)
2501 timevar_pop (pass
->tv_id
);
2503 pass_fini_dump_file (pass
);
2506 /* As cgraph_node::release_body expects release dominators info,
2507 we have to release it. */
2508 if (dom_info_available_p (CDI_DOMINATORS
))
2509 free_dominance_info (CDI_DOMINATORS
);
2511 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2512 free_dominance_info (CDI_POST_DOMINATORS
);
2514 tree fn
= cfun
->decl
;
2517 cgraph_node::get (fn
)->release_body ();
2519 current_pass
= NULL
;
2520 redirect_edge_var_map_empty ();
2527 do_per_function (clear_last_verified
, NULL
);
2529 do_per_function (update_properties_after_pass
, pass
);
2531 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2532 check_profile_consistency (pass
->static_pass_number
, 0, true);
2534 /* Run post-pass cleanup and verification. */
2535 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2536 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2537 check_profile_consistency (pass
->static_pass_number
, 1, true);
2539 verify_interpass_invariants ();
2542 if (pass
->tv_id
!= TV_NONE
)
2543 timevar_pop (pass
->tv_id
);
2545 if (pass
->type
== IPA_PASS
2546 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2548 struct cgraph_node
*node
;
2549 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2550 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2553 do_per_function (execute_function_dump
, pass
);
2555 if (!current_function_decl
)
2556 symtab
->process_new_functions ();
2558 pass_fini_dump_file (pass
);
2560 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2561 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2562 || pass
->type
!= RTL_PASS
);
2564 current_pass
= NULL
;
2565 redirect_edge_var_map_empty ();
2567 /* Signal this is a suitable GC collection point. */
2568 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2575 execute_pass_list_1 (opt_pass
*pass
)
2579 gcc_assert (pass
->type
== GIMPLE_PASS
2580 || pass
->type
== RTL_PASS
);
2584 if (execute_one_pass (pass
) && pass
->sub
)
2585 execute_pass_list_1 (pass
->sub
);
2592 execute_pass_list (function
*fn
, opt_pass
*pass
)
2594 gcc_assert (fn
== cfun
);
2595 execute_pass_list_1 (pass
);
2596 if (cfun
&& fn
->cfg
)
2598 free_dominance_info (CDI_DOMINATORS
);
2599 free_dominance_info (CDI_POST_DOMINATORS
);
2603 /* Write out all LTO data. */
2607 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2609 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2610 timevar_push (TV_IPA_LTO_DECL_OUT
);
2611 produce_asm_for_decls ();
2612 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2615 /* Same as execute_pass_list but assume that subpasses of IPA passes
2616 are local passes. If SET is not NULL, write out summaries of only
2617 those node in SET. */
2620 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2624 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2625 gcc_assert (!current_function_decl
);
2627 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2628 if (pass
->type
== IPA_PASS
2629 && ipa_pass
->write_summary
2630 && pass
->gate (cfun
))
2632 /* If a timevar is present, start it. */
2634 timevar_push (pass
->tv_id
);
2636 pass_init_dump_file (pass
);
2638 current_pass
= pass
;
2639 ipa_pass
->write_summary ();
2641 pass_fini_dump_file (pass
);
2643 /* If a timevar is present, start it. */
2645 timevar_pop (pass
->tv_id
);
2648 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2649 ipa_write_summaries_2 (pass
->sub
, state
);
2655 /* Helper function of ipa_write_summaries. Creates and destroys the
2656 decl state and calls ipa_write_summaries_2 for all passes that have
2657 summaries. SET is the set of nodes to be written. */
2660 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2662 pass_manager
*passes
= g
->get_passes ();
2663 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2664 state
->symtab_node_encoder
= encoder
;
2666 lto_output_init_mode_table ();
2667 lto_push_out_decl_state (state
);
2669 gcc_assert (!flag_wpa
);
2670 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2674 gcc_assert (lto_get_out_decl_state () == state
);
2675 lto_pop_out_decl_state ();
2676 lto_delete_out_decl_state (state
);
2679 /* Write out summaries for all the nodes in the callgraph. */
2682 ipa_write_summaries (void)
2684 lto_symtab_encoder_t encoder
;
2686 varpool_node
*vnode
;
2687 struct cgraph_node
*node
;
2688 struct cgraph_node
**order
;
2690 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2693 select_what_to_stream ();
2695 encoder
= lto_symtab_encoder_new (false);
2697 /* Create the callgraph set in the same order used in
2698 cgraph_expand_all_functions. This mostly facilitates debugging,
2699 since it causes the gimple file to be processed in the same order
2700 as the source code. */
2701 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2702 order_pos
= ipa_reverse_postorder (order
);
2703 gcc_assert (order_pos
== symtab
->cgraph_count
);
2705 for (i
= order_pos
- 1; i
>= 0; i
--)
2707 struct cgraph_node
*node
= order
[i
];
2709 if (node
->has_gimple_body_p ())
2711 /* When streaming out references to statements as part of some IPA
2712 pass summary, the statements need to have uids assigned and the
2713 following does that for all the IPA passes here. Naturally, this
2714 ordering then matches the one IPA-passes get in their stmt_fixup
2717 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2718 renumber_gimple_stmt_uids ();
2721 if (node
->definition
&& node
->need_lto_streaming
)
2722 lto_set_symtab_encoder_in_partition (encoder
, node
);
2725 FOR_EACH_DEFINED_FUNCTION (node
)
2726 if (node
->alias
&& node
->need_lto_streaming
)
2727 lto_set_symtab_encoder_in_partition (encoder
, node
);
2728 FOR_EACH_DEFINED_VARIABLE (vnode
)
2729 if (vnode
->need_lto_streaming
)
2730 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2732 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2737 /* Same as execute_pass_list but assume that subpasses of IPA passes
2738 are local passes. If SET is not NULL, write out optimization summaries of
2739 only those node in SET. */
2742 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2743 struct lto_out_decl_state
*state
)
2747 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2748 gcc_assert (!current_function_decl
);
2750 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2751 if (pass
->type
== IPA_PASS
2752 && ipa_pass
->write_optimization_summary
2753 && pass
->gate (cfun
))
2755 /* If a timevar is present, start it. */
2757 timevar_push (pass
->tv_id
);
2759 pass_init_dump_file (pass
);
2761 current_pass
= pass
;
2762 ipa_pass
->write_optimization_summary ();
2764 pass_fini_dump_file (pass
);
2766 /* If a timevar is present, start it. */
2768 timevar_pop (pass
->tv_id
);
2771 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2772 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2778 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2779 NULL, write out all summaries of all nodes. */
2782 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2784 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2785 lto_symtab_encoder_iterator lsei
;
2786 state
->symtab_node_encoder
= encoder
;
2788 lto_output_init_mode_table ();
2789 lto_push_out_decl_state (state
);
2790 for (lsei
= lsei_start_function_in_partition (encoder
);
2791 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2793 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2794 /* When streaming out references to statements as part of some IPA
2795 pass summary, the statements need to have uids assigned.
2797 For functions newly born at WPA stage we need to initialize
2799 if (node
->definition
2800 && gimple_has_body_p (node
->decl
))
2802 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2803 renumber_gimple_stmt_uids ();
2808 gcc_assert (flag_wpa
);
2809 pass_manager
*passes
= g
->get_passes ();
2810 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2814 gcc_assert (lto_get_out_decl_state () == state
);
2815 lto_pop_out_decl_state ();
2816 lto_delete_out_decl_state (state
);
2819 /* Same as execute_pass_list but assume that subpasses of IPA passes
2820 are local passes. */
2823 ipa_read_summaries_1 (opt_pass
*pass
)
2827 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2829 gcc_assert (!current_function_decl
);
2831 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2833 if (pass
->gate (cfun
))
2835 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2837 /* If a timevar is present, start it. */
2839 timevar_push (pass
->tv_id
);
2841 pass_init_dump_file (pass
);
2843 current_pass
= pass
;
2844 ipa_pass
->read_summary ();
2846 pass_fini_dump_file (pass
);
2850 timevar_pop (pass
->tv_id
);
2853 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2854 ipa_read_summaries_1 (pass
->sub
);
2861 /* Read all the summaries for all_regular_ipa_passes. */
2864 ipa_read_summaries (void)
2866 pass_manager
*passes
= g
->get_passes ();
2867 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2870 /* Same as execute_pass_list but assume that subpasses of IPA passes
2871 are local passes. */
2874 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2878 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2880 gcc_assert (!current_function_decl
);
2882 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2884 if (pass
->gate (cfun
))
2886 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2888 /* If a timevar is present, start it. */
2890 timevar_push (pass
->tv_id
);
2892 pass_init_dump_file (pass
);
2894 current_pass
= pass
;
2895 ipa_pass
->read_optimization_summary ();
2897 pass_fini_dump_file (pass
);
2901 timevar_pop (pass
->tv_id
);
2904 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2905 ipa_read_optimization_summaries_1 (pass
->sub
);
2911 /* Read all the summaries for all_regular_ipa_passes. */
2914 ipa_read_optimization_summaries (void)
2916 pass_manager
*passes
= g
->get_passes ();
2917 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2920 /* Same as execute_pass_list but assume that subpasses of IPA passes
2921 are local passes. */
2923 execute_ipa_pass_list (opt_pass
*pass
)
2927 gcc_assert (!current_function_decl
);
2929 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2930 if (execute_one_pass (pass
) && pass
->sub
)
2932 if (pass
->sub
->type
== GIMPLE_PASS
)
2934 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2935 do_per_function_toporder ((void (*)(function
*, void *))
2938 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2940 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2941 || pass
->sub
->type
== IPA_PASS
)
2942 execute_ipa_pass_list (pass
->sub
);
2946 gcc_assert (!current_function_decl
);
2947 symtab
->process_new_functions ();
2953 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2956 execute_ipa_stmt_fixups (opt_pass
*pass
,
2957 struct cgraph_node
*node
, gimple
**stmts
)
2961 /* Execute all of the IPA_PASSes in the list. */
2962 if (pass
->type
== IPA_PASS
2963 && pass
->gate (cfun
))
2965 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2967 if (ipa_pass
->stmt_fixup
)
2969 pass_init_dump_file (pass
);
2970 /* If a timevar is present, start it. */
2972 timevar_push (pass
->tv_id
);
2974 current_pass
= pass
;
2975 ipa_pass
->stmt_fixup (node
, stmts
);
2979 timevar_pop (pass
->tv_id
);
2980 pass_fini_dump_file (pass
);
2983 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2989 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2992 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2994 pass_manager
*passes
= g
->get_passes ();
2995 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2999 extern void debug_properties (unsigned int);
3000 extern void dump_properties (FILE *, unsigned int);
3003 dump_properties (FILE *dump
, unsigned int props
)
3005 fprintf (dump
, "Properties:\n");
3006 if (props
& PROP_gimple_any
)
3007 fprintf (dump
, "PROP_gimple_any\n");
3008 if (props
& PROP_gimple_lcf
)
3009 fprintf (dump
, "PROP_gimple_lcf\n");
3010 if (props
& PROP_gimple_leh
)
3011 fprintf (dump
, "PROP_gimple_leh\n");
3012 if (props
& PROP_cfg
)
3013 fprintf (dump
, "PROP_cfg\n");
3014 if (props
& PROP_ssa
)
3015 fprintf (dump
, "PROP_ssa\n");
3016 if (props
& PROP_no_crit_edges
)
3017 fprintf (dump
, "PROP_no_crit_edges\n");
3018 if (props
& PROP_rtl
)
3019 fprintf (dump
, "PROP_rtl\n");
3020 if (props
& PROP_gimple_lomp
)
3021 fprintf (dump
, "PROP_gimple_lomp\n");
3022 if (props
& PROP_gimple_lomp_dev
)
3023 fprintf (dump
, "PROP_gimple_lomp_dev\n");
3024 if (props
& PROP_gimple_lcx
)
3025 fprintf (dump
, "PROP_gimple_lcx\n");
3026 if (props
& PROP_gimple_lvec
)
3027 fprintf (dump
, "PROP_gimple_lvec\n");
3028 if (props
& PROP_cfglayout
)
3029 fprintf (dump
, "PROP_cfglayout\n");
3033 debug_properties (unsigned int props
)
3035 dump_properties (stderr
, props
);
3038 /* Called by local passes to see if function is called by already processed nodes.
3039 Because we process nodes in topological order, this means that function is
3040 in recursive cycle or we introduced new direct calls. */
3042 function_called_by_processed_nodes_p (void)
3044 struct cgraph_edge
*e
;
3045 for (e
= cgraph_node::get (current_function_decl
)->callers
;
3049 if (e
->caller
->decl
== current_function_decl
)
3051 if (!e
->caller
->has_gimple_body_p ())
3053 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
3055 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
3060 fprintf (dump_file
, "Already processed call to:\n");
3061 e
->caller
->dump (dump_file
);
3066 #include "gt-passes.h"