1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2014 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"
36 #include "insn-attr.h"
37 #include "insn-config.h"
38 #include "insn-flags.h"
39 #include "hard-reg-set.h"
51 #include "basic-block.h"
55 #include "diagnostic-core.h"
60 #include "langhooks.h"
62 #include "hosthooks.h"
65 #include "value-prof.h"
66 #include "tree-inline.h"
67 #include "tree-ssa-alias.h"
68 #include "internal-fn.h"
69 #include "gimple-expr.h"
72 #include "gimple-ssa.h"
74 #include "stringpool.h"
75 #include "tree-ssanames.h"
76 #include "tree-ssa-loop-manip.h"
77 #include "tree-into-ssa.h"
80 #include "tree-pass.h"
81 #include "tree-dump.h"
84 #include "plugin-api.h"
87 #include "lto-streamer.h"
89 #include "ipa-utils.h"
90 #include "tree-pretty-print.h" /* for dump_function_header */
92 #include "pass_manager.h"
93 #include "tree-ssa-live.h" /* For remove_unused_locals. */
94 #include "tree-cfgcleanup.h"
98 /* This is used for debugging. It allows the current pass to printed
99 from anywhere in compilation.
100 The variable current_pass is also used for statistics and plugins. */
101 opt_pass
*current_pass
;
103 static void register_pass_name (opt_pass
*, const char *);
105 /* Most passes are single-instance (within their context) and thus don't
106 need to implement cloning, but passes that support multiple instances
107 *must* provide their own implementation of the clone method.
109 Handle this by providing a default implemenation, but make it a fatal
115 internal_error ("pass %s does not support cloning", name
);
119 opt_pass::gate (function
*)
125 opt_pass::execute (function
*)
130 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
134 static_pass_number (0),
141 pass_manager::execute_early_local_passes ()
143 execute_pass_list (cfun
, pass_build_ssa_passes_1
->sub
);
144 execute_pass_list (cfun
, pass_chkp_instrumentation_passes_1
->sub
);
145 execute_pass_list (cfun
, pass_local_optimization_passes_1
->sub
);
149 pass_manager::execute_pass_mode_switching ()
151 return pass_mode_switching_1
->execute (cfun
);
155 /* Call from anywhere to find out what pass this is. Useful for
156 printing out debugging information deep inside an service
159 print_current_pass (FILE *file
)
162 fprintf (file
, "current pass = %s (%d)\n",
163 current_pass
->name
, current_pass
->static_pass_number
);
165 fprintf (file
, "no current pass.\n");
169 /* Call from the debugger to get the current pass name. */
173 print_current_pass (stderr
);
178 /* Global variables used to communicate with passes. */
180 bool first_pass_instance
;
183 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
186 This does nothing for local (non-static) variables, unless the
187 variable is a register variable with DECL_ASSEMBLER_NAME set. In
188 that case, or if the variable is not an automatic, it sets up the
189 RTL and outputs any assembler code (label definition, storage
190 allocation and initialization).
192 DECL is the declaration. TOP_LEVEL is nonzero
193 if this declaration is not within a function. */
196 rest_of_decl_compilation (tree decl
,
200 bool finalize
= true;
202 /* We deferred calling assemble_alias so that we could collect
203 other attributes such as visibility. Emit the alias now. */
207 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
210 alias
= TREE_VALUE (TREE_VALUE (alias
));
211 alias
= get_identifier (TREE_STRING_POINTER (alias
));
212 /* A quirk of the initial implementation of aliases required that the
213 user add "extern" to all of them. Which is silly, but now
214 historical. Do note that the symbol is in fact locally defined. */
215 DECL_EXTERNAL (decl
) = 0;
216 TREE_STATIC (decl
) = 1;
217 assemble_alias (decl
, alias
);
222 /* Can't defer this, because it needs to happen before any
223 later function definitions are processed. */
224 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
225 make_decl_rtl (decl
);
227 /* Forward declarations for nested functions are not "external",
228 but we need to treat them as if they were. */
229 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
230 || TREE_CODE (decl
) == FUNCTION_DECL
)
232 timevar_push (TV_VARCONST
);
234 /* Don't output anything when a tentative file-scope definition
235 is seen. But at end of compilation, do output code for them.
237 We do output all variables and rely on
238 callgraph code to defer them except for forward declarations
239 (see gcc.c-torture/compile/920624-1.c) */
241 || !DECL_DEFER_OUTPUT (decl
)
242 || DECL_INITIAL (decl
))
243 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
244 && !DECL_EXTERNAL (decl
))
246 /* When reading LTO unit, we also read varpool, so do not
248 if (in_lto_p
&& !at_end
)
250 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
251 varpool_node::finalize_decl (decl
);
254 #ifdef ASM_FINISH_DECLARE_OBJECT
255 if (decl
== last_assemble_variable_decl
)
257 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
262 timevar_pop (TV_VARCONST
);
264 else if (TREE_CODE (decl
) == TYPE_DECL
265 /* Like in rest_of_type_compilation, avoid confusing the debug
266 information machinery when there are errors. */
269 timevar_push (TV_SYMOUT
);
270 debug_hooks
->type_decl (decl
, !top_level
);
271 timevar_pop (TV_SYMOUT
);
274 /* Let cgraph know about the existence of variables. */
275 if (in_lto_p
&& !at_end
)
277 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
278 && TREE_STATIC (decl
))
279 varpool_node::get_create (decl
);
282 /* Called after finishing a record, union or enumeral type. */
285 rest_of_type_compilation (tree type
, int toplev
)
287 /* Avoid confusing the debug information machinery when there are
292 timevar_push (TV_SYMOUT
);
293 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
294 timevar_pop (TV_SYMOUT
);
301 finish_optimization_passes (void)
304 struct dump_file_info
*dfi
;
306 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
308 timevar_push (TV_DUMP
);
309 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
311 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
313 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
318 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
319 print_combine_total_stats ();
320 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
323 /* Do whatever is necessary to finish printing the graphs. */
324 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
325 if (dumps
->dump_initialized_p (i
)
326 && (dfi
->pflags
& TDF_GRAPH
) != 0
327 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
329 finish_graph_dump_file (name
);
333 timevar_pop (TV_DUMP
);
337 execute_build_ssa_passes (void)
339 /* Once this pass (and its sub-passes) are complete, all functions
340 will be in SSA form. Technically this state change is happening
341 a tad early, since the sub-passes have not yet run, but since
342 none of the sub-passes are IPA passes and do not create new
343 functions, this is ok. We're setting this value for the benefit
344 of IPA passes that follow. */
345 if (symtab
->state
< IPA_SSA
)
346 symtab
->state
= IPA_SSA
;
352 const pass_data pass_data_build_ssa_passes
=
354 SIMPLE_IPA_PASS
, /* type */
355 "build_ssa_passes", /* name */
356 OPTGROUP_NONE
, /* optinfo_flags */
357 TV_EARLY_LOCAL
, /* tv_id */
358 0, /* properties_required */
359 0, /* properties_provided */
360 0, /* properties_destroyed */
361 0, /* todo_flags_start */
362 /* todo_flags_finish is executed before subpases. For this reason
363 it makes no sense to remove unreachable functions here. */
364 0, /* todo_flags_finish */
367 class pass_build_ssa_passes
: public simple_ipa_opt_pass
370 pass_build_ssa_passes (gcc::context
*ctxt
)
371 : simple_ipa_opt_pass (pass_data_build_ssa_passes
, ctxt
)
374 /* opt_pass methods: */
375 virtual bool gate (function
*)
377 /* Don't bother doing anything if the program has errors. */
378 return (!seen_error () && !in_lto_p
);
381 virtual unsigned int execute (function
*)
383 return execute_build_ssa_passes ();
386 }; // class pass_build_ssa_passes
388 const pass_data pass_data_chkp_instrumentation_passes
=
390 SIMPLE_IPA_PASS
, /* type */
391 "chkp_passes", /* name */
392 OPTGROUP_NONE
, /* optinfo_flags */
394 0, /* properties_required */
395 0, /* properties_provided */
396 0, /* properties_destroyed */
397 0, /* todo_flags_start */
398 0, /* todo_flags_finish */
401 class pass_chkp_instrumentation_passes
: public simple_ipa_opt_pass
404 pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
405 : simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes
, ctxt
)
408 /* opt_pass methods: */
409 virtual bool gate (function
*)
411 /* Don't bother doing anything if the program has errors. */
412 return (!seen_error () && !in_lto_p
);
415 }; // class pass_chkp_instrumentation_passes
417 const pass_data pass_data_local_optimization_passes
=
419 SIMPLE_IPA_PASS
, /* type */
420 "opt_local_passes", /* name */
421 OPTGROUP_NONE
, /* optinfo_flags */
423 0, /* properties_required */
424 0, /* properties_provided */
425 0, /* properties_destroyed */
426 0, /* todo_flags_start */
427 0, /* todo_flags_finish */
430 class pass_local_optimization_passes
: public simple_ipa_opt_pass
433 pass_local_optimization_passes (gcc::context
*ctxt
)
434 : simple_ipa_opt_pass (pass_data_local_optimization_passes
, ctxt
)
437 /* opt_pass methods: */
438 virtual bool gate (function
*)
440 /* Don't bother doing anything if the program has errors. */
441 return (!seen_error () && !in_lto_p
);
444 }; // class pass_local_optimization_passes
448 simple_ipa_opt_pass
*
449 make_pass_build_ssa_passes (gcc::context
*ctxt
)
451 return new pass_build_ssa_passes (ctxt
);
454 simple_ipa_opt_pass
*
455 make_pass_chkp_instrumentation_passes (gcc::context
*ctxt
)
457 return new pass_chkp_instrumentation_passes (ctxt
);
460 simple_ipa_opt_pass
*
461 make_pass_local_optimization_passes (gcc::context
*ctxt
)
463 return new pass_local_optimization_passes (ctxt
);
468 const pass_data pass_data_all_early_optimizations
=
470 GIMPLE_PASS
, /* type */
471 "early_optimizations", /* name */
472 OPTGROUP_NONE
, /* optinfo_flags */
474 0, /* properties_required */
475 0, /* properties_provided */
476 0, /* properties_destroyed */
477 0, /* todo_flags_start */
478 0, /* todo_flags_finish */
481 class pass_all_early_optimizations
: public gimple_opt_pass
484 pass_all_early_optimizations (gcc::context
*ctxt
)
485 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
488 /* opt_pass methods: */
489 virtual bool gate (function
*)
491 return (optimize
>= 1
492 /* Don't bother doing anything if the program has errors. */
496 }; // class pass_all_early_optimizations
500 static gimple_opt_pass
*
501 make_pass_all_early_optimizations (gcc::context
*ctxt
)
503 return new pass_all_early_optimizations (ctxt
);
508 const pass_data pass_data_all_optimizations
=
510 GIMPLE_PASS
, /* type */
511 "*all_optimizations", /* name */
512 OPTGROUP_NONE
, /* optinfo_flags */
513 TV_OPTIMIZE
, /* tv_id */
514 0, /* properties_required */
515 0, /* properties_provided */
516 0, /* properties_destroyed */
517 0, /* todo_flags_start */
518 0, /* todo_flags_finish */
521 class pass_all_optimizations
: public gimple_opt_pass
524 pass_all_optimizations (gcc::context
*ctxt
)
525 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
528 /* opt_pass methods: */
529 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
531 }; // class pass_all_optimizations
535 static gimple_opt_pass
*
536 make_pass_all_optimizations (gcc::context
*ctxt
)
538 return new pass_all_optimizations (ctxt
);
543 const pass_data pass_data_all_optimizations_g
=
545 GIMPLE_PASS
, /* type */
546 "*all_optimizations_g", /* name */
547 OPTGROUP_NONE
, /* optinfo_flags */
548 TV_OPTIMIZE
, /* tv_id */
549 0, /* properties_required */
550 0, /* properties_provided */
551 0, /* properties_destroyed */
552 0, /* todo_flags_start */
553 0, /* todo_flags_finish */
556 class pass_all_optimizations_g
: public gimple_opt_pass
559 pass_all_optimizations_g (gcc::context
*ctxt
)
560 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
563 /* opt_pass methods: */
564 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
566 }; // class pass_all_optimizations_g
570 static gimple_opt_pass
*
571 make_pass_all_optimizations_g (gcc::context
*ctxt
)
573 return new pass_all_optimizations_g (ctxt
);
578 const pass_data pass_data_rest_of_compilation
=
581 "*rest_of_compilation", /* name */
582 OPTGROUP_NONE
, /* optinfo_flags */
583 TV_REST_OF_COMPILATION
, /* tv_id */
584 PROP_rtl
, /* properties_required */
585 0, /* properties_provided */
586 0, /* properties_destroyed */
587 0, /* todo_flags_start */
588 0, /* todo_flags_finish */
591 class pass_rest_of_compilation
: public rtl_opt_pass
594 pass_rest_of_compilation (gcc::context
*ctxt
)
595 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
598 /* opt_pass methods: */
599 virtual bool gate (function
*)
601 /* Early return if there were errors. We can run afoul of our
602 consistency checks, and there's not really much point in fixing them. */
603 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
606 }; // class pass_rest_of_compilation
610 static rtl_opt_pass
*
611 make_pass_rest_of_compilation (gcc::context
*ctxt
)
613 return new pass_rest_of_compilation (ctxt
);
618 const pass_data pass_data_postreload
=
621 "*all-postreload", /* name */
622 OPTGROUP_NONE
, /* optinfo_flags */
623 TV_POSTRELOAD
, /* tv_id */
624 PROP_rtl
, /* properties_required */
625 0, /* properties_provided */
626 0, /* properties_destroyed */
627 0, /* todo_flags_start */
628 0, /* todo_flags_finish */
631 class pass_postreload
: public rtl_opt_pass
634 pass_postreload (gcc::context
*ctxt
)
635 : rtl_opt_pass (pass_data_postreload
, ctxt
)
638 /* opt_pass methods: */
639 virtual bool gate (function
*) { return reload_completed
; }
641 }; // class pass_postreload
645 static rtl_opt_pass
*
646 make_pass_postreload (gcc::context
*ctxt
)
648 return new pass_postreload (ctxt
);
653 const pass_data pass_data_late_compilation
=
656 "*all-late_compilation", /* name */
657 OPTGROUP_NONE
, /* optinfo_flags */
658 TV_LATE_COMPILATION
, /* tv_id */
659 PROP_rtl
, /* properties_required */
660 0, /* properties_provided */
661 0, /* properties_destroyed */
662 0, /* todo_flags_start */
663 0, /* todo_flags_finish */
666 class pass_late_compilation
: public rtl_opt_pass
669 pass_late_compilation (gcc::context
*ctxt
)
670 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
673 /* opt_pass methods: */
674 virtual bool gate (function
*)
676 return reload_completed
|| targetm
.no_register_allocation
;
679 }; // class pass_late_compilation
683 static rtl_opt_pass
*
684 make_pass_late_compilation (gcc::context
*ctxt
)
686 return new pass_late_compilation (ctxt
);
691 /* Set the static pass number of pass PASS to ID and record that
692 in the mapping from static pass number to pass. */
696 set_pass_for_id (int id
, opt_pass
*pass
)
698 pass
->static_pass_number
= id
;
699 if (passes_by_id_size
<= id
)
701 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
702 memset (passes_by_id
+ passes_by_id_size
, 0,
703 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
704 passes_by_id_size
= id
+ 1;
706 passes_by_id
[id
] = pass
;
709 /* Return the pass with the static pass number ID. */
712 pass_manager::get_pass_for_id (int id
) const
714 if (id
>= passes_by_id_size
)
716 return passes_by_id
[id
];
719 /* Iterate over the pass tree allocating dump file numbers. We want
720 to do this depth first, and independent of whether the pass is
724 register_one_dump_file (opt_pass
*pass
)
726 g
->get_passes ()->register_one_dump_file (pass
);
730 pass_manager::register_one_dump_file (opt_pass
*pass
)
732 char *dot_name
, *flag_name
, *glob_name
;
733 const char *name
, *full_name
, *prefix
;
736 int optgroup_flags
= OPTGROUP_NONE
;
737 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
739 /* See below in next_pass_1. */
741 if (pass
->static_pass_number
!= -1)
742 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
743 ? 1 : pass
->static_pass_number
));
745 /* The name is both used to identify the pass for the purposes of plugins,
746 and to specify dump file name and option.
747 The latter two might want something short which is not quite unique; for
748 that reason, we may have a disambiguating prefix, followed by a space
749 to mark the start of the following dump file name / option string. */
750 name
= strchr (pass
->name
, ' ');
751 name
= name
? name
+ 1 : pass
->name
;
752 dot_name
= concat (".", name
, num
, NULL
);
753 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
757 optgroup_flags
|= OPTGROUP_IPA
;
759 else if (pass
->type
== GIMPLE_PASS
)
770 flag_name
= concat (prefix
, name
, num
, NULL
);
771 glob_name
= concat (prefix
, name
, NULL
);
772 optgroup_flags
|= pass
->optinfo_flags
;
773 /* For any passes that do not have an optgroup set, and which are not
774 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
775 any dump messages are emitted properly under -fopt-info(-optall). */
776 if (optgroup_flags
== OPTGROUP_NONE
)
777 optgroup_flags
= OPTGROUP_OTHER
;
778 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
780 set_pass_for_id (id
, pass
);
781 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
782 register_pass_name (pass
, full_name
);
783 free (CONST_CAST (char *, full_name
));
786 /* Register the dump files for the pass_manager starting at PASS. */
789 pass_manager::register_dump_files (opt_pass
*pass
)
793 if (pass
->name
&& pass
->name
[0] != '*')
794 register_one_dump_file (pass
);
797 register_dump_files (pass
->sub
);
804 /* Helper for pass_registry hash table. */
806 struct pass_registry_hasher
: default_hashmap_traits
808 static inline hashval_t
hash (const char *);
809 static inline bool equal_keys (const char *, const char *);
812 /* Pass registry hash function. */
815 pass_registry_hasher::hash (const char *name
)
817 return htab_hash_string (name
);
820 /* Hash equal function */
823 pass_registry_hasher::equal_keys (const char *s1
, const char *s2
)
825 return !strcmp (s1
, s2
);
828 static hash_map
<const char *, opt_pass
*, pass_registry_hasher
>
831 /* Register PASS with NAME. */
834 register_pass_name (opt_pass
*pass
, const char *name
)
836 if (!name_to_pass_map
)
838 = new hash_map
<const char *, opt_pass
*, pass_registry_hasher
> (256);
840 if (name_to_pass_map
->get (name
))
841 return; /* Ignore plugin passes. */
843 const char *unique_name
= xstrdup (name
);
844 name_to_pass_map
->put (unique_name
, pass
);
847 /* Map from pass id to canonicalized pass name. */
849 typedef const char *char_ptr
;
850 static vec
<char_ptr
> pass_tab
= vNULL
;
852 /* Callback function for traversing NAME_TO_PASS_MAP. */
855 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
857 gcc_assert (pass
->static_pass_number
> 0);
858 gcc_assert (pass_tab
.exists ());
860 pass_tab
[pass
->static_pass_number
] = name
;
865 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
866 table for dumping purpose. */
869 create_pass_tab (void)
871 if (!flag_dump_passes
)
874 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
875 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
878 static bool override_gate_status (opt_pass
*, tree
, bool);
880 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
881 is turned on or not. */
884 dump_one_pass (opt_pass
*pass
, int pass_indent
)
886 int indent
= 3 * pass_indent
;
888 bool is_on
, is_really_on
;
890 is_on
= pass
->gate (cfun
);
891 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
893 if (pass
->static_pass_number
<= 0)
896 pn
= pass_tab
[pass
->static_pass_number
];
898 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
899 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
900 is_on
? " ON" : " OFF",
901 ((!is_on
) == (!is_really_on
) ? ""
902 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
905 /* Dump pass list PASS with indentation INDENT. */
908 dump_pass_list (opt_pass
*pass
, int indent
)
912 dump_one_pass (pass
, indent
);
914 dump_pass_list (pass
->sub
, indent
+ 1);
920 /* Dump all optimization passes. */
925 g
->get_passes ()->dump_passes ();
929 pass_manager::dump_passes () const
931 struct cgraph_node
*n
, *node
= NULL
;
935 FOR_EACH_FUNCTION (n
)
936 if (DECL_STRUCT_FUNCTION (n
->decl
))
945 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
947 dump_pass_list (all_lowering_passes
, 1);
948 dump_pass_list (all_small_ipa_passes
, 1);
949 dump_pass_list (all_regular_ipa_passes
, 1);
950 dump_pass_list (all_late_ipa_passes
, 1);
951 dump_pass_list (all_passes
, 1);
957 /* Returns the pass with NAME. */
960 get_pass_by_name (const char *name
)
962 opt_pass
**p
= name_to_pass_map
->get (name
);
970 /* Range [start, last]. */
976 const char *assem_name
;
977 struct uid_range
*next
;
980 typedef struct uid_range
*uid_range_p
;
983 static vec
<uid_range_p
>
984 enabled_pass_uid_range_tab
= vNULL
;
985 static vec
<uid_range_p
>
986 disabled_pass_uid_range_tab
= vNULL
;
989 /* Parse option string for -fdisable- and -fenable-
990 The syntax of the options:
993 -fdisable-<pass_name>
995 -fenable-<pass_name>=s1:e1,s2:e2,...
996 -fdisable-<pass_name>=s1:e1,s2:e2,...
1000 enable_disable_pass (const char *arg
, bool is_enable
)
1003 char *range_str
, *phase_name
;
1004 char *argstr
= xstrdup (arg
);
1005 vec
<uid_range_p
> *tab
= 0;
1007 range_str
= strchr (argstr
,'=');
1014 phase_name
= argstr
;
1018 error ("unrecognized option -fenable");
1020 error ("unrecognized option -fdisable");
1024 pass
= get_pass_by_name (phase_name
);
1025 if (!pass
|| pass
->static_pass_number
== -1)
1028 error ("unknown pass %s specified in -fenable", phase_name
);
1030 error ("unknown pass %s specified in -fdisable", phase_name
);
1036 tab
= &enabled_pass_uid_range_tab
;
1038 tab
= &disabled_pass_uid_range_tab
;
1040 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1041 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1046 uid_range_p new_range
= XCNEW (struct uid_range
);
1048 new_range
->start
= 0;
1049 new_range
->last
= (unsigned)-1;
1051 slot
= (*tab
)[pass
->static_pass_number
];
1052 new_range
->next
= slot
;
1053 (*tab
)[pass
->static_pass_number
] = new_range
;
1055 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1056 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1058 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1059 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1063 char *next_range
= NULL
;
1064 char *one_range
= range_str
;
1065 char *end_val
= NULL
;
1070 uid_range_p new_range
;
1071 char *invalid
= NULL
;
1073 char *func_name
= NULL
;
1075 next_range
= strchr (one_range
, ',');
1082 end_val
= strchr (one_range
, ':');
1088 start
= strtol (one_range
, &invalid
, 10);
1089 if (*invalid
|| start
< 0)
1091 if (end_val
|| (one_range
[0] >= '0'
1092 && one_range
[0] <= '9'))
1094 error ("Invalid range %s in option %s",
1096 is_enable
? "-fenable" : "-fdisable");
1100 func_name
= one_range
;
1104 new_range
= XCNEW (struct uid_range
);
1107 new_range
->start
= (unsigned) start
;
1108 new_range
->last
= (unsigned) start
;
1112 new_range
->start
= (unsigned) -1;
1113 new_range
->last
= (unsigned) -1;
1114 new_range
->assem_name
= xstrdup (func_name
);
1119 long last
= strtol (end_val
, &invalid
, 10);
1120 if (*invalid
|| last
< start
)
1122 error ("Invalid range %s in option %s",
1124 is_enable
? "-fenable" : "-fdisable");
1128 new_range
= XCNEW (struct uid_range
);
1129 new_range
->start
= (unsigned) start
;
1130 new_range
->last
= (unsigned) last
;
1133 slot
= (*tab
)[pass
->static_pass_number
];
1134 new_range
->next
= slot
;
1135 (*tab
)[pass
->static_pass_number
] = new_range
;
1138 if (new_range
->assem_name
)
1139 inform (UNKNOWN_LOCATION
,
1140 "enable pass %s for function %s",
1141 phase_name
, new_range
->assem_name
);
1143 inform (UNKNOWN_LOCATION
,
1144 "enable pass %s for functions in the range of [%u, %u]",
1145 phase_name
, new_range
->start
, new_range
->last
);
1149 if (new_range
->assem_name
)
1150 inform (UNKNOWN_LOCATION
,
1151 "disable pass %s for function %s",
1152 phase_name
, new_range
->assem_name
);
1154 inform (UNKNOWN_LOCATION
,
1155 "disable pass %s for functions in the range of [%u, %u]",
1156 phase_name
, new_range
->start
, new_range
->last
);
1159 one_range
= next_range
;
1160 } while (next_range
);
1166 /* Enable pass specified by ARG. */
1169 enable_pass (const char *arg
)
1171 enable_disable_pass (arg
, true);
1174 /* Disable pass specified by ARG. */
1177 disable_pass (const char *arg
)
1179 enable_disable_pass (arg
, false);
1182 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1185 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1187 vec
<uid_range_p
> tab
)
1189 uid_range_p slot
, range
;
1191 const char *aname
= NULL
;
1194 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1195 || pass
->static_pass_number
== -1)
1198 slot
= tab
[pass
->static_pass_number
];
1202 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1203 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1204 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1209 if ((unsigned) cgraph_uid
>= range
->start
1210 && (unsigned) cgraph_uid
<= range
->last
)
1212 if (range
->assem_name
&& aname
1213 && !strcmp (range
->assem_name
, aname
))
1215 range
= range
->next
;
1222 /* Update static_pass_number for passes (and the flag
1223 TODO_mark_first_instance).
1225 Passes are constructed with static_pass_number preinitialized to 0
1227 This field is used in two different ways: initially as instance numbers
1228 of their kind, and then as ids within the entire pass manager.
1230 Within pass_manager::pass_manager:
1232 * In add_pass_instance(), as called by next_pass_1 in
1233 NEXT_PASS in init_optimization_passes
1235 * When the initial instance of a pass within a pass manager is seen,
1236 it is flagged, and its static_pass_number is set to -1
1238 * On subsequent times that it is seen, the static pass number
1239 is decremented each time, so that if there are e.g. 4 dups,
1240 they have static_pass_number -4, 2, 3, 4 respectively (note
1241 how the initial one is negative and gives the count); these
1242 can be thought of as instance numbers of the specific pass
1244 * Within the register_dump_files () traversal, set_pass_for_id()
1245 is called on each pass, using these instance numbers to create
1246 dumpfile switches, and then overwriting them with a pass id,
1247 which are global to the whole pass manager (based on
1248 (TDI_end + current value of extra_dump_files_in_use) ) */
1251 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1252 opt_pass
*initial_pass
)
1254 /* Are we dealing with the first pass of its kind, or a clone? */
1255 if (new_pass
!= initial_pass
)
1257 /* We're dealing with a clone. */
1258 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1260 /* Indicate to register_dump_files that this pass has duplicates,
1261 and so it should rename the dump file. The first instance will
1262 be -1, and be number of duplicates = -static_pass_number - 1.
1263 Subsequent instances will be > 0 and just the duplicate number. */
1264 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1266 initial_pass
->static_pass_number
-= 1;
1267 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1272 /* We're dealing with the first pass of its kind. */
1273 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1274 new_pass
->static_pass_number
= -1;
1276 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1280 /* Add a pass to the pass list. Duplicate the pass if it's already
1284 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1286 /* Every pass should have a name so that plugins can refer to them. */
1287 gcc_assert (pass
->name
!= NULL
);
1289 add_pass_instance (pass
, false, initial_pass
);
1292 return &(*list
)->next
;
1295 /* List node for an inserted pass instance. We need to keep track of all
1296 the newly-added pass instances (with 'added_pass_nodes' defined below)
1297 so that we can register their dump files after pass-positioning is finished.
1298 Registering dumping files needs to be post-processed or the
1299 static_pass_number of the opt_pass object would be modified and mess up
1300 the dump file names of future pass instances to be added. */
1302 struct pass_list_node
1305 struct pass_list_node
*next
;
1308 static struct pass_list_node
*added_pass_nodes
= NULL
;
1309 static struct pass_list_node
*prev_added_pass_node
;
1311 /* Insert the pass at the proper position. Return true if the pass
1312 is successfully added.
1314 NEW_PASS_INFO - new pass to be inserted
1315 PASS_LIST - root of the pass list to insert the new pass to */
1318 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1320 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1321 bool success
= false;
1323 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1325 /* Check if the current pass is of the same type as the new pass and
1326 matches the name and the instance number of the reference pass. */
1327 if (pass
->type
== new_pass_info
->pass
->type
1329 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1330 && ((new_pass_info
->ref_pass_instance_number
== 0)
1331 || (new_pass_info
->ref_pass_instance_number
==
1332 pass
->static_pass_number
)
1333 || (new_pass_info
->ref_pass_instance_number
== 1
1334 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1337 struct pass_list_node
*new_pass_node
;
1339 if (new_pass_info
->ref_pass_instance_number
== 0)
1341 new_pass
= new_pass_info
->pass
->clone ();
1342 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1346 new_pass
= new_pass_info
->pass
;
1347 add_pass_instance (new_pass
, true, new_pass
);
1350 /* Insert the new pass instance based on the positioning op. */
1351 switch (new_pass_info
->pos_op
)
1353 case PASS_POS_INSERT_AFTER
:
1354 new_pass
->next
= pass
->next
;
1355 pass
->next
= new_pass
;
1357 /* Skip newly inserted pass to avoid repeated
1358 insertions in the case where the new pass and the
1359 existing one have the same name. */
1362 case PASS_POS_INSERT_BEFORE
:
1363 new_pass
->next
= pass
;
1365 prev_pass
->next
= new_pass
;
1367 *pass_list
= new_pass
;
1369 case PASS_POS_REPLACE
:
1370 new_pass
->next
= pass
->next
;
1372 prev_pass
->next
= new_pass
;
1374 *pass_list
= new_pass
;
1375 new_pass
->sub
= pass
->sub
;
1376 new_pass
->tv_id
= pass
->tv_id
;
1380 error ("invalid pass positioning operation");
1384 /* Save the newly added pass (instance) in the added_pass_nodes
1385 list so that we can register its dump file later. Note that
1386 we cannot register the dump file now because doing so will modify
1387 the static_pass_number of the opt_pass object and therefore
1388 mess up the dump file name of future instances. */
1389 new_pass_node
= XCNEW (struct pass_list_node
);
1390 new_pass_node
->pass
= new_pass
;
1391 if (!added_pass_nodes
)
1392 added_pass_nodes
= new_pass_node
;
1394 prev_added_pass_node
->next
= new_pass_node
;
1395 prev_added_pass_node
= new_pass_node
;
1400 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1407 /* Hooks a new pass into the pass lists.
1409 PASS_INFO - pass information that specifies the opt_pass object,
1410 reference pass, instance number, and how to position
1414 register_pass (struct register_pass_info
*pass_info
)
1416 g
->get_passes ()->register_pass (pass_info
);
1420 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1421 const char* ref_pass_name
, int ref_pass_inst_number
)
1423 register_pass_info i
;
1425 i
.reference_pass_name
= ref_pass_name
;
1426 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1429 g
->get_passes ()->register_pass (&i
);
1433 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1435 bool all_instances
, success
;
1436 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1438 /* The checks below could fail in buggy plugins. Existing GCC
1439 passes should never fail these checks, so we mention plugin in
1441 if (!pass_info
->pass
)
1442 fatal_error ("plugin cannot register a missing pass");
1444 if (!pass_info
->pass
->name
)
1445 fatal_error ("plugin cannot register an unnamed pass");
1447 if (!pass_info
->reference_pass_name
)
1449 ("plugin cannot register pass %qs without reference pass name",
1450 pass_info
->pass
->name
);
1452 /* Try to insert the new pass to the pass lists. We need to check
1453 all five lists as the reference pass could be in one (or all) of
1455 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1456 success
= position_pass (pass_info
, &all_lowering_passes
);
1457 if (!success
|| all_instances
)
1458 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1459 if (!success
|| all_instances
)
1460 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1461 if (!success
|| all_instances
)
1462 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1463 if (!success
|| all_instances
)
1464 success
|= position_pass (pass_info
, &all_passes
);
1467 ("pass %qs not found but is referenced by new pass %qs",
1468 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1470 /* OK, we have successfully inserted the new pass. We need to register
1471 the dump files for the newly added pass and its duplicates (if any).
1472 Because the registration of plugin/backend passes happens after the
1473 command-line options are parsed, the options that specify single
1474 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1475 passes. Therefore we currently can only enable dumping of
1476 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1477 are specified. While doing so, we also delete the pass_list_node
1478 objects created during pass positioning. */
1479 while (added_pass_nodes
)
1481 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1482 enum tree_dump_index tdi
;
1483 register_one_dump_file (added_pass_nodes
->pass
);
1484 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1485 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1487 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1491 /* Check if dump-all flag is specified. */
1492 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1493 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1494 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1495 XDELETE (added_pass_nodes
);
1496 added_pass_nodes
= next_node
;
1500 /* Construct the pass tree. The sequencing of passes is driven by
1501 the cgraph routines:
1503 finalize_compilation_unit ()
1504 for each node N in the cgraph
1505 cgraph_analyze_function (N)
1506 cgraph_lower_function (N) -> all_lowering_passes
1508 If we are optimizing, compile is then invoked:
1511 ipa_passes () -> all_small_ipa_passes
1512 -> Analysis of all_regular_ipa_passes
1513 * possible LTO streaming at copmilation time *
1514 -> Execution of all_regular_ipa_passes
1515 * possible LTO streaming at link time *
1516 -> all_late_ipa_passes
1517 expand_all_functions ()
1518 for each node N in the cgraph
1519 expand_function (N) -> Transformation of all_regular_ipa_passes
1524 pass_manager::operator new (size_t sz
)
1526 /* Ensure that all fields of the pass manager are zero-initialized. */
1527 return xcalloc (1, sz
);
1530 pass_manager::pass_manager (context
*ctxt
)
1531 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1532 all_regular_ipa_passes (NULL
),
1533 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1538 /* Initialize the pass_lists array. */
1539 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1541 #undef DEF_PASS_LIST
1543 /* Build the tree of passes. */
1545 #define INSERT_PASSES_AFTER(PASS) \
1548 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1550 opt_pass **p = &(PASS ## _1)->sub;
1552 #define POP_INSERT_PASSES() \
1555 #define NEXT_PASS(PASS, NUM) \
1557 gcc_assert (NULL == PASS ## _ ## NUM); \
1559 PASS ## _1 = make_##PASS (m_ctxt); \
1562 gcc_assert (PASS ## _1); \
1563 PASS ## _ ## NUM = PASS ## _1->clone (); \
1565 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1568 #define TERMINATE_PASS_LIST() \
1571 #include "pass-instances.def"
1573 #undef INSERT_PASSES_AFTER
1574 #undef PUSH_INSERT_PASSES_WITHIN
1575 #undef POP_INSERT_PASSES
1577 #undef TERMINATE_PASS_LIST
1579 /* Register the passes with the tree dump code. */
1580 register_dump_files (all_lowering_passes
);
1581 register_dump_files (all_small_ipa_passes
);
1582 register_dump_files (all_regular_ipa_passes
);
1583 register_dump_files (all_late_ipa_passes
);
1584 register_dump_files (all_passes
);
1587 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1588 function CALLBACK for every function in the call graph. Otherwise,
1589 call CALLBACK on the current function. */
1592 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1594 if (current_function_decl
)
1595 callback (cfun
, data
);
1598 struct cgraph_node
*node
;
1599 FOR_EACH_DEFINED_FUNCTION (node
)
1600 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1601 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1602 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1606 /* Because inlining might remove no-longer reachable nodes, we need to
1607 keep the array visible to garbage collector to avoid reading collected
1610 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1612 /* Hook called when NODE is removed and therefore should be
1613 excluded from order vector. DATA is an array of integers.
1614 DATA[0] holds max index it may be accessed by. For cgraph
1615 node DATA[node->uid + 1] holds index of this node in order
1618 remove_cgraph_node_from_order (cgraph_node
*node
, void *data
)
1620 int *order_idx
= (int *)data
;
1622 if (node
->uid
>= order_idx
[0])
1625 int idx
= order_idx
[node
->uid
+ 1];
1626 if (idx
>= 0 && idx
< nnodes
&& order
[idx
] == node
)
1630 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1631 function CALLBACK for every function in the call graph. Otherwise,
1632 call CALLBACK on the current function.
1633 This function is global so that plugins can use it. */
1635 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1639 if (current_function_decl
)
1640 callback (cfun
, data
);
1643 cgraph_node_hook_list
*hook
;
1645 gcc_assert (!order
);
1646 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1648 order_idx
= XALLOCAVEC (int, symtab
->cgraph_max_uid
+ 1);
1649 memset (order_idx
+ 1, -1, sizeof (int) * symtab
->cgraph_max_uid
);
1650 order_idx
[0] = symtab
->cgraph_max_uid
;
1652 nnodes
= ipa_reverse_postorder (order
);
1653 for (i
= nnodes
- 1; i
>= 0; i
--)
1655 order
[i
]->process
= 1;
1656 order_idx
[order
[i
]->uid
+ 1] = i
;
1658 hook
= symtab
->add_cgraph_removal_hook (remove_cgraph_node_from_order
,
1660 for (i
= nnodes
- 1; i
>= 0; i
--)
1662 /* Function could be inlined and removed as unreachable. */
1666 struct cgraph_node
*node
= order
[i
];
1668 /* Allow possibly removed nodes to be garbage collected. */
1671 if (node
->has_gimple_body_p ())
1672 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1674 symtab
->remove_cgraph_removal_hook (hook
);
1681 /* Helper function to perform function body dump. */
1684 execute_function_dump (function
*fn
, void *data
)
1686 opt_pass
*pass
= (opt_pass
*)data
;
1692 if (fn
->curr_properties
& PROP_trees
)
1693 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1695 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1697 /* Flush the file. If verification fails, we won't be able to
1698 close the file before aborting. */
1701 if ((fn
->curr_properties
& PROP_cfg
)
1702 && (dump_flags
& TDF_GRAPH
))
1704 if (!pass
->graph_dump_initialized
)
1706 clean_graph_dump_file (dump_file_name
);
1707 pass
->graph_dump_initialized
= true;
1709 print_graph_cfg (dump_file_name
, fn
);
1716 static struct profile_record
*profile_record
;
1718 /* Do profile consistency book-keeping for the pass with static number INDEX.
1719 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1720 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1721 if we are only book-keeping on passes that may have selectively disabled
1722 themselves on a given function. */
1724 check_profile_consistency (int index
, int subpass
, bool run
)
1726 pass_manager
*passes
= g
->get_passes ();
1729 if (!profile_record
)
1730 profile_record
= XCNEWVEC (struct profile_record
,
1731 passes
->passes_by_id_size
);
1732 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1733 gcc_assert (subpass
< 2);
1734 profile_record
[index
].run
|= run
;
1735 account_profile_record (&profile_record
[index
], subpass
);
1738 /* Output profile consistency. */
1741 dump_profile_report (void)
1743 g
->get_passes ()->dump_profile_report ();
1747 pass_manager::dump_profile_report () const
1750 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1751 gcov_type last_time
= 0, last_size
= 0;
1752 double rel_time_change
, rel_size_change
;
1753 int last_reported
= 0;
1755 if (!profile_record
)
1757 fprintf (stderr
, "\nProfile consistency report:\n\n");
1758 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1759 fprintf (stderr
, " |freq count |freq count |size time\n");
1761 for (i
= 0; i
< passes_by_id_size
; i
++)
1762 for (j
= 0 ; j
< 2; j
++)
1763 if (profile_record
[i
].run
)
1766 rel_time_change
= (profile_record
[i
].time
[j
]
1767 - (double)last_time
) * 100 / (double)last_time
;
1769 rel_time_change
= 0;
1771 rel_size_change
= (profile_record
[i
].size
[j
]
1772 - (double)last_size
) * 100 / (double)last_size
;
1774 rel_size_change
= 0;
1776 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1777 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1778 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1779 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1780 || rel_time_change
|| rel_size_change
)
1783 fprintf (stderr
, "%-20s %s",
1784 passes_by_id
[i
]->name
,
1785 j
? "(after TODO)" : " ");
1786 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1787 fprintf (stderr
, "| %+5i",
1788 profile_record
[i
].num_mismatched_freq_in
[j
]
1791 fprintf (stderr
, "| ");
1792 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1793 fprintf (stderr
, " %+5i",
1794 profile_record
[i
].num_mismatched_count_in
[j
]
1797 fprintf (stderr
, " ");
1798 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1799 fprintf (stderr
, "| %+5i",
1800 profile_record
[i
].num_mismatched_freq_out
[j
]
1803 fprintf (stderr
, "| ");
1804 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1805 fprintf (stderr
, " %+5i",
1806 profile_record
[i
].num_mismatched_count_out
[j
]
1809 fprintf (stderr
, " ");
1811 /* Size/time units change across gimple and RTL. */
1812 if (i
== pass_expand_1
->static_pass_number
)
1813 fprintf (stderr
, "|----------");
1816 if (rel_size_change
)
1817 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1819 fprintf (stderr
, "| ");
1820 if (rel_time_change
)
1821 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1823 fprintf (stderr
, "\n");
1824 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1825 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1826 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1827 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1829 else if (j
&& last_reported
!= i
)
1832 fprintf (stderr
, "%-20s ------------| | |\n",
1833 passes_by_id
[i
]->name
);
1835 last_time
= profile_record
[i
].time
[j
];
1836 last_size
= profile_record
[i
].size
[j
];
1840 /* Perform all TODO actions that ought to be done on each function. */
1843 execute_function_todo (function
*fn
, void *data
)
1845 bool from_ipa_pass
= (cfun
== NULL
);
1846 unsigned int flags
= (size_t)data
;
1847 flags
&= ~fn
->last_verified
;
1853 /* Always cleanup the CFG before trying to update SSA. */
1854 if (flags
& TODO_cleanup_cfg
)
1856 cleanup_tree_cfg ();
1858 /* When cleanup_tree_cfg merges consecutive blocks, it may
1859 perform some simplistic propagation when removing single
1860 valued PHI nodes. This propagation may, in turn, cause the
1861 SSA form to become out-of-date (see PR 22037). So, even
1862 if the parent pass had not scheduled an SSA update, we may
1863 still need to do one. */
1864 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1865 flags
|= TODO_update_ssa
;
1868 if (flags
& TODO_update_ssa_any
)
1870 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1871 update_ssa (update_flags
);
1874 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1875 compute_may_aliases ();
1877 if (optimize
&& (flags
& TODO_update_address_taken
))
1878 execute_update_addresses_taken ();
1880 if (flags
& TODO_remove_unused_locals
)
1881 remove_unused_locals ();
1883 if (flags
& TODO_rebuild_frequencies
)
1884 rebuild_frequencies ();
1886 if (flags
& TODO_rebuild_cgraph_edges
)
1887 cgraph_edge::rebuild_edges ();
1889 /* If we've seen errors do not bother running any verifiers. */
1892 #if defined ENABLE_CHECKING
1893 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1894 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1896 if (flags
& TODO_verify_il
)
1898 if (cfun
->curr_properties
& PROP_trees
)
1900 if (cfun
->curr_properties
& PROP_cfg
)
1901 /* IPA passes leave stmts to be fixed up, so make sure to
1902 not verify stmts really throw. */
1903 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1905 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1907 if (cfun
->curr_properties
& PROP_ssa
)
1908 /* IPA passes leave stmts to be fixed up, so make sure to
1909 not verify SSA operands whose verifier will choke on that. */
1910 verify_ssa (true, !from_ipa_pass
);
1911 /* IPA passes leave basic-blocks unsplit, so make sure to
1912 not trip on that. */
1913 if ((cfun
->curr_properties
& PROP_cfg
)
1915 verify_flow_info ();
1917 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1918 verify_loop_closed_ssa (false);
1919 if (cfun
->curr_properties
& PROP_rtl
)
1920 verify_rtl_sharing ();
1923 /* Make sure verifiers don't change dominator state. */
1924 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1925 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1929 fn
->last_verified
= flags
& TODO_verify_all
;
1933 /* For IPA passes make sure to release dominator info, it can be
1934 computed by non-verifying TODOs. */
1937 free_dominance_info (fn
, CDI_DOMINATORS
);
1938 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1942 /* Perform all TODO actions. */
1944 execute_todo (unsigned int flags
)
1946 #if defined ENABLE_CHECKING
1948 && need_ssa_update_p (cfun
))
1949 gcc_assert (flags
& TODO_update_ssa_any
);
1952 timevar_push (TV_TODO
);
1954 /* Inform the pass whether it is the first time it is run. */
1955 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1957 statistics_fini_pass ();
1960 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1962 /* Always remove functions just as before inlining: IPA passes might be
1963 interested to see bodies of extern inline functions that are not inlined
1964 to analyze side effects. The full removal is done just at the end
1965 of IPA pass queue. */
1966 if (flags
& TODO_remove_functions
)
1969 symtab
->remove_unreachable_nodes (true, dump_file
);
1972 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1975 symtab_node::dump_table (dump_file
);
1976 /* Flush the file. If verification fails, we won't be able to
1977 close the file before aborting. */
1981 /* Now that the dumping has been done, we can get rid of the optional
1983 if (flags
& TODO_df_finish
)
1984 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1986 timevar_pop (TV_TODO
);
1989 /* Verify invariants that should hold between passes. This is a place
1990 to put simple sanity checks. */
1993 verify_interpass_invariants (void)
1995 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1998 /* Clear the last verified flag. */
2001 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
2003 fn
->last_verified
= 0;
2006 /* Helper function. Verify that the properties has been turn into the
2007 properties expected by the pass. */
2009 #ifdef ENABLE_CHECKING
2011 verify_curr_properties (function
*fn
, void *data
)
2013 unsigned int props
= (size_t)data
;
2014 gcc_assert ((fn
->curr_properties
& props
) == props
);
2018 /* Initialize pass dump file. */
2019 /* This is non-static so that the plugins can use it. */
2022 pass_init_dump_file (opt_pass
*pass
)
2024 /* If a dump file name is present, open it if enabled. */
2025 if (pass
->static_pass_number
!= -1)
2027 timevar_push (TV_DUMP
);
2028 gcc::dump_manager
*dumps
= g
->get_dumps ();
2029 bool initializing_dump
=
2030 !dumps
->dump_initialized_p (pass
->static_pass_number
);
2031 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
2032 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
2033 if (dump_file
&& current_function_decl
)
2034 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2035 if (initializing_dump
2036 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2037 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2039 clean_graph_dump_file (dump_file_name
);
2040 pass
->graph_dump_initialized
= true;
2042 timevar_pop (TV_DUMP
);
2043 return initializing_dump
;
2049 /* Flush PASS dump file. */
2050 /* This is non-static so that plugins can use it. */
2053 pass_fini_dump_file (opt_pass
*pass
)
2055 timevar_push (TV_DUMP
);
2057 /* Flush and close dump file. */
2060 free (CONST_CAST (char *, dump_file_name
));
2061 dump_file_name
= NULL
;
2064 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
2065 timevar_pop (TV_DUMP
);
2068 /* After executing the pass, apply expected changes to the function
2072 update_properties_after_pass (function
*fn
, void *data
)
2074 opt_pass
*pass
= (opt_pass
*) data
;
2075 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
2076 & ~pass
->properties_destroyed
;
2079 /* Execute summary generation for all of the passes in IPA_PASS. */
2082 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
2086 opt_pass
*pass
= ipa_pass
;
2088 /* Execute all of the IPA_PASSes in the list. */
2089 if (ipa_pass
->type
== IPA_PASS
2090 && pass
->gate (cfun
)
2091 && ipa_pass
->generate_summary
)
2093 pass_init_dump_file (pass
);
2095 /* If a timevar is present, start it. */
2097 timevar_push (pass
->tv_id
);
2099 current_pass
= pass
;
2100 ipa_pass
->generate_summary ();
2104 timevar_pop (pass
->tv_id
);
2106 pass_fini_dump_file (pass
);
2108 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2112 /* Execute IPA_PASS function transform on NODE. */
2115 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2116 ipa_opt_pass_d
*ipa_pass
)
2118 opt_pass
*pass
= ipa_pass
;
2119 unsigned int todo_after
= 0;
2121 current_pass
= pass
;
2122 if (!ipa_pass
->function_transform
)
2125 /* Note that the folders should only create gimple expressions.
2126 This is a hack until the new folder is ready. */
2127 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2129 pass_init_dump_file (pass
);
2131 /* Run pre-pass verification. */
2132 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2134 /* If a timevar is present, start it. */
2135 if (pass
->tv_id
!= TV_NONE
)
2136 timevar_push (pass
->tv_id
);
2139 todo_after
= ipa_pass
->function_transform (node
);
2142 if (pass
->tv_id
!= TV_NONE
)
2143 timevar_pop (pass
->tv_id
);
2145 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2146 check_profile_consistency (pass
->static_pass_number
, 0, true);
2148 /* Run post-pass cleanup and verification. */
2149 execute_todo (todo_after
);
2150 verify_interpass_invariants ();
2151 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2152 check_profile_consistency (pass
->static_pass_number
, 1, true);
2155 do_per_function (execute_function_dump
, NULL
);
2156 pass_fini_dump_file (pass
);
2158 current_pass
= NULL
;
2160 /* Signal this is a suitable GC collection point. */
2161 if (!(todo_after
& TODO_do_not_ggc_collect
))
2165 /* For the current function, execute all ipa transforms. */
2168 execute_all_ipa_transforms (void)
2170 struct cgraph_node
*node
;
2173 node
= cgraph_node::get (current_function_decl
);
2175 if (node
->ipa_transforms_to_apply
.exists ())
2179 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2180 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2181 node
->ipa_transforms_to_apply
.release ();
2185 /* Check if PASS is explicitly disabled or enabled and return
2186 the gate status. FUNC is the function to be processed, and
2187 GATE_STATUS is the gate status determined by pass manager by
2191 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2193 bool explicitly_enabled
= false;
2194 bool explicitly_disabled
= false;
2197 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2198 enabled_pass_uid_range_tab
);
2200 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2201 disabled_pass_uid_range_tab
);
2203 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2212 execute_one_pass (opt_pass
*pass
)
2214 unsigned int todo_after
= 0;
2218 /* IPA passes are executed on whole program, so cfun should be NULL.
2219 Other passes need function context set. */
2220 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2221 gcc_assert (!cfun
&& !current_function_decl
);
2223 gcc_assert (cfun
&& current_function_decl
);
2225 current_pass
= pass
;
2227 /* Check whether gate check should be avoided.
2228 User controls the value of the gate through the parameter "gate_status". */
2229 gate_status
= pass
->gate (cfun
);
2230 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2232 /* Override gate with plugin. */
2233 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2237 /* Run so passes selectively disabling themselves on a given function
2238 are not miscounted. */
2239 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2241 check_profile_consistency (pass
->static_pass_number
, 0, false);
2242 check_profile_consistency (pass
->static_pass_number
, 1, false);
2244 current_pass
= NULL
;
2248 /* Pass execution event trigger: useful to identify passes being
2250 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2252 if (!quiet_flag
&& !cfun
)
2253 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2255 /* Note that the folders should only create gimple expressions.
2256 This is a hack until the new folder is ready. */
2257 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2259 pass_init_dump_file (pass
);
2261 /* Run pre-pass verification. */
2262 execute_todo (pass
->todo_flags_start
);
2264 #ifdef ENABLE_CHECKING
2265 do_per_function (verify_curr_properties
,
2266 (void *)(size_t)pass
->properties_required
);
2269 /* If a timevar is present, start it. */
2270 if (pass
->tv_id
!= TV_NONE
)
2271 timevar_push (pass
->tv_id
);
2274 todo_after
= pass
->execute (cfun
);
2275 do_per_function (clear_last_verified
, NULL
);
2278 if (pass
->tv_id
!= TV_NONE
)
2279 timevar_pop (pass
->tv_id
);
2281 do_per_function (update_properties_after_pass
, pass
);
2283 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2284 check_profile_consistency (pass
->static_pass_number
, 0, true);
2286 /* Run post-pass cleanup and verification. */
2287 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2288 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2289 check_profile_consistency (pass
->static_pass_number
, 1, true);
2291 verify_interpass_invariants ();
2293 do_per_function (execute_function_dump
, pass
);
2294 if (pass
->type
== IPA_PASS
)
2296 struct cgraph_node
*node
;
2297 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2298 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2301 if (!current_function_decl
)
2302 symtab
->process_new_functions ();
2304 pass_fini_dump_file (pass
);
2306 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2307 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2308 || pass
->type
!= RTL_PASS
);
2310 current_pass
= NULL
;
2312 /* Signal this is a suitable GC collection point. */
2313 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2320 execute_pass_list_1 (opt_pass
*pass
)
2324 gcc_assert (pass
->type
== GIMPLE_PASS
2325 || pass
->type
== RTL_PASS
);
2326 if (execute_one_pass (pass
) && pass
->sub
)
2327 execute_pass_list_1 (pass
->sub
);
2334 execute_pass_list (function
*fn
, opt_pass
*pass
)
2337 execute_pass_list_1 (pass
);
2340 free_dominance_info (CDI_DOMINATORS
);
2341 free_dominance_info (CDI_POST_DOMINATORS
);
2346 /* Write out all LTO data. */
2350 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2352 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2353 timevar_push (TV_IPA_LTO_DECL_OUT
);
2354 produce_asm_for_decls ();
2355 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2358 /* Same as execute_pass_list but assume that subpasses of IPA passes
2359 are local passes. If SET is not NULL, write out summaries of only
2360 those node in SET. */
2363 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2367 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2368 gcc_assert (!current_function_decl
);
2370 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2371 if (pass
->type
== IPA_PASS
2372 && ipa_pass
->write_summary
2373 && pass
->gate (cfun
))
2375 /* If a timevar is present, start it. */
2377 timevar_push (pass
->tv_id
);
2379 pass_init_dump_file (pass
);
2381 current_pass
= pass
;
2382 ipa_pass
->write_summary ();
2384 pass_fini_dump_file (pass
);
2386 /* If a timevar is present, start it. */
2388 timevar_pop (pass
->tv_id
);
2391 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2392 ipa_write_summaries_2 (pass
->sub
, state
);
2398 /* Helper function of ipa_write_summaries. Creates and destroys the
2399 decl state and calls ipa_write_summaries_2 for all passes that have
2400 summaries. SET is the set of nodes to be written. */
2403 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2405 pass_manager
*passes
= g
->get_passes ();
2406 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2407 state
->symtab_node_encoder
= encoder
;
2409 lto_push_out_decl_state (state
);
2411 gcc_assert (!flag_wpa
);
2412 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2416 gcc_assert (lto_get_out_decl_state () == state
);
2417 lto_pop_out_decl_state ();
2418 lto_delete_out_decl_state (state
);
2421 /* Write out summaries for all the nodes in the callgraph. */
2424 ipa_write_summaries (bool offload_lto_mode
)
2426 lto_symtab_encoder_t encoder
;
2428 varpool_node
*vnode
;
2429 struct cgraph_node
*node
;
2430 struct cgraph_node
**order
;
2432 if (!flag_generate_lto
|| seen_error ())
2435 select_what_to_stream (offload_lto_mode
);
2437 encoder
= lto_symtab_encoder_new (false);
2439 /* Create the callgraph set in the same order used in
2440 cgraph_expand_all_functions. This mostly facilitates debugging,
2441 since it causes the gimple file to be processed in the same order
2442 as the source code. */
2443 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2444 order_pos
= ipa_reverse_postorder (order
);
2445 gcc_assert (order_pos
== symtab
->cgraph_count
);
2447 for (i
= order_pos
- 1; i
>= 0; i
--)
2449 struct cgraph_node
*node
= order
[i
];
2451 if (node
->has_gimple_body_p ())
2453 /* When streaming out references to statements as part of some IPA
2454 pass summary, the statements need to have uids assigned and the
2455 following does that for all the IPA passes here. Naturally, this
2456 ordering then matches the one IPA-passes get in their stmt_fixup
2459 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2460 renumber_gimple_stmt_uids ();
2463 if (node
->definition
&& node
->need_lto_streaming
)
2464 lto_set_symtab_encoder_in_partition (encoder
, node
);
2467 FOR_EACH_DEFINED_FUNCTION (node
)
2468 if (node
->alias
&& node
->need_lto_streaming
)
2469 lto_set_symtab_encoder_in_partition (encoder
, node
);
2470 FOR_EACH_DEFINED_VARIABLE (vnode
)
2471 if (vnode
->need_lto_streaming
)
2472 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2474 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2479 /* Same as execute_pass_list but assume that subpasses of IPA passes
2480 are local passes. If SET is not NULL, write out optimization summaries of
2481 only those node in SET. */
2484 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2485 struct lto_out_decl_state
*state
)
2489 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2490 gcc_assert (!current_function_decl
);
2492 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2493 if (pass
->type
== IPA_PASS
2494 && ipa_pass
->write_optimization_summary
2495 && pass
->gate (cfun
))
2497 /* If a timevar is present, start it. */
2499 timevar_push (pass
->tv_id
);
2501 pass_init_dump_file (pass
);
2503 current_pass
= pass
;
2504 ipa_pass
->write_optimization_summary ();
2506 pass_fini_dump_file (pass
);
2508 /* If a timevar is present, start it. */
2510 timevar_pop (pass
->tv_id
);
2513 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2514 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2520 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2521 NULL, write out all summaries of all nodes. */
2524 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2526 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2527 lto_symtab_encoder_iterator lsei
;
2528 state
->symtab_node_encoder
= encoder
;
2530 lto_push_out_decl_state (state
);
2531 for (lsei
= lsei_start_function_in_partition (encoder
);
2532 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2534 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2535 /* When streaming out references to statements as part of some IPA
2536 pass summary, the statements need to have uids assigned.
2538 For functions newly born at WPA stage we need to initialize
2540 if (node
->definition
2541 && gimple_has_body_p (node
->decl
))
2543 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2544 renumber_gimple_stmt_uids ();
2549 gcc_assert (flag_wpa
);
2550 pass_manager
*passes
= g
->get_passes ();
2551 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2555 gcc_assert (lto_get_out_decl_state () == state
);
2556 lto_pop_out_decl_state ();
2557 lto_delete_out_decl_state (state
);
2560 /* Same as execute_pass_list but assume that subpasses of IPA passes
2561 are local passes. */
2564 ipa_read_summaries_1 (opt_pass
*pass
)
2568 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2570 gcc_assert (!current_function_decl
);
2572 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2574 if (pass
->gate (cfun
))
2576 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2578 /* If a timevar is present, start it. */
2580 timevar_push (pass
->tv_id
);
2582 pass_init_dump_file (pass
);
2584 current_pass
= pass
;
2585 ipa_pass
->read_summary ();
2587 pass_fini_dump_file (pass
);
2591 timevar_pop (pass
->tv_id
);
2594 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2595 ipa_read_summaries_1 (pass
->sub
);
2602 /* Read all the summaries for all_regular_ipa_passes. */
2605 ipa_read_summaries (void)
2607 pass_manager
*passes
= g
->get_passes ();
2608 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2611 /* Same as execute_pass_list but assume that subpasses of IPA passes
2612 are local passes. */
2615 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2619 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2621 gcc_assert (!current_function_decl
);
2623 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2625 if (pass
->gate (cfun
))
2627 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2629 /* If a timevar is present, start it. */
2631 timevar_push (pass
->tv_id
);
2633 pass_init_dump_file (pass
);
2635 current_pass
= pass
;
2636 ipa_pass
->read_optimization_summary ();
2638 pass_fini_dump_file (pass
);
2642 timevar_pop (pass
->tv_id
);
2645 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2646 ipa_read_optimization_summaries_1 (pass
->sub
);
2652 /* Read all the summaries for all_regular_ipa_passes. */
2655 ipa_read_optimization_summaries (void)
2657 pass_manager
*passes
= g
->get_passes ();
2658 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2661 /* Same as execute_pass_list but assume that subpasses of IPA passes
2662 are local passes. */
2664 execute_ipa_pass_list (opt_pass
*pass
)
2668 gcc_assert (!current_function_decl
);
2670 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2671 if (execute_one_pass (pass
) && pass
->sub
)
2673 if (pass
->sub
->type
== GIMPLE_PASS
)
2675 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2676 do_per_function_toporder ((void (*)(function
*, void *))
2679 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2681 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2682 || pass
->sub
->type
== IPA_PASS
)
2683 execute_ipa_pass_list (pass
->sub
);
2687 gcc_assert (!current_function_decl
);
2688 symtab
->process_new_functions ();
2694 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2697 execute_ipa_stmt_fixups (opt_pass
*pass
,
2698 struct cgraph_node
*node
, gimple
*stmts
)
2702 /* Execute all of the IPA_PASSes in the list. */
2703 if (pass
->type
== IPA_PASS
2704 && pass
->gate (cfun
))
2706 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2708 if (ipa_pass
->stmt_fixup
)
2710 pass_init_dump_file (pass
);
2711 /* If a timevar is present, start it. */
2713 timevar_push (pass
->tv_id
);
2715 current_pass
= pass
;
2716 ipa_pass
->stmt_fixup (node
, stmts
);
2720 timevar_pop (pass
->tv_id
);
2721 pass_fini_dump_file (pass
);
2724 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2730 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2733 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2735 pass_manager
*passes
= g
->get_passes ();
2736 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2740 extern void debug_properties (unsigned int);
2741 extern void dump_properties (FILE *, unsigned int);
2744 dump_properties (FILE *dump
, unsigned int props
)
2746 fprintf (dump
, "Properties:\n");
2747 if (props
& PROP_gimple_any
)
2748 fprintf (dump
, "PROP_gimple_any\n");
2749 if (props
& PROP_gimple_lcf
)
2750 fprintf (dump
, "PROP_gimple_lcf\n");
2751 if (props
& PROP_gimple_leh
)
2752 fprintf (dump
, "PROP_gimple_leh\n");
2753 if (props
& PROP_cfg
)
2754 fprintf (dump
, "PROP_cfg\n");
2755 if (props
& PROP_ssa
)
2756 fprintf (dump
, "PROP_ssa\n");
2757 if (props
& PROP_no_crit_edges
)
2758 fprintf (dump
, "PROP_no_crit_edges\n");
2759 if (props
& PROP_rtl
)
2760 fprintf (dump
, "PROP_rtl\n");
2761 if (props
& PROP_gimple_lomp
)
2762 fprintf (dump
, "PROP_gimple_lomp\n");
2763 if (props
& PROP_gimple_lcx
)
2764 fprintf (dump
, "PROP_gimple_lcx\n");
2765 if (props
& PROP_gimple_lvec
)
2766 fprintf (dump
, "PROP_gimple_lvec\n");
2767 if (props
& PROP_cfglayout
)
2768 fprintf (dump
, "PROP_cfglayout\n");
2772 debug_properties (unsigned int props
)
2774 dump_properties (stderr
, props
);
2777 /* Called by local passes to see if function is called by already processed nodes.
2778 Because we process nodes in topological order, this means that function is
2779 in recursive cycle or we introduced new direct calls. */
2781 function_called_by_processed_nodes_p (void)
2783 struct cgraph_edge
*e
;
2784 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2788 if (e
->caller
->decl
== current_function_decl
)
2790 if (!e
->caller
->has_gimple_body_p ())
2792 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2794 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2799 fprintf (dump_file
, "Already processed call to:\n");
2800 e
->caller
->dump (dump_file
);
2805 #include "gt-passes.h"