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 */
67 /* This is used for debugging. It allows the current pass to printed
68 from anywhere in compilation.
69 The variable current_pass is also used for statistics and plugins. */
70 opt_pass
*current_pass
;
72 /* Most passes are single-instance (within their context) and thus don't
73 need to implement cloning, but passes that support multiple instances
74 *must* provide their own implementation of the clone method.
76 Handle this by providing a default implemenation, but make it a fatal
82 internal_error ("pass %s does not support cloning", name
);
86 opt_pass::set_pass_param (unsigned int, bool)
88 internal_error ("pass %s needs a set_pass_param implementation to handle the"
89 " extra argument in NEXT_PASS", name
);
93 opt_pass::gate (function
*)
99 opt_pass::execute (function
*)
104 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
108 static_pass_number (0),
115 pass_manager::execute_early_local_passes ()
117 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
118 if (flag_check_pointer_bounds
)
119 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
120 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
124 pass_manager::execute_pass_mode_switching ()
126 return pass_mode_switching_1
->execute (cfun
);
130 /* Call from anywhere to find out what pass this is. Useful for
131 printing out debugging information deep inside an service
134 print_current_pass (FILE *file
)
137 fprintf (file
, "current pass = %s (%d)\n",
138 current_pass
->name
, current_pass
->static_pass_number
);
140 fprintf (file
, "no current pass.\n");
144 /* Call from the debugger to get the current pass name. */
148 print_current_pass (stderr
);
153 /* Global variables used to communicate with passes. */
157 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
160 This does nothing for local (non-static) variables, unless the
161 variable is a register variable with DECL_ASSEMBLER_NAME set. In
162 that case, or if the variable is not an automatic, it sets up the
163 RTL and outputs any assembler code (label definition, storage
164 allocation and initialization).
166 DECL is the declaration. TOP_LEVEL is nonzero
167 if this declaration is not within a function. */
170 rest_of_decl_compilation (tree decl
,
174 bool finalize
= true;
176 /* We deferred calling assemble_alias so that we could collect
177 other attributes such as visibility. Emit the alias now. */
181 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
184 alias
= TREE_VALUE (TREE_VALUE (alias
));
185 alias
= get_identifier (TREE_STRING_POINTER (alias
));
186 /* A quirk of the initial implementation of aliases required that the
187 user add "extern" to all of them. Which is silly, but now
188 historical. Do note that the symbol is in fact locally defined. */
189 DECL_EXTERNAL (decl
) = 0;
190 TREE_STATIC (decl
) = 1;
191 assemble_alias (decl
, alias
);
196 /* Can't defer this, because it needs to happen before any
197 later function definitions are processed. */
198 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
199 make_decl_rtl (decl
);
201 /* Forward declarations for nested functions are not "external",
202 but we need to treat them as if they were. */
203 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
204 || TREE_CODE (decl
) == FUNCTION_DECL
)
206 timevar_push (TV_VARCONST
);
208 /* Don't output anything when a tentative file-scope definition
209 is seen. But at end of compilation, do output code for them.
211 We do output all variables and rely on
212 callgraph code to defer them except for forward declarations
213 (see gcc.c-torture/compile/920624-1.c) */
215 || !DECL_DEFER_OUTPUT (decl
)
216 || DECL_INITIAL (decl
))
217 && (!VAR_P (decl
) || !DECL_HAS_VALUE_EXPR_P (decl
))
218 && !DECL_EXTERNAL (decl
))
220 /* When reading LTO unit, we also read varpool, so do not
222 if (in_lto_p
&& !at_end
)
224 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
225 varpool_node::finalize_decl (decl
);
228 #ifdef ASM_FINISH_DECLARE_OBJECT
229 if (decl
== last_assemble_variable_decl
)
231 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
236 /* Now that we have activated any function-specific attributes
237 that might affect function decl, particularly align, relayout it. */
238 if (TREE_CODE (decl
) == FUNCTION_DECL
)
239 targetm
.target_option
.relayout_function (decl
);
241 timevar_pop (TV_VARCONST
);
243 else if (TREE_CODE (decl
) == TYPE_DECL
244 /* Like in rest_of_type_compilation, avoid confusing the debug
245 information machinery when there are errors. */
248 timevar_push (TV_SYMOUT
);
249 debug_hooks
->type_decl (decl
, !top_level
);
250 timevar_pop (TV_SYMOUT
);
253 /* Let cgraph know about the existence of variables. */
254 if (in_lto_p
&& !at_end
)
256 else if (VAR_P (decl
) && !DECL_EXTERNAL (decl
)
257 && TREE_STATIC (decl
))
258 varpool_node::get_create (decl
);
260 /* Generate early debug for global variables. Any local variables will
261 be handled by either handling reachable functions from
262 finalize_compilation_unit (and by consequence, locally scoped
263 symbols), or by rest_of_type_compilation below.
265 For Go's hijack of the debug_hooks to implement -fdump-go-spec, pick up
266 function prototypes. Go's debug_hooks will not forward them to the
269 && (TREE_CODE (decl
) != FUNCTION_DECL
270 /* This will pick up function prototypes with no bodies,
271 which are not visible in finalize_compilation_unit()
272 while iterating with FOR_EACH_*_FUNCTION through the
274 || (flag_dump_go_spec
!= NULL
275 && !DECL_SAVED_TREE (decl
)
276 && DECL_STRUCT_FUNCTION (decl
) == NULL
))
278 /* We need to check both decl_function_context and
279 current_function_decl here to make sure local extern
280 declarations end up with the correct context.
282 For local extern declarations, decl_function_context is
283 empty, but current_function_decl is set to the function where
284 the extern was declared . Without the check for
285 !current_function_decl below, the local extern ends up
286 incorrectly with a top-level context.
298 extern int i; // Local extern declaration.
305 && !decl_function_context (decl
)
306 && !current_function_decl
307 && DECL_SOURCE_LOCATION (decl
) != BUILTINS_LOCATION
308 && (!decl_type_context (decl
)
309 /* If we created a varpool node for the decl make sure to
310 call early_global_decl. Otherwise we miss changes
311 introduced by member definitions like
312 struct A { static int staticdatamember; };
313 int A::staticdatamember;
314 and thus have incomplete early debug and late debug
315 called from varpool node removal fails to handle it
319 && TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)))
320 /* Avoid confusing the debug information machinery when there are
323 (*debug_hooks
->early_global_decl
) (decl
);
326 /* Called after finishing a record, union or enumeral type. */
329 rest_of_type_compilation (tree type
, int toplev
)
331 /* Avoid confusing the debug information machinery when there are
336 timevar_push (TV_SYMOUT
);
337 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
338 timevar_pop (TV_SYMOUT
);
345 finish_optimization_passes (void)
348 struct dump_file_info
*dfi
;
350 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
352 timevar_push (TV_DUMP
);
353 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
355 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
357 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
362 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
363 print_combine_total_stats ();
364 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
367 /* Do whatever is necessary to finish printing the graphs. */
368 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
369 if (dfi
->graph_dump_initialized
)
371 name
= dumps
->get_dump_file_name (dfi
);
372 finish_graph_dump_file (name
);
376 timevar_pop (TV_DUMP
);
380 execute_build_ssa_passes (void)
382 /* Once this pass (and its sub-passes) are complete, all functions
383 will be in SSA form. Technically this state change is happening
384 a tad early, since the sub-passes have not yet run, but since
385 none of the sub-passes are IPA passes and do not create new
386 functions, this is ok. We're setting this value for the benefit
387 of IPA passes that follow. */
388 if (symtab
->state
< IPA_SSA
)
389 symtab
->state
= IPA_SSA
;
395 const pass_data pass_data_build_ssa_passes
=
397 SIMPLE_IPA_PASS
, /* type */
398 "build_ssa_passes", /* name */
399 OPTGROUP_NONE
, /* optinfo_flags */
400 TV_EARLY_LOCAL
, /* tv_id */
401 0, /* properties_required */
402 0, /* properties_provided */
403 0, /* properties_destroyed */
404 0, /* todo_flags_start */
405 /* todo_flags_finish is executed before subpases. For this reason
406 it makes no sense to remove unreachable functions here. */
407 0, /* todo_flags_finish */
410 class pass_build_ssa_passes
: public simple_ipa_opt_pass
413 pass_build_ssa_passes (gcc::context
*ctxt
)
414 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
417 /* opt_pass methods: */
418 virtual bool gate (function
*)
420 /* Don't bother doing anything if the program has errors. */
421 return (!seen_error () && !in_lto_p
);
424 virtual unsigned int execute (function
*)
426 return execute_build_ssa_passes ();
429 }; // class pass_build_ssa_passes
431 const pass_data pass_data_chkp_instrumentation_passes
=
433 SIMPLE_IPA_PASS
, /* type */
434 "chkp_passes", /* name */
435 OPTGROUP_NONE
, /* optinfo_flags */
437 0, /* properties_required */
438 0, /* properties_provided */
439 0, /* properties_destroyed */
440 0, /* todo_flags_start */
441 0, /* todo_flags_finish */
444 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
447 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
448 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
451 /* opt_pass methods: */
452 virtual bool gate (function
*)
454 /* Don't bother doing anything if the program has errors. */
455 return (flag_check_pointer_bounds
456 && !seen_error () && !in_lto_p
);
459 }; // class pass_chkp_instrumentation_passes
461 const pass_data pass_data_local_optimization_passes
=
463 SIMPLE_IPA_PASS
, /* type */
464 "opt_local_passes", /* name */
465 OPTGROUP_NONE
, /* optinfo_flags */
467 0, /* properties_required */
468 0, /* properties_provided */
469 0, /* properties_destroyed */
470 0, /* todo_flags_start */
471 0, /* todo_flags_finish */
474 class pass_local_optimization_passes
: public simple_ipa_opt_pass
477 pass_local_optimization_passes (gcc::context
*ctxt
)
478 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
481 /* opt_pass methods: */
482 virtual bool gate (function
*)
484 /* Don't bother doing anything if the program has errors. */
485 return (!seen_error () && !in_lto_p
);
488 }; // class pass_local_optimization_passes
492 simple_ipa_opt_pass
*
493 make_pass_build_ssa_passes (gcc::context
*ctxt
)
495 return new pass_build_ssa_passes (ctxt
);
498 simple_ipa_opt_pass
*
499 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
501 return new pass_chkp_instrumentation_passes (ctxt
);
504 simple_ipa_opt_pass
*
505 make_pass_local_optimization_passes (gcc::context
*ctxt
)
507 return new pass_local_optimization_passes (ctxt
);
512 const pass_data pass_data_all_early_optimizations
=
514 GIMPLE_PASS
, /* type */
515 "early_optimizations", /* name */
516 OPTGROUP_NONE
, /* optinfo_flags */
518 0, /* properties_required */
519 0, /* properties_provided */
520 0, /* properties_destroyed */
521 0, /* todo_flags_start */
522 0, /* todo_flags_finish */
525 class pass_all_early_optimizations
: public gimple_opt_pass
528 pass_all_early_optimizations (gcc::context
*ctxt
)
529 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
532 /* opt_pass methods: */
533 virtual bool gate (function
*)
535 return (optimize
>= 1
536 /* Don't bother doing anything if the program has errors. */
540 }; // class pass_all_early_optimizations
544 static gimple_opt_pass
*
545 make_pass_all_early_optimizations (gcc::context
*ctxt
)
547 return new pass_all_early_optimizations (ctxt
);
552 const pass_data pass_data_all_optimizations
=
554 GIMPLE_PASS
, /* type */
555 "*all_optimizations", /* name */
556 OPTGROUP_NONE
, /* optinfo_flags */
557 TV_OPTIMIZE
, /* tv_id */
558 0, /* properties_required */
559 0, /* properties_provided */
560 0, /* properties_destroyed */
561 0, /* todo_flags_start */
562 0, /* todo_flags_finish */
565 class pass_all_optimizations
: public gimple_opt_pass
568 pass_all_optimizations (gcc::context
*ctxt
)
569 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
572 /* opt_pass methods: */
573 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
575 }; // class pass_all_optimizations
579 static gimple_opt_pass
*
580 make_pass_all_optimizations (gcc::context
*ctxt
)
582 return new pass_all_optimizations (ctxt
);
587 const pass_data pass_data_all_optimizations_g
=
589 GIMPLE_PASS
, /* type */
590 "*all_optimizations_g", /* name */
591 OPTGROUP_NONE
, /* optinfo_flags */
592 TV_OPTIMIZE
, /* tv_id */
593 0, /* properties_required */
594 0, /* properties_provided */
595 0, /* properties_destroyed */
596 0, /* todo_flags_start */
597 0, /* todo_flags_finish */
600 class pass_all_optimizations_g
: public gimple_opt_pass
603 pass_all_optimizations_g (gcc::context
*ctxt
)
604 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
607 /* opt_pass methods: */
608 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
610 }; // class pass_all_optimizations_g
614 static gimple_opt_pass
*
615 make_pass_all_optimizations_g (gcc::context
*ctxt
)
617 return new pass_all_optimizations_g (ctxt
);
622 const pass_data pass_data_rest_of_compilation
=
625 "*rest_of_compilation", /* name */
626 OPTGROUP_NONE
, /* optinfo_flags */
627 TV_REST_OF_COMPILATION
, /* tv_id */
628 PROP_rtl
, /* properties_required */
629 0, /* properties_provided */
630 0, /* properties_destroyed */
631 0, /* todo_flags_start */
632 0, /* todo_flags_finish */
635 class pass_rest_of_compilation
: public rtl_opt_pass
638 pass_rest_of_compilation (gcc::context
*ctxt
)
639 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
642 /* opt_pass methods: */
643 virtual bool gate (function
*)
645 /* Early return if there were errors. We can run afoul of our
646 consistency checks, and there's not really much point in fixing them. */
647 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
650 }; // class pass_rest_of_compilation
654 static rtl_opt_pass
*
655 make_pass_rest_of_compilation (gcc::context
*ctxt
)
657 return new pass_rest_of_compilation (ctxt
);
662 const pass_data pass_data_postreload
=
665 "*all-postreload", /* name */
666 OPTGROUP_NONE
, /* optinfo_flags */
667 TV_POSTRELOAD
, /* tv_id */
668 PROP_rtl
, /* properties_required */
669 0, /* properties_provided */
670 0, /* properties_destroyed */
671 0, /* todo_flags_start */
672 0, /* todo_flags_finish */
675 class pass_postreload
: public rtl_opt_pass
678 pass_postreload (gcc::context
*ctxt
)
679 : rtl_opt_pass (pass_data_postreload
, ctxt
)
682 /* opt_pass methods: */
683 virtual bool gate (function
*) { return reload_completed
; }
685 }; // class pass_postreload
689 static rtl_opt_pass
*
690 make_pass_postreload (gcc::context
*ctxt
)
692 return new pass_postreload (ctxt
);
697 const pass_data pass_data_late_compilation
=
700 "*all-late_compilation", /* name */
701 OPTGROUP_NONE
, /* optinfo_flags */
702 TV_LATE_COMPILATION
, /* tv_id */
703 PROP_rtl
, /* properties_required */
704 0, /* properties_provided */
705 0, /* properties_destroyed */
706 0, /* todo_flags_start */
707 0, /* todo_flags_finish */
710 class pass_late_compilation
: public rtl_opt_pass
713 pass_late_compilation (gcc::context
*ctxt
)
714 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
717 /* opt_pass methods: */
718 virtual bool gate (function
*)
720 return reload_completed
|| targetm
.no_register_allocation
;
723 }; // class pass_late_compilation
727 static rtl_opt_pass
*
728 make_pass_late_compilation (gcc::context
*ctxt
)
730 return new pass_late_compilation (ctxt
);
735 /* Set the static pass number of pass PASS to ID and record that
736 in the mapping from static pass number to pass. */
740 set_pass_for_id (int id
, opt_pass
*pass
)
742 pass
->static_pass_number
= id
;
743 if (passes_by_id_size
<= id
)
745 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
746 memset (passes_by_id
+ passes_by_id_size
, 0,
747 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
748 passes_by_id_size
= id
+ 1;
750 passes_by_id
[id
] = pass
;
753 /* Return the pass with the static pass number ID. */
756 pass_manager::get_pass_for_id (int id
) const
758 if (id
>= passes_by_id_size
)
760 return passes_by_id
[id
];
763 /* Iterate over the pass tree allocating dump file numbers. We want
764 to do this depth first, and independent of whether the pass is
768 register_one_dump_file (opt_pass
*pass
)
770 g
->get_passes ()->register_one_dump_file (pass
);
774 pass_manager::register_one_dump_file (opt_pass
*pass
)
776 char *dot_name
, *flag_name
, *glob_name
;
777 const char *name
, *full_name
, *prefix
;
779 /* Buffer big enough to format a 32-bit UINT_MAX into. */
783 int optgroup_flags
= OPTGROUP_NONE
;
784 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
786 /* See below in next_pass_1. */
788 if (pass
->static_pass_number
!= -1)
789 sprintf (num
, "%u", ((int) pass
->static_pass_number
< 0
790 ? 1 : pass
->static_pass_number
));
792 /* The name is both used to identify the pass for the purposes of plugins,
793 and to specify dump file name and option.
794 The latter two might want something short which is not quite unique; for
795 that reason, we may have a disambiguating prefix, followed by a space
796 to mark the start of the following dump file name / option string. */
797 name
= strchr (pass
->name
, ' ');
798 name
= name
? name
+ 1 : pass
->name
;
799 dot_name
= concat (".", name
, num
, NULL
);
800 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
804 optgroup_flags
|= OPTGROUP_IPA
;
806 else if (pass
->type
== GIMPLE_PASS
)
817 flag_name
= concat (prefix
, name
, num
, NULL
);
818 glob_name
= concat (prefix
, name
, NULL
);
819 optgroup_flags
|= pass
->optinfo_flags
;
820 /* For any passes that do not have an optgroup set, and which are not
821 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
822 any dump messages are emitted properly under -fopt-info(-optall). */
823 if (optgroup_flags
== OPTGROUP_NONE
)
824 optgroup_flags
= OPTGROUP_OTHER
;
825 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, dkind
,
828 set_pass_for_id (id
, pass
);
829 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
830 register_pass_name (pass
, full_name
);
831 free (CONST_CAST (char *, full_name
));
834 /* Register the dump files for the pass_manager starting at PASS. */
837 pass_manager::register_dump_files (opt_pass
*pass
)
841 if (pass
->name
&& pass
->name
[0] != '*')
842 register_one_dump_file (pass
);
845 register_dump_files (pass
->sub
);
852 /* Register PASS with NAME. */
855 pass_manager::register_pass_name (opt_pass
*pass
, const char *name
)
857 if (!m_name_to_pass_map
)
858 m_name_to_pass_map
= new hash_map
<nofree_string_hash
, opt_pass
*> (256);
860 if (m_name_to_pass_map
->get (name
))
861 return; /* Ignore plugin passes. */
863 const char *unique_name
= xstrdup (name
);
864 m_name_to_pass_map
->put (unique_name
, pass
);
867 /* Map from pass id to canonicalized pass name. */
869 typedef const char *char_ptr
;
870 static vec
<char_ptr
> pass_tab
;
872 /* Callback function for traversing NAME_TO_PASS_MAP. */
875 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
877 gcc_assert (pass
->static_pass_number
> 0);
878 gcc_assert (pass_tab
.exists ());
880 pass_tab
[pass
->static_pass_number
] = name
;
885 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
886 table for dumping purpose. */
889 pass_manager::create_pass_tab (void) const
891 if (!flag_dump_passes
)
894 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
895 m_name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
898 static bool override_gate_status (opt_pass
*, tree
, bool);
900 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
901 is turned on or not. */
904 dump_one_pass (opt_pass
*pass
, int pass_indent
)
906 int indent
= 3 * pass_indent
;
908 bool is_on
, is_really_on
;
910 is_on
= pass
->gate (cfun
);
911 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
913 if (pass
->static_pass_number
<= 0)
916 pn
= pass_tab
[pass
->static_pass_number
];
918 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
919 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
920 is_on
? " ON" : " OFF",
921 ((!is_on
) == (!is_really_on
) ? ""
922 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
925 /* Dump pass list PASS with indentation INDENT. */
928 dump_pass_list (opt_pass
*pass
, int indent
)
932 dump_one_pass (pass
, indent
);
934 dump_pass_list (pass
->sub
, indent
+ 1);
940 /* Dump all optimization passes. */
945 g
->get_passes ()->dump_passes ();
949 pass_manager::dump_passes () const
951 push_dummy_function (true);
955 dump_pass_list (all_lowering_passes
, 1);
956 dump_pass_list (all_small_ipa_passes
, 1);
957 dump_pass_list (all_regular_ipa_passes
, 1);
958 dump_pass_list (all_late_ipa_passes
, 1);
959 dump_pass_list (all_passes
, 1);
961 pop_dummy_function ();
964 /* Returns the pass with NAME. */
967 pass_manager::get_pass_by_name (const char *name
)
969 opt_pass
**p
= m_name_to_pass_map
->get (name
);
977 /* Range [start, last]. */
983 const char *assem_name
;
984 struct uid_range
*next
;
987 typedef struct uid_range
*uid_range_p
;
990 static vec
<uid_range_p
> enabled_pass_uid_range_tab
;
991 static vec
<uid_range_p
> disabled_pass_uid_range_tab
;
994 /* Parse option string for -fdisable- and -fenable-
995 The syntax of the options:
998 -fdisable-<pass_name>
1000 -fenable-<pass_name>=s1:e1,s2:e2,...
1001 -fdisable-<pass_name>=s1:e1,s2:e2,...
1005 enable_disable_pass (const char *arg
, bool is_enable
)
1008 char *range_str
, *phase_name
;
1009 char *argstr
= xstrdup (arg
);
1010 vec
<uid_range_p
> *tab
= 0;
1012 range_str
= strchr (argstr
,'=');
1019 phase_name
= argstr
;
1023 error ("unrecognized option -fenable");
1025 error ("unrecognized option -fdisable");
1029 pass
= g
->get_passes ()->get_pass_by_name (phase_name
);
1030 if (!pass
|| pass
->static_pass_number
== -1)
1033 error ("unknown pass %s specified in -fenable", phase_name
);
1035 error ("unknown pass %s specified in -fdisable", phase_name
);
1041 tab
= &enabled_pass_uid_range_tab
;
1043 tab
= &disabled_pass_uid_range_tab
;
1045 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1046 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1051 uid_range_p new_range
= XCNEW (struct uid_range
);
1053 new_range
->start
= 0;
1054 new_range
->last
= (unsigned)-1;
1056 slot
= (*tab
)[pass
->static_pass_number
];
1057 new_range
->next
= slot
;
1058 (*tab
)[pass
->static_pass_number
] = new_range
;
1060 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1061 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1063 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1064 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1068 char *next_range
= NULL
;
1069 char *one_range
= range_str
;
1070 char *end_val
= NULL
;
1075 uid_range_p new_range
;
1076 char *invalid
= NULL
;
1078 char *func_name
= NULL
;
1080 next_range
= strchr (one_range
, ',');
1087 end_val
= strchr (one_range
, ':');
1093 start
= strtol (one_range
, &invalid
, 10);
1094 if (*invalid
|| start
< 0)
1096 if (end_val
|| (one_range
[0] >= '0'
1097 && one_range
[0] <= '9'))
1099 error ("Invalid range %s in option %s",
1101 is_enable
? "-fenable" : "-fdisable");
1105 func_name
= one_range
;
1109 new_range
= XCNEW (struct uid_range
);
1112 new_range
->start
= (unsigned) start
;
1113 new_range
->last
= (unsigned) start
;
1117 new_range
->start
= (unsigned) -1;
1118 new_range
->last
= (unsigned) -1;
1119 new_range
->assem_name
= xstrdup (func_name
);
1124 long last
= strtol (end_val
, &invalid
, 10);
1125 if (*invalid
|| last
< start
)
1127 error ("Invalid range %s in option %s",
1129 is_enable
? "-fenable" : "-fdisable");
1133 new_range
= XCNEW (struct uid_range
);
1134 new_range
->start
= (unsigned) start
;
1135 new_range
->last
= (unsigned) last
;
1138 slot
= (*tab
)[pass
->static_pass_number
];
1139 new_range
->next
= slot
;
1140 (*tab
)[pass
->static_pass_number
] = new_range
;
1143 if (new_range
->assem_name
)
1144 inform (UNKNOWN_LOCATION
,
1145 "enable pass %s for function %s",
1146 phase_name
, new_range
->assem_name
);
1148 inform (UNKNOWN_LOCATION
,
1149 "enable pass %s for functions in the range of [%u, %u]",
1150 phase_name
, new_range
->start
, new_range
->last
);
1154 if (new_range
->assem_name
)
1155 inform (UNKNOWN_LOCATION
,
1156 "disable pass %s for function %s",
1157 phase_name
, new_range
->assem_name
);
1159 inform (UNKNOWN_LOCATION
,
1160 "disable pass %s for functions in the range of [%u, %u]",
1161 phase_name
, new_range
->start
, new_range
->last
);
1164 one_range
= next_range
;
1165 } while (next_range
);
1171 /* Enable pass specified by ARG. */
1174 enable_pass (const char *arg
)
1176 enable_disable_pass (arg
, true);
1179 /* Disable pass specified by ARG. */
1182 disable_pass (const char *arg
)
1184 enable_disable_pass (arg
, false);
1187 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1190 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1192 vec
<uid_range_p
> tab
)
1194 uid_range_p slot
, range
;
1196 const char *aname
= NULL
;
1199 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1200 || pass
->static_pass_number
== -1)
1203 slot
= tab
[pass
->static_pass_number
];
1207 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1208 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1209 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1214 if ((unsigned) cgraph_uid
>= range
->start
1215 && (unsigned) cgraph_uid
<= range
->last
)
1217 if (range
->assem_name
&& aname
1218 && !strcmp (range
->assem_name
, aname
))
1220 range
= range
->next
;
1227 /* Update static_pass_number for passes (and the flag
1228 TODO_mark_first_instance).
1230 Passes are constructed with static_pass_number preinitialized to 0
1232 This field is used in two different ways: initially as instance numbers
1233 of their kind, and then as ids within the entire pass manager.
1235 Within pass_manager::pass_manager:
1237 * In add_pass_instance(), as called by next_pass_1 in
1238 NEXT_PASS in init_optimization_passes
1240 * When the initial instance of a pass within a pass manager is seen,
1241 it is flagged, and its static_pass_number is set to -1
1243 * On subsequent times that it is seen, the static pass number
1244 is decremented each time, so that if there are e.g. 4 dups,
1245 they have static_pass_number -4, 2, 3, 4 respectively (note
1246 how the initial one is negative and gives the count); these
1247 can be thought of as instance numbers of the specific pass
1249 * Within the register_dump_files () traversal, set_pass_for_id()
1250 is called on each pass, using these instance numbers to create
1251 dumpfile switches, and then overwriting them with a pass id,
1252 which are global to the whole pass manager (based on
1253 (TDI_end + current value of extra_dump_files_in_use) ) */
1256 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1257 opt_pass
*initial_pass
)
1259 /* Are we dealing with the first pass of its kind, or a clone? */
1260 if (new_pass
!= initial_pass
)
1262 /* We're dealing with a clone. */
1263 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1265 /* Indicate to register_dump_files that this pass has duplicates,
1266 and so it should rename the dump file. The first instance will
1267 be -1, and be number of duplicates = -static_pass_number - 1.
1268 Subsequent instances will be > 0 and just the duplicate number. */
1269 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1271 initial_pass
->static_pass_number
-= 1;
1272 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1277 /* We're dealing with the first pass of its kind. */
1278 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1279 new_pass
->static_pass_number
= -1;
1281 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1285 /* Add a pass to the pass list. Duplicate the pass if it's already
1289 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1291 /* Every pass should have a name so that plugins can refer to them. */
1292 gcc_assert (pass
->name
!= NULL
);
1294 add_pass_instance (pass
, false, initial_pass
);
1297 return &(*list
)->next
;
1300 /* List node for an inserted pass instance. We need to keep track of all
1301 the newly-added pass instances (with 'added_pass_nodes' defined below)
1302 so that we can register their dump files after pass-positioning is finished.
1303 Registering dumping files needs to be post-processed or the
1304 static_pass_number of the opt_pass object would be modified and mess up
1305 the dump file names of future pass instances to be added. */
1307 struct pass_list_node
1310 struct pass_list_node
*next
;
1313 static struct pass_list_node
*added_pass_nodes
= NULL
;
1314 static struct pass_list_node
*prev_added_pass_node
;
1316 /* Insert the pass at the proper position. Return true if the pass
1317 is successfully added.
1319 NEW_PASS_INFO - new pass to be inserted
1320 PASS_LIST - root of the pass list to insert the new pass to */
1323 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1325 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1326 bool success
= false;
1328 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1330 /* Check if the current pass is of the same type as the new pass and
1331 matches the name and the instance number of the reference pass. */
1332 if (pass
->type
== new_pass_info
->pass
->type
1334 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1335 && ((new_pass_info
->ref_pass_instance_number
== 0)
1336 || (new_pass_info
->ref_pass_instance_number
==
1337 pass
->static_pass_number
)
1338 || (new_pass_info
->ref_pass_instance_number
== 1
1339 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1342 struct pass_list_node
*new_pass_node
;
1344 if (new_pass_info
->ref_pass_instance_number
== 0)
1346 new_pass
= new_pass_info
->pass
->clone ();
1347 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1351 new_pass
= new_pass_info
->pass
;
1352 add_pass_instance (new_pass
, true, new_pass
);
1355 /* Insert the new pass instance based on the positioning op. */
1356 switch (new_pass_info
->pos_op
)
1358 case PASS_POS_INSERT_AFTER
:
1359 new_pass
->next
= pass
->next
;
1360 pass
->next
= new_pass
;
1362 /* Skip newly inserted pass to avoid repeated
1363 insertions in the case where the new pass and the
1364 existing one have the same name. */
1367 case PASS_POS_INSERT_BEFORE
:
1368 new_pass
->next
= pass
;
1370 prev_pass
->next
= new_pass
;
1372 *pass_list
= new_pass
;
1374 case PASS_POS_REPLACE
:
1375 new_pass
->next
= pass
->next
;
1377 prev_pass
->next
= new_pass
;
1379 *pass_list
= new_pass
;
1380 new_pass
->sub
= pass
->sub
;
1381 new_pass
->tv_id
= pass
->tv_id
;
1385 error ("invalid pass positioning operation");
1389 /* Save the newly added pass (instance) in the added_pass_nodes
1390 list so that we can register its dump file later. Note that
1391 we cannot register the dump file now because doing so will modify
1392 the static_pass_number of the opt_pass object and therefore
1393 mess up the dump file name of future instances. */
1394 new_pass_node
= XCNEW (struct pass_list_node
);
1395 new_pass_node
->pass
= new_pass
;
1396 if (!added_pass_nodes
)
1397 added_pass_nodes
= new_pass_node
;
1399 prev_added_pass_node
->next
= new_pass_node
;
1400 prev_added_pass_node
= new_pass_node
;
1405 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1412 /* Hooks a new pass into the pass lists.
1414 PASS_INFO - pass information that specifies the opt_pass object,
1415 reference pass, instance number, and how to position
1419 register_pass (struct register_pass_info
*pass_info
)
1421 g
->get_passes ()->register_pass (pass_info
);
1425 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1426 const char* ref_pass_name
, int ref_pass_inst_number
)
1428 register_pass_info i
;
1430 i
.reference_pass_name
= ref_pass_name
;
1431 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1434 g
->get_passes ()->register_pass (&i
);
1438 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1440 bool all_instances
, success
;
1441 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1443 /* The checks below could fail in buggy plugins. Existing GCC
1444 passes should never fail these checks, so we mention plugin in
1446 if (!pass_info
->pass
)
1447 fatal_error (input_location
, "plugin cannot register a missing pass");
1449 if (!pass_info
->pass
->name
)
1450 fatal_error (input_location
, "plugin cannot register an unnamed pass");
1452 if (!pass_info
->reference_pass_name
)
1455 "plugin cannot register pass %qs without reference pass name",
1456 pass_info
->pass
->name
);
1458 /* Try to insert the new pass to the pass lists. We need to check
1459 all five lists as the reference pass could be in one (or all) of
1461 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1462 success
= position_pass (pass_info
, &all_lowering_passes
);
1463 if (!success
|| all_instances
)
1464 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1465 if (!success
|| all_instances
)
1466 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1467 if (!success
|| all_instances
)
1468 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1469 if (!success
|| all_instances
)
1470 success
|= position_pass (pass_info
, &all_passes
);
1474 "pass %qs not found but is referenced by new pass %qs",
1475 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1477 /* OK, we have successfully inserted the new pass. We need to register
1478 the dump files for the newly added pass and its duplicates (if any).
1479 Because the registration of plugin/backend passes happens after the
1480 command-line options are parsed, the options that specify single
1481 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1482 passes. Therefore we currently can only enable dumping of
1483 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1484 are specified. While doing so, we also delete the pass_list_node
1485 objects created during pass positioning. */
1486 while (added_pass_nodes
)
1488 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1489 enum tree_dump_index tdi
;
1490 register_one_dump_file (added_pass_nodes
->pass
);
1491 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1492 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1494 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1498 /* Check if dump-all flag is specified. */
1499 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1501 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1502 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1503 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1504 ->pflags
= dumps
->get_dump_file_info (tdi
)->pflags
;
1506 XDELETE (added_pass_nodes
);
1507 added_pass_nodes
= next_node
;
1511 /* Construct the pass tree. The sequencing of passes is driven by
1512 the cgraph routines:
1514 finalize_compilation_unit ()
1515 for each node N in the cgraph
1516 cgraph_analyze_function (N)
1517 cgraph_lower_function (N) -> all_lowering_passes
1519 If we are optimizing, compile is then invoked:
1522 ipa_passes () -> all_small_ipa_passes
1523 -> Analysis of all_regular_ipa_passes
1524 * possible LTO streaming at copmilation time *
1525 -> Execution of all_regular_ipa_passes
1526 * possible LTO streaming at link time *
1527 -> all_late_ipa_passes
1528 expand_all_functions ()
1529 for each node N in the cgraph
1530 expand_function (N) -> Transformation of all_regular_ipa_passes
1534 pass_manager::pass_manager (context
*ctxt
)
1535 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1536 all_regular_ipa_passes (NULL
),
1537 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1538 m_ctxt (ctxt
), m_name_to_pass_map (NULL
)
1542 /* Zero-initialize pass members. */
1543 #define INSERT_PASSES_AFTER(PASS)
1544 #define PUSH_INSERT_PASSES_WITHIN(PASS)
1545 #define POP_INSERT_PASSES()
1546 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
1547 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
1548 #define TERMINATE_PASS_LIST(PASS)
1549 #include "pass-instances.def"
1550 #undef INSERT_PASSES_AFTER
1551 #undef PUSH_INSERT_PASSES_WITHIN
1552 #undef POP_INSERT_PASSES
1554 #undef NEXT_PASS_WITH_ARG
1555 #undef TERMINATE_PASS_LIST
1557 /* Initialize the pass_lists array. */
1558 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1560 #undef DEF_PASS_LIST
1562 /* Build the tree of passes. */
1564 #define INSERT_PASSES_AFTER(PASS) \
1566 opt_pass **p_start; \
1567 p_start = p = &(PASS);
1569 #define TERMINATE_PASS_LIST(PASS) \
1570 gcc_assert (p_start == &PASS); \
1574 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1576 opt_pass **p = &(PASS ## _1)->sub;
1578 #define POP_INSERT_PASSES() \
1581 #define NEXT_PASS(PASS, NUM) \
1583 gcc_assert (NULL == PASS ## _ ## NUM); \
1585 PASS ## _1 = make_##PASS (m_ctxt); \
1588 gcc_assert (PASS ## _1); \
1589 PASS ## _ ## NUM = PASS ## _1->clone (); \
1591 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1594 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) \
1596 NEXT_PASS (PASS, NUM); \
1597 PASS ## _ ## NUM->set_pass_param (0, ARG); \
1600 #include "pass-instances.def"
1602 #undef INSERT_PASSES_AFTER
1603 #undef PUSH_INSERT_PASSES_WITHIN
1604 #undef POP_INSERT_PASSES
1606 #undef NEXT_PASS_WITH_ARG
1607 #undef TERMINATE_PASS_LIST
1609 /* Register the passes with the tree dump code. */
1610 register_dump_files (all_lowering_passes
);
1611 register_dump_files (all_small_ipa_passes
);
1612 register_dump_files (all_regular_ipa_passes
);
1613 register_dump_files (all_late_ipa_passes
);
1614 register_dump_files (all_passes
);
1618 delete_pass_tree (opt_pass
*pass
)
1622 /* Recurse into child passes. */
1623 delete_pass_tree (pass
->sub
);
1625 opt_pass
*next
= pass
->next
;
1627 /* Delete this pass. */
1630 /* Iterate onto sibling passes. */
1635 pass_manager::~pass_manager ()
1637 XDELETEVEC (passes_by_id
);
1639 /* Call delete_pass_tree on each of the pass_lists. */
1640 #define DEF_PASS_LIST(LIST) \
1641 delete_pass_tree (*pass_lists[PASS_LIST_NO_##LIST]);
1643 #undef DEF_PASS_LIST
1647 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1648 function CALLBACK for every function in the call graph. Otherwise,
1649 call CALLBACK on the current function. */
1652 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1654 if (current_function_decl
)
1655 callback (cfun
, data
);
1658 struct cgraph_node
*node
;
1659 FOR_EACH_DEFINED_FUNCTION (node
)
1660 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1661 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1662 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1666 /* Because inlining might remove no-longer reachable nodes, we need to
1667 keep the array visible to garbage collector to avoid reading collected
1670 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1672 /* Hook called when NODE is removed and therefore should be
1673 excluded from order vector. DATA is an array of integers.
1674 DATA[0] holds max index it may be accessed by. For cgraph
1675 node DATA[node->uid + 1] holds index of this node in order
1678 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1680 int *order_idx
= (int *)data
;
1682 if (node
->uid
>= order_idx
[0])
1685 int idx
= order_idx
[node
->uid
+ 1];
1686 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1690 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1691 function CALLBACK for every function in the call graph. Otherwise,
1692 call CALLBACK on the current function.
1693 This function is global so that plugins can use it. */
1695 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1699 if (current_function_decl
)
1700 callback (cfun
, data
);
1703 cgraph_node_hook_list
*hook
;
1705 gcc_assert (!order
);
1706 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1708 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1709 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1710 order_idx
[0] = symtab
->cgraph_max_uid
;
1712 nnodes
= ipa_reverse_postorder (order
);
1713 for (i
= nnodes
- 1; i
>= 0; i
--)
1715 order
[i
]->process
= 1;
1716 order_idx
[order
[i
]->uid
+ 1] = i
;
1718 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1720 for (i
= nnodes
- 1; i
>= 0; i
--)
1722 /* Function could be inlined and removed as unreachable. */
1726 struct cgraph_node
*node
= order
[i
];
1728 /* Allow possibly removed nodes to be garbage collected. */
1731 if (node
->has_gimple_body_p ())
1733 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1735 callback (fn
, data
);
1739 symtab
->remove_cgraph_removal_hook (hook
);
1746 /* Helper function to perform function body dump. */
1749 execute_function_dump (function
*fn
, void *data
)
1751 opt_pass
*pass
= (opt_pass
*)data
;
1757 if (fn
->curr_properties
& PROP_trees
)
1758 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1760 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1762 /* Flush the file. If verification fails, we won't be able to
1763 close the file before aborting. */
1766 if ((fn
->curr_properties
& PROP_cfg
)
1767 && (dump_flags
& TDF_GRAPH
))
1769 gcc::dump_manager
*dumps
= g
->get_dumps ();
1770 struct dump_file_info
*dfi
1771 = dumps
->get_dump_file_info (pass
->static_pass_number
);
1772 if (!dfi
->graph_dump_initialized
)
1774 clean_graph_dump_file (dump_file_name
);
1775 dfi
->graph_dump_initialized
= true;
1777 print_graph_cfg (dump_file_name
, fn
);
1784 /* This function is called when an internal compiler error is encountered.
1785 Ensure that function dump is made available before compiler is aborted. */
1788 emergency_dump_function ()
1792 enum opt_pass_type pt
= current_pass
->type
;
1793 fnotice (stderr
, "during %s pass: %s\n",
1794 pt
== GIMPLE_PASS
? "GIMPLE" : pt
== RTL_PASS
? "RTL" : "IPA",
1795 current_pass
->name
);
1796 if (!dump_file
|| !cfun
)
1798 fnotice (stderr
, "dump file: %s\n", dump_file_name
);
1799 fprintf (dump_file
, "\n\n\nEMERGENCY DUMP:\n\n");
1800 execute_function_dump (cfun
, current_pass
);
1803 static struct profile_record
*profile_record
;
1805 /* Do profile consistency book-keeping for the pass with static number INDEX.
1806 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1807 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1808 if we are only book-keeping on passes that may have selectively disabled
1809 themselves on a given function. */
1811 check_profile_consistency (int index
, int subpass
, bool run
)
1813 pass_manager
*passes
= g
->get_passes ();
1816 if (!profile_record
)
1817 profile_record
= XCNEWVEC (struct profile_record
,
1818 passes
->passes_by_id_size
);
1819 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1820 gcc_assert (subpass
< 2);
1821 profile_record
[index
].run
|= run
;
1822 account_profile_record (&profile_record
[index
], subpass
);
1825 /* Output profile consistency. */
1828 dump_profile_report (void)
1830 g
->get_passes ()->dump_profile_report ();
1834 pass_manager::dump_profile_report () const
1837 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1838 gcov_type last_time
= 0, last_size
= 0;
1839 double rel_time_change
, rel_size_change
;
1840 int last_reported
= 0;
1842 if (!profile_record
)
1844 fprintf (stderr
, "\nProfile consistency report:\n\n");
1845 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1846 fprintf (stderr
, " |freq count |freq count |size time\n");
1848 for (i
= 0; i
< passes_by_id_size
; i
++)
1849 for (j
= 0 ; j
< 2; j
++)
1850 if (profile_record
[i
].run
)
1853 rel_time_change
= (profile_record
[i
].time
[j
]
1854 - (double)last_time
) * 100 / (double)last_time
;
1856 rel_time_change
= 0;
1858 rel_size_change
= (profile_record
[i
].size
[j
]
1859 - (double)last_size
) * 100 / (double)last_size
;
1861 rel_size_change
= 0;
1863 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1864 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1865 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1866 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1867 || rel_time_change
|| rel_size_change
)
1870 fprintf (stderr
, "%-20s %s",
1871 passes_by_id
[i
]->name
,
1872 j
? "(after TODO)" : " ");
1873 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1874 fprintf (stderr
, "| %+5i",
1875 profile_record
[i
].num_mismatched_freq_in
[j
]
1878 fprintf (stderr
, "| ");
1879 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1880 fprintf (stderr
, " %+5i",
1881 profile_record
[i
].num_mismatched_count_in
[j
]
1884 fprintf (stderr
, " ");
1885 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1886 fprintf (stderr
, "| %+5i",
1887 profile_record
[i
].num_mismatched_freq_out
[j
]
1890 fprintf (stderr
, "| ");
1891 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1892 fprintf (stderr
, " %+5i",
1893 profile_record
[i
].num_mismatched_count_out
[j
]
1896 fprintf (stderr
, " ");
1898 /* Size/time units change across gimple and RTL. */
1899 if (i
== pass_expand_1
->static_pass_number
)
1900 fprintf (stderr
, "|----------");
1903 if (rel_size_change
)
1904 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1906 fprintf (stderr
, "| ");
1907 if (rel_time_change
)
1908 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1910 fprintf (stderr
, "\n");
1911 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1912 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1913 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1914 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1916 else if (j
&& last_reported
!= i
)
1919 fprintf (stderr
, "%-20s ------------| | |\n",
1920 passes_by_id
[i
]->name
);
1922 last_time
= profile_record
[i
].time
[j
];
1923 last_size
= profile_record
[i
].size
[j
];
1927 /* Perform all TODO actions that ought to be done on each function. */
1930 execute_function_todo (function
*fn
, void *data
)
1932 bool from_ipa_pass
= (cfun
== NULL
);
1933 unsigned int flags
= (size_t)data
;
1934 flags
&= ~fn
->last_verified
;
1940 /* Always cleanup the CFG before trying to update SSA. */
1941 if (flags
& TODO_cleanup_cfg
)
1943 cleanup_tree_cfg ();
1945 /* When cleanup_tree_cfg merges consecutive blocks, it may
1946 perform some simplistic propagation when removing single
1947 valued PHI nodes. This propagation may, in turn, cause the
1948 SSA form to become out-of-date (see PR 22037). So, even
1949 if the parent pass had not scheduled an SSA update, we may
1950 still need to do one. */
1951 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1952 flags
|= TODO_update_ssa
;
1955 if (flags
& TODO_update_ssa_any
)
1957 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1958 update_ssa (update_flags
);
1961 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1962 compute_may_aliases ();
1964 if (optimize
&& (flags
& TODO_update_address_taken
))
1965 execute_update_addresses_taken ();
1967 if (flags
& TODO_remove_unused_locals
)
1968 remove_unused_locals ();
1970 if (flags
& TODO_rebuild_frequencies
)
1971 rebuild_frequencies ();
1973 if (flags
& TODO_rebuild_cgraph_edges
)
1974 cgraph_edge::rebuild_edges ();
1976 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == DOM_NONE
);
1977 /* If we've seen errors do not bother running any verifiers. */
1978 if (flag_checking
&& !seen_error ())
1980 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1981 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1983 if (flags
& TODO_verify_il
)
1985 if (cfun
->curr_properties
& PROP_trees
)
1987 if (cfun
->curr_properties
& PROP_cfg
)
1988 /* IPA passes leave stmts to be fixed up, so make sure to
1989 not verify stmts really throw. */
1990 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1992 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1994 if (cfun
->curr_properties
& PROP_ssa
)
1995 /* IPA passes leave stmts to be fixed up, so make sure to
1996 not verify SSA operands whose verifier will choke on that. */
1997 verify_ssa (true, !from_ipa_pass
);
1998 /* IPA passes leave basic-blocks unsplit, so make sure to
1999 not trip on that. */
2000 if ((cfun
->curr_properties
& PROP_cfg
)
2002 verify_flow_info ();
2004 && ! loops_state_satisfies_p (LOOPS_NEED_FIXUP
))
2006 verify_loop_structure ();
2007 if (loops_state_satisfies_p (LOOP_CLOSED_SSA
))
2008 verify_loop_closed_ssa (false);
2010 if (cfun
->curr_properties
& PROP_rtl
)
2011 verify_rtl_sharing ();
2014 /* Make sure verifiers don't change dominator state. */
2015 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
2016 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
2019 fn
->last_verified
= flags
& TODO_verify_all
;
2023 /* For IPA passes make sure to release dominator info, it can be
2024 computed by non-verifying TODOs. */
2027 free_dominance_info (fn
, CDI_DOMINATORS
);
2028 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
2032 /* Perform all TODO actions. */
2034 execute_todo (unsigned int flags
)
2038 && need_ssa_update_p (cfun
))
2039 gcc_assert (flags
& TODO_update_ssa_any
);
2041 statistics_fini_pass ();
2044 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2046 /* At this point we should not have any unreachable code in the
2047 CFG, so it is safe to flush the pending freelist for SSA_NAMES. */
2048 if (cfun
&& cfun
->gimple_df
)
2049 flush_ssaname_freelist ();
2051 /* Always remove functions just as before inlining: IPA passes might be
2052 interested to see bodies of extern inline functions that are not inlined
2053 to analyze side effects. The full removal is done just at the end
2054 of IPA pass queue. */
2055 if (flags
& TODO_remove_functions
)
2058 symtab
->remove_unreachable_nodes (dump_file
);
2061 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2064 symtab
->dump (dump_file
);
2065 /* Flush the file. If verification fails, we won't be able to
2066 close the file before aborting. */
2070 /* Now that the dumping has been done, we can get rid of the optional
2072 if (flags
& TODO_df_finish
)
2073 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2076 /* Verify invariants that should hold between passes. This is a place
2077 to put simple sanity checks. */
2080 verify_interpass_invariants (void)
2082 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2085 /* Clear the last verified flag. */
2088 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2090 fn
->last_verified
= 0;
2093 /* Helper function. Verify that the properties has been turn into the
2094 properties expected by the pass. */
2097 verify_curr_properties (function
*fn
, void *data
)
2099 unsigned int props
= (size_t)data
;
2100 gcc_assert ((fn
->curr_properties
& props
) == props
);
2103 /* Release dump file name if set. */
2106 release_dump_file_name (void)
2110 free (CONST_CAST (char *, dump_file_name
));
2111 dump_file_name
= NULL
;
2115 /* Initialize pass dump file. */
2116 /* This is non-static so that the plugins can use it. */
2119 pass_init_dump_file (opt_pass
*pass
)
2121 /* If a dump file name is present, open it if enabled. */
2122 if (pass
->static_pass_number
!= -1)
2124 timevar_push (TV_DUMP
);
2125 gcc::dump_manager
*dumps
= g
->get_dumps ();
2126 bool initializing_dump
=
2127 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2128 release_dump_file_name ();
2129 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2130 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2131 if (dump_file
&& current_function_decl
&& ! (dump_flags
& TDF_GIMPLE
))
2132 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2133 if (initializing_dump
2134 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2135 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2137 clean_graph_dump_file (dump_file_name
);
2138 struct dump_file_info
*dfi
2139 = dumps
->get_dump_file_info (pass
->static_pass_number
);
2140 dfi
->graph_dump_initialized
= true;
2142 timevar_pop (TV_DUMP
);
2143 return initializing_dump
;
2149 /* Flush PASS dump file. */
2150 /* This is non-static so that plugins can use it. */
2153 pass_fini_dump_file (opt_pass
*pass
)
2155 timevar_push (TV_DUMP
);
2157 /* Flush and close dump file. */
2158 release_dump_file_name ();
2160 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2161 timevar_pop (TV_DUMP
);
2164 /* After executing the pass, apply expected changes to the function
2168 update_properties_after_pass (function
*fn
, void *data
)
2170 opt_pass
*pass
= (opt_pass
*) data
;
2171 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2172 & ~pass
->properties_destroyed
;
2175 /* Execute summary generation for all of the passes in IPA_PASS. */
2178 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2182 opt_pass
*pass
= ipa_pass
;
2184 /* Execute all of the IPA_PASSes in the list. */
2185 if (ipa_pass
->type
== IPA_PASS
2186 && pass
->gate (cfun
)
2187 && ipa_pass
->generate_summary
)
2189 pass_init_dump_file (pass
);
2191 /* If a timevar is present, start it. */
2193 timevar_push (pass
->tv_id
);
2195 current_pass
= pass
;
2196 ipa_pass
->generate_summary ();
2200 timevar_pop (pass
->tv_id
);
2202 pass_fini_dump_file (pass
);
2204 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2208 /* Execute IPA_PASS function transform on NODE. */
2211 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2212 ipa_opt_pass_d
*ipa_pass
)
2214 opt_pass
*pass
= ipa_pass
;
2215 unsigned int todo_after
= 0;
2217 current_pass
= pass
;
2218 if (!ipa_pass
->function_transform
)
2221 /* Note that the folders should only create gimple expressions.
2222 This is a hack until the new folder is ready. */
2223 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2225 pass_init_dump_file (pass
);
2227 /* If a timevar is present, start it. */
2228 if (pass
->tv_id
!= TV_NONE
)
2229 timevar_push (pass
->tv_id
);
2231 /* Run pre-pass verification. */
2232 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2235 todo_after
= ipa_pass
->function_transform (node
);
2237 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2238 check_profile_consistency (pass
->static_pass_number
, 0, true);
2240 /* Run post-pass cleanup and verification. */
2241 execute_todo (todo_after
);
2242 verify_interpass_invariants ();
2243 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2244 check_profile_consistency (pass
->static_pass_number
, 1, true);
2247 if (pass
->tv_id
!= TV_NONE
)
2248 timevar_pop (pass
->tv_id
);
2251 do_per_function (execute_function_dump
, pass
);
2252 pass_fini_dump_file (pass
);
2254 current_pass
= NULL
;
2255 redirect_edge_var_map_empty ();
2257 /* Signal this is a suitable GC collection point. */
2258 if (!(todo_after
& TODO_do_not_ggc_collect
))
2262 /* For the current function, execute all ipa transforms. */
2265 execute_all_ipa_transforms (void)
2267 struct cgraph_node
*node
;
2270 node
= cgraph_node::get (current_function_decl
);
2272 if (node
->ipa_transforms_to_apply
.exists ())
2276 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2277 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2278 node
->ipa_transforms_to_apply
.release ();
2282 /* Check if PASS is explicitly disabled or enabled and return
2283 the gate status. FUNC is the function to be processed, and
2284 GATE_STATUS is the gate status determined by pass manager by
2288 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2290 bool explicitly_enabled
= false;
2291 bool explicitly_disabled
= false;
2294 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2295 enabled_pass_uid_range_tab
);
2297 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2298 disabled_pass_uid_range_tab
);
2300 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2305 /* Determine if PASS_NAME matches CRITERION.
2306 Not a pure predicate, since it can update CRITERION, to support
2307 matching the Nth invocation of a pass.
2308 Subroutine of should_skip_pass_p. */
2311 determine_pass_name_match (const char *pass_name
, char *criterion
)
2313 size_t namelen
= strlen (pass_name
);
2314 if (! strncmp (pass_name
, criterion
, namelen
))
2316 /* The following supports starting with the Nth invocation
2317 of a pass (where N does not necessarily is equal to the
2318 dump file suffix). */
2319 if (criterion
[namelen
] == '\0'
2320 || (criterion
[namelen
] == '1'
2321 && criterion
[namelen
+ 1] == '\0'))
2325 if (criterion
[namelen
+ 1] == '\0')
2326 --criterion
[namelen
];
2334 /* For skipping passes until "startwith" pass.
2335 Return true iff PASS should be skipped.
2336 Clear cfun->pass_startwith when encountering the "startwith" pass,
2337 so that all subsequent passes are run. */
2340 should_skip_pass_p (opt_pass
*pass
)
2344 if (!cfun
->pass_startwith
)
2347 /* For __GIMPLE functions, we have to at least start when we leave
2348 SSA. Hence, we need to detect the "expand" pass, and stop skipping
2349 when we encounter it. A cheap way to identify "expand" is it to
2350 detect the destruction of PROP_ssa.
2351 For __RTL functions, we invoke "rest_of_compilation" directly, which
2352 is after "expand", and hence we don't reach this conditional. */
2353 if (pass
->properties_destroyed
& PROP_ssa
)
2356 fprintf (stderr
, "starting anyway when leaving SSA: %s\n", pass
->name
);
2357 cfun
->pass_startwith
= NULL
;
2361 if (determine_pass_name_match (pass
->name
, cfun
->pass_startwith
))
2364 fprintf (stderr
, "found starting pass: %s\n", pass
->name
);
2365 cfun
->pass_startwith
= NULL
;
2369 /* For GIMPLE passes, run any property provider (but continue skipping
2371 We don't want to force running RTL passes that are property providers:
2372 "expand" is covered above, and the only pass other than "expand" that
2373 provides a property is "into_cfglayout" (PROP_cfglayout), which does
2374 too much for a dumped __RTL function. */
2375 if (pass
->type
== GIMPLE_PASS
2376 && pass
->properties_provided
!= 0)
2379 /* Don't skip df init; later RTL passes need it. */
2380 if (strstr (pass
->name
, "dfinit") != NULL
)
2384 fprintf (stderr
, "skipping pass: %s\n", pass
->name
);
2386 /* If we get here, then we have a "startwith" that we haven't seen yet;
2391 /* Skip the given pass, for handling passes before "startwith"
2392 in __GIMPLE and__RTL-marked functions.
2393 In theory, this ought to be a no-op, but some of the RTL passes
2394 need additional processing here. */
2397 skip_pass (opt_pass
*pass
)
2399 /* Pass "reload" sets the global "reload_completed", and many
2400 things depend on this (e.g. instructions in .md files). */
2401 if (strcmp (pass
->name
, "reload") == 0)
2402 reload_completed
= 1;
2404 /* The INSN_ADDRESSES vec is normally set up by
2405 shorten_branches; set it up for the benefit of passes that
2407 if (strcmp (pass
->name
, "shorten") == 0)
2408 INSN_ADDRESSES_ALLOC (get_max_uid ());
2410 /* Update the cfg hooks as appropriate. */
2411 if (strcmp (pass
->name
, "into_cfglayout") == 0)
2413 cfg_layout_rtl_register_cfg_hooks ();
2414 cfun
->curr_properties
|= PROP_cfglayout
;
2416 if (strcmp (pass
->name
, "outof_cfglayout") == 0)
2418 rtl_register_cfg_hooks ();
2419 cfun
->curr_properties
&= ~PROP_cfglayout
;
2426 execute_one_pass (opt_pass
*pass
)
2428 unsigned int todo_after
= 0;
2432 /* IPA passes are executed on whole program, so cfun should be NULL.
2433 Other passes need function context set. */
2434 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2435 gcc_assert (!cfun
&& !current_function_decl
);
2437 gcc_assert (cfun
&& current_function_decl
);
2439 current_pass
= pass
;
2441 /* Check whether gate check should be avoided.
2442 User controls the value of the gate through the parameter "gate_status". */
2443 gate_status
= pass
->gate (cfun
);
2444 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2446 /* Override gate with plugin. */
2447 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2451 /* Run so passes selectively disabling themselves on a given function
2452 are not miscounted. */
2453 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2455 check_profile_consistency (pass
->static_pass_number
, 0, false);
2456 check_profile_consistency (pass
->static_pass_number
, 1, false);
2458 current_pass
= NULL
;
2462 if (should_skip_pass_p (pass
))
2468 /* Pass execution event trigger: useful to identify passes being
2470 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2472 if (!quiet_flag
&& !cfun
)
2473 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2475 /* Note that the folders should only create gimple expressions.
2476 This is a hack until the new folder is ready. */
2477 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2479 pass_init_dump_file (pass
);
2481 /* If a timevar is present, start it. */
2482 if (pass
->tv_id
!= TV_NONE
)
2483 timevar_push (pass
->tv_id
);
2485 /* Run pre-pass verification. */
2486 execute_todo (pass
->todo_flags_start
);
2489 do_per_function (verify_curr_properties
,
2490 (void *)(size_t)pass
->properties_required
);
2493 todo_after
= pass
->execute (cfun
);
2495 if (todo_after
& TODO_discard_function
)
2498 if (pass
->tv_id
!= TV_NONE
)
2499 timevar_pop (pass
->tv_id
);
2501 pass_fini_dump_file (pass
);
2504 /* As cgraph_node::release_body expects release dominators info,
2505 we have to release it. */
2506 if (dom_info_available_p (CDI_DOMINATORS
))
2507 free_dominance_info (CDI_DOMINATORS
);
2509 if (dom_info_available_p (CDI_POST_DOMINATORS
))
2510 free_dominance_info (CDI_POST_DOMINATORS
);
2512 tree fn
= cfun
->decl
;
2515 cgraph_node::get (fn
)->release_body ();
2517 current_pass
= NULL
;
2518 redirect_edge_var_map_empty ();
2525 do_per_function (clear_last_verified
, NULL
);
2527 do_per_function (update_properties_after_pass
, pass
);
2529 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2530 check_profile_consistency (pass
->static_pass_number
, 0, true);
2532 /* Run post-pass cleanup and verification. */
2533 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2534 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2535 check_profile_consistency (pass
->static_pass_number
, 1, true);
2537 verify_interpass_invariants ();
2540 if (pass
->tv_id
!= TV_NONE
)
2541 timevar_pop (pass
->tv_id
);
2543 if (pass
->type
== IPA_PASS
2544 && ((ipa_opt_pass_d
*)pass
)->function_transform
)
2546 struct cgraph_node
*node
;
2547 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2548 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2551 do_per_function (execute_function_dump
, pass
);
2553 if (!current_function_decl
)
2554 symtab
->process_new_functions ();
2556 pass_fini_dump_file (pass
);
2558 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2559 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2560 || pass
->type
!= RTL_PASS
);
2562 current_pass
= NULL
;
2563 redirect_edge_var_map_empty ();
2565 /* Signal this is a suitable GC collection point. */
2566 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2573 execute_pass_list_1 (opt_pass
*pass
)
2577 gcc_assert (pass
->type
== GIMPLE_PASS
2578 || pass
->type
== RTL_PASS
);
2582 if (execute_one_pass (pass
) && pass
->sub
)
2583 execute_pass_list_1 (pass
->sub
);
2590 execute_pass_list (function
*fn
, opt_pass
*pass
)
2592 gcc_assert (fn
== cfun
);
2593 execute_pass_list_1 (pass
);
2594 if (cfun
&& fn
->cfg
)
2596 free_dominance_info (CDI_DOMINATORS
);
2597 free_dominance_info (CDI_POST_DOMINATORS
);
2601 /* Write out all LTO data. */
2605 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2607 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2608 timevar_push (TV_IPA_LTO_DECL_OUT
);
2609 produce_asm_for_decls ();
2610 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2613 /* Same as execute_pass_list but assume that subpasses of IPA passes
2614 are local passes. If SET is not NULL, write out summaries of only
2615 those node in SET. */
2618 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2622 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2623 gcc_assert (!current_function_decl
);
2625 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2626 if (pass
->type
== IPA_PASS
2627 && ipa_pass
->write_summary
2628 && pass
->gate (cfun
))
2630 /* If a timevar is present, start it. */
2632 timevar_push (pass
->tv_id
);
2634 pass_init_dump_file (pass
);
2636 current_pass
= pass
;
2637 ipa_pass
->write_summary ();
2639 pass_fini_dump_file (pass
);
2641 /* If a timevar is present, start it. */
2643 timevar_pop (pass
->tv_id
);
2646 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2647 ipa_write_summaries_2 (pass
->sub
, state
);
2653 /* Helper function of ipa_write_summaries. Creates and destroys the
2654 decl state and calls ipa_write_summaries_2 for all passes that have
2655 summaries. SET is the set of nodes to be written. */
2658 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2660 pass_manager
*passes
= g
->get_passes ();
2661 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2662 state
->symtab_node_encoder
= encoder
;
2664 lto_output_init_mode_table ();
2665 lto_push_out_decl_state (state
);
2667 gcc_assert (!flag_wpa
);
2668 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2672 gcc_assert (lto_get_out_decl_state () == state
);
2673 lto_pop_out_decl_state ();
2674 lto_delete_out_decl_state (state
);
2677 /* Write out summaries for all the nodes in the callgraph. */
2680 ipa_write_summaries (void)
2682 lto_symtab_encoder_t encoder
;
2684 varpool_node
*vnode
;
2685 struct cgraph_node
*node
;
2686 struct cgraph_node
**order
;
2688 if ((!flag_generate_lto
&& !flag_generate_offload
) || seen_error ())
2691 select_what_to_stream ();
2693 encoder
= lto_symtab_encoder_new (false);
2695 /* Create the callgraph set in the same order used in
2696 cgraph_expand_all_functions. This mostly facilitates debugging,
2697 since it causes the gimple file to be processed in the same order
2698 as the source code. */
2699 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2700 order_pos
= ipa_reverse_postorder (order
);
2701 gcc_assert (order_pos
== symtab
->cgraph_count
);
2703 for (i
= order_pos
- 1; i
>= 0; i
--)
2705 struct cgraph_node
*node
= order
[i
];
2707 if (node
->has_gimple_body_p ())
2709 /* When streaming out references to statements as part of some IPA
2710 pass summary, the statements need to have uids assigned and the
2711 following does that for all the IPA passes here. Naturally, this
2712 ordering then matches the one IPA-passes get in their stmt_fixup
2715 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2716 renumber_gimple_stmt_uids ();
2719 if (node
->definition
&& node
->need_lto_streaming
)
2720 lto_set_symtab_encoder_in_partition (encoder
, node
);
2723 FOR_EACH_DEFINED_FUNCTION (node
)
2724 if (node
->alias
&& node
->need_lto_streaming
)
2725 lto_set_symtab_encoder_in_partition (encoder
, node
);
2726 FOR_EACH_DEFINED_VARIABLE (vnode
)
2727 if (vnode
->need_lto_streaming
)
2728 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2730 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2735 /* Same as execute_pass_list but assume that subpasses of IPA passes
2736 are local passes. If SET is not NULL, write out optimization summaries of
2737 only those node in SET. */
2740 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2741 struct lto_out_decl_state
*state
)
2745 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2746 gcc_assert (!current_function_decl
);
2748 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2749 if (pass
->type
== IPA_PASS
2750 && ipa_pass
->write_optimization_summary
2751 && pass
->gate (cfun
))
2753 /* If a timevar is present, start it. */
2755 timevar_push (pass
->tv_id
);
2757 pass_init_dump_file (pass
);
2759 current_pass
= pass
;
2760 ipa_pass
->write_optimization_summary ();
2762 pass_fini_dump_file (pass
);
2764 /* If a timevar is present, start it. */
2766 timevar_pop (pass
->tv_id
);
2769 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2770 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2776 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2777 NULL, write out all summaries of all nodes. */
2780 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2782 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2783 lto_symtab_encoder_iterator lsei
;
2784 state
->symtab_node_encoder
= encoder
;
2786 lto_output_init_mode_table ();
2787 lto_push_out_decl_state (state
);
2788 for (lsei
= lsei_start_function_in_partition (encoder
);
2789 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2791 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2792 /* When streaming out references to statements as part of some IPA
2793 pass summary, the statements need to have uids assigned.
2795 For functions newly born at WPA stage we need to initialize
2797 if (node
->definition
2798 && gimple_has_body_p (node
->decl
))
2800 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2801 renumber_gimple_stmt_uids ();
2806 gcc_assert (flag_wpa
);
2807 pass_manager
*passes
= g
->get_passes ();
2808 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2812 gcc_assert (lto_get_out_decl_state () == state
);
2813 lto_pop_out_decl_state ();
2814 lto_delete_out_decl_state (state
);
2817 /* Same as execute_pass_list but assume that subpasses of IPA passes
2818 are local passes. */
2821 ipa_read_summaries_1 (opt_pass
*pass
)
2825 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2827 gcc_assert (!current_function_decl
);
2829 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2831 if (pass
->gate (cfun
))
2833 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2835 /* If a timevar is present, start it. */
2837 timevar_push (pass
->tv_id
);
2839 pass_init_dump_file (pass
);
2841 current_pass
= pass
;
2842 ipa_pass
->read_summary ();
2844 pass_fini_dump_file (pass
);
2848 timevar_pop (pass
->tv_id
);
2851 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2852 ipa_read_summaries_1 (pass
->sub
);
2859 /* Read all the summaries for all_regular_ipa_passes. */
2862 ipa_read_summaries (void)
2864 pass_manager
*passes
= g
->get_passes ();
2865 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2868 /* Same as execute_pass_list but assume that subpasses of IPA passes
2869 are local passes. */
2872 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2876 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2878 gcc_assert (!current_function_decl
);
2880 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2882 if (pass
->gate (cfun
))
2884 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2886 /* If a timevar is present, start it. */
2888 timevar_push (pass
->tv_id
);
2890 pass_init_dump_file (pass
);
2892 current_pass
= pass
;
2893 ipa_pass
->read_optimization_summary ();
2895 pass_fini_dump_file (pass
);
2899 timevar_pop (pass
->tv_id
);
2902 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2903 ipa_read_optimization_summaries_1 (pass
->sub
);
2909 /* Read all the summaries for all_regular_ipa_passes. */
2912 ipa_read_optimization_summaries (void)
2914 pass_manager
*passes
= g
->get_passes ();
2915 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2918 /* Same as execute_pass_list but assume that subpasses of IPA passes
2919 are local passes. */
2921 execute_ipa_pass_list (opt_pass
*pass
)
2925 gcc_assert (!current_function_decl
);
2927 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2928 if (execute_one_pass (pass
) && pass
->sub
)
2930 if (pass
->sub
->type
== GIMPLE_PASS
)
2932 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2933 do_per_function_toporder ((void (*)(function
*, void *))
2936 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2938 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2939 || pass
->sub
->type
== IPA_PASS
)
2940 execute_ipa_pass_list (pass
->sub
);
2944 gcc_assert (!current_function_decl
);
2945 symtab
->process_new_functions ();
2951 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2954 execute_ipa_stmt_fixups (opt_pass
*pass
,
2955 struct cgraph_node
*node
, gimple
**stmts
)
2959 /* Execute all of the IPA_PASSes in the list. */
2960 if (pass
->type
== IPA_PASS
2961 && pass
->gate (cfun
))
2963 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2965 if (ipa_pass
->stmt_fixup
)
2967 pass_init_dump_file (pass
);
2968 /* If a timevar is present, start it. */
2970 timevar_push (pass
->tv_id
);
2972 current_pass
= pass
;
2973 ipa_pass
->stmt_fixup (node
, stmts
);
2977 timevar_pop (pass
->tv_id
);
2978 pass_fini_dump_file (pass
);
2981 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2987 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2990 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
**stmts
)
2992 pass_manager
*passes
= g
->get_passes ();
2993 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2997 extern void debug_properties (unsigned int);
2998 extern void dump_properties (FILE *, unsigned int);
3001 dump_properties (FILE *dump
, unsigned int props
)
3003 fprintf (dump
, "Properties:\n");
3004 if (props
& PROP_gimple_any
)
3005 fprintf (dump
, "PROP_gimple_any\n");
3006 if (props
& PROP_gimple_lcf
)
3007 fprintf (dump
, "PROP_gimple_lcf\n");
3008 if (props
& PROP_gimple_leh
)
3009 fprintf (dump
, "PROP_gimple_leh\n");
3010 if (props
& PROP_cfg
)
3011 fprintf (dump
, "PROP_cfg\n");
3012 if (props
& PROP_ssa
)
3013 fprintf (dump
, "PROP_ssa\n");
3014 if (props
& PROP_no_crit_edges
)
3015 fprintf (dump
, "PROP_no_crit_edges\n");
3016 if (props
& PROP_rtl
)
3017 fprintf (dump
, "PROP_rtl\n");
3018 if (props
& PROP_gimple_lomp
)
3019 fprintf (dump
, "PROP_gimple_lomp\n");
3020 if (props
& PROP_gimple_lomp_dev
)
3021 fprintf (dump
, "PROP_gimple_lomp_dev\n");
3022 if (props
& PROP_gimple_lcx
)
3023 fprintf (dump
, "PROP_gimple_lcx\n");
3024 if (props
& PROP_gimple_lvec
)
3025 fprintf (dump
, "PROP_gimple_lvec\n");
3026 if (props
& PROP_cfglayout
)
3027 fprintf (dump
, "PROP_cfglayout\n");
3031 debug_properties (unsigned int props
)
3033 dump_properties (stderr
, props
);
3036 /* Called by local passes to see if function is called by already processed nodes.
3037 Because we process nodes in topological order, this means that function is
3038 in recursive cycle or we introduced new direct calls. */
3040 function_called_by_processed_nodes_p (void)
3042 struct cgraph_edge
*e
;
3043 for (e
= cgraph_node::get (current_function_decl
)->callers
;
3047 if (e
->caller
->decl
== current_function_decl
)
3049 if (!e
->caller
->has_gimple_body_p ())
3051 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
3053 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
3058 fprintf (dump_file
, "Already processed call to:\n");
3059 e
->caller
->dump (dump_file
);
3064 #include "gt-passes.h"