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_early_local_passes_1
->sub
);
147 pass_manager::execute_pass_mode_switching ()
149 return pass_mode_switching_1
->execute (cfun
);
153 /* Call from anywhere to find out what pass this is. Useful for
154 printing out debugging information deep inside an service
157 print_current_pass (FILE *file
)
160 fprintf (file
, "current pass = %s (%d)\n",
161 current_pass
->name
, current_pass
->static_pass_number
);
163 fprintf (file
, "no current pass.\n");
167 /* Call from the debugger to get the current pass name. */
171 print_current_pass (stderr
);
176 /* Global variables used to communicate with passes. */
178 bool first_pass_instance
;
181 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
184 This does nothing for local (non-static) variables, unless the
185 variable is a register variable with DECL_ASSEMBLER_NAME set. In
186 that case, or if the variable is not an automatic, it sets up the
187 RTL and outputs any assembler code (label definition, storage
188 allocation and initialization).
190 DECL is the declaration. TOP_LEVEL is nonzero
191 if this declaration is not within a function. */
194 rest_of_decl_compilation (tree decl
,
198 bool finalize
= true;
200 /* We deferred calling assemble_alias so that we could collect
201 other attributes such as visibility. Emit the alias now. */
205 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
208 alias
= TREE_VALUE (TREE_VALUE (alias
));
209 alias
= get_identifier (TREE_STRING_POINTER (alias
));
210 /* A quirk of the initial implementation of aliases required that the
211 user add "extern" to all of them. Which is silly, but now
212 historical. Do note that the symbol is in fact locally defined. */
213 DECL_EXTERNAL (decl
) = 0;
214 TREE_STATIC (decl
) = 1;
215 assemble_alias (decl
, alias
);
220 /* Can't defer this, because it needs to happen before any
221 later function definitions are processed. */
222 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
223 make_decl_rtl (decl
);
225 /* Forward declarations for nested functions are not "external",
226 but we need to treat them as if they were. */
227 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
228 || TREE_CODE (decl
) == FUNCTION_DECL
)
230 timevar_push (TV_VARCONST
);
232 /* Don't output anything when a tentative file-scope definition
233 is seen. But at end of compilation, do output code for them.
235 We do output all variables and rely on
236 callgraph code to defer them except for forward declarations
237 (see gcc.c-torture/compile/920624-1.c) */
239 || !DECL_DEFER_OUTPUT (decl
)
240 || DECL_INITIAL (decl
))
241 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
242 && !DECL_EXTERNAL (decl
))
244 /* When reading LTO unit, we also read varpool, so do not
246 if (in_lto_p
&& !at_end
)
248 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
249 varpool_node::finalize_decl (decl
);
252 #ifdef ASM_FINISH_DECLARE_OBJECT
253 if (decl
== last_assemble_variable_decl
)
255 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
260 timevar_pop (TV_VARCONST
);
262 else if (TREE_CODE (decl
) == TYPE_DECL
263 /* Like in rest_of_type_compilation, avoid confusing the debug
264 information machinery when there are errors. */
267 timevar_push (TV_SYMOUT
);
268 debug_hooks
->type_decl (decl
, !top_level
);
269 timevar_pop (TV_SYMOUT
);
272 /* Let cgraph know about the existence of variables. */
273 if (in_lto_p
&& !at_end
)
275 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
276 && TREE_STATIC (decl
))
277 varpool_node::get_create (decl
);
280 /* Called after finishing a record, union or enumeral type. */
283 rest_of_type_compilation (tree type
, int toplev
)
285 /* Avoid confusing the debug information machinery when there are
290 timevar_push (TV_SYMOUT
);
291 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
292 timevar_pop (TV_SYMOUT
);
299 finish_optimization_passes (void)
302 struct dump_file_info
*dfi
;
304 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
306 timevar_push (TV_DUMP
);
307 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
309 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
311 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
316 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
317 print_combine_total_stats ();
318 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
321 /* Do whatever is necessary to finish printing the graphs. */
322 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
323 if (dumps
->dump_initialized_p (i
)
324 && (dfi
->pflags
& TDF_GRAPH
) != 0
325 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
327 finish_graph_dump_file (name
);
331 timevar_pop (TV_DUMP
);
335 execute_all_early_local_passes (void)
337 /* Once this pass (and its sub-passes) are complete, all functions
338 will be in SSA form. Technically this state change is happening
339 a tad early, since the sub-passes have not yet run, but since
340 none of the sub-passes are IPA passes and do not create new
341 functions, this is ok. We're setting this value for the benefit
342 of IPA passes that follow. */
343 if (symtab
->state
< IPA_SSA
)
344 symtab
->state
= IPA_SSA
;
350 const pass_data pass_data_early_local_passes
=
352 SIMPLE_IPA_PASS
, /* type */
353 "early_local_cleanups", /* name */
354 OPTGROUP_NONE
, /* optinfo_flags */
355 TV_EARLY_LOCAL
, /* tv_id */
356 0, /* properties_required */
357 0, /* properties_provided */
358 0, /* properties_destroyed */
359 0, /* todo_flags_start */
360 /* todo_flags_finish is executed before subpases. For this reason
361 it makes no sense to remove unreachable functions here. */
362 0, /* todo_flags_finish */
365 class pass_early_local_passes
: public simple_ipa_opt_pass
368 pass_early_local_passes (gcc::context
*ctxt
)
369 : simple_ipa_opt_pass (pass_data_early_local_passes
, ctxt
)
372 /* opt_pass methods: */
373 virtual bool gate (function
*)
375 /* Don't bother doing anything if the program has errors. */
376 return (!seen_error () && !in_lto_p
);
379 virtual unsigned int execute (function
*)
381 return execute_all_early_local_passes ();
384 }; // class pass_early_local_passes
388 simple_ipa_opt_pass
*
389 make_pass_early_local_passes (gcc::context
*ctxt
)
391 return new pass_early_local_passes (ctxt
);
396 const pass_data pass_data_all_early_optimizations
=
398 GIMPLE_PASS
, /* type */
399 "early_optimizations", /* name */
400 OPTGROUP_NONE
, /* optinfo_flags */
402 0, /* properties_required */
403 0, /* properties_provided */
404 0, /* properties_destroyed */
405 0, /* todo_flags_start */
406 0, /* todo_flags_finish */
409 class pass_all_early_optimizations
: public gimple_opt_pass
412 pass_all_early_optimizations (gcc::context
*ctxt
)
413 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
416 /* opt_pass methods: */
417 virtual bool gate (function
*)
419 return (optimize
>= 1
420 /* Don't bother doing anything if the program has errors. */
424 }; // class pass_all_early_optimizations
428 static gimple_opt_pass
*
429 make_pass_all_early_optimizations (gcc::context
*ctxt
)
431 return new pass_all_early_optimizations (ctxt
);
436 const pass_data pass_data_all_optimizations
=
438 GIMPLE_PASS
, /* type */
439 "*all_optimizations", /* name */
440 OPTGROUP_NONE
, /* optinfo_flags */
441 TV_OPTIMIZE
, /* tv_id */
442 0, /* properties_required */
443 0, /* properties_provided */
444 0, /* properties_destroyed */
445 0, /* todo_flags_start */
446 0, /* todo_flags_finish */
449 class pass_all_optimizations
: public gimple_opt_pass
452 pass_all_optimizations (gcc::context
*ctxt
)
453 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
456 /* opt_pass methods: */
457 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
459 }; // class pass_all_optimizations
463 static gimple_opt_pass
*
464 make_pass_all_optimizations (gcc::context
*ctxt
)
466 return new pass_all_optimizations (ctxt
);
471 const pass_data pass_data_all_optimizations_g
=
473 GIMPLE_PASS
, /* type */
474 "*all_optimizations_g", /* name */
475 OPTGROUP_NONE
, /* optinfo_flags */
476 TV_OPTIMIZE
, /* tv_id */
477 0, /* properties_required */
478 0, /* properties_provided */
479 0, /* properties_destroyed */
480 0, /* todo_flags_start */
481 0, /* todo_flags_finish */
484 class pass_all_optimizations_g
: public gimple_opt_pass
487 pass_all_optimizations_g (gcc::context
*ctxt
)
488 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
491 /* opt_pass methods: */
492 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
494 }; // class pass_all_optimizations_g
498 static gimple_opt_pass
*
499 make_pass_all_optimizations_g (gcc::context
*ctxt
)
501 return new pass_all_optimizations_g (ctxt
);
506 const pass_data pass_data_rest_of_compilation
=
509 "*rest_of_compilation", /* name */
510 OPTGROUP_NONE
, /* optinfo_flags */
511 TV_REST_OF_COMPILATION
, /* tv_id */
512 PROP_rtl
, /* properties_required */
513 0, /* properties_provided */
514 0, /* properties_destroyed */
515 0, /* todo_flags_start */
516 0, /* todo_flags_finish */
519 class pass_rest_of_compilation
: public rtl_opt_pass
522 pass_rest_of_compilation (gcc::context
*ctxt
)
523 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
526 /* opt_pass methods: */
527 virtual bool gate (function
*)
529 /* Early return if there were errors. We can run afoul of our
530 consistency checks, and there's not really much point in fixing them. */
531 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
534 }; // class pass_rest_of_compilation
538 static rtl_opt_pass
*
539 make_pass_rest_of_compilation (gcc::context
*ctxt
)
541 return new pass_rest_of_compilation (ctxt
);
546 const pass_data pass_data_postreload
=
549 "*all-postreload", /* name */
550 OPTGROUP_NONE
, /* optinfo_flags */
551 TV_POSTRELOAD
, /* tv_id */
552 PROP_rtl
, /* properties_required */
553 0, /* properties_provided */
554 0, /* properties_destroyed */
555 0, /* todo_flags_start */
556 0, /* todo_flags_finish */
559 class pass_postreload
: public rtl_opt_pass
562 pass_postreload (gcc::context
*ctxt
)
563 : rtl_opt_pass (pass_data_postreload
, ctxt
)
566 /* opt_pass methods: */
567 virtual bool gate (function
*) { return reload_completed
; }
569 }; // class pass_postreload
573 static rtl_opt_pass
*
574 make_pass_postreload (gcc::context
*ctxt
)
576 return new pass_postreload (ctxt
);
581 const pass_data pass_data_late_compilation
=
584 "*all-late_compilation", /* name */
585 OPTGROUP_NONE
, /* optinfo_flags */
586 TV_LATE_COMPILATION
, /* tv_id */
587 PROP_rtl
, /* properties_required */
588 0, /* properties_provided */
589 0, /* properties_destroyed */
590 0, /* todo_flags_start */
591 0, /* todo_flags_finish */
594 class pass_late_compilation
: public rtl_opt_pass
597 pass_late_compilation (gcc::context
*ctxt
)
598 : rtl_opt_pass (pass_data_late_compilation
, ctxt
)
601 /* opt_pass methods: */
602 virtual bool gate (function
*)
604 return reload_completed
|| targetm
.no_register_allocation
;
607 }; // class pass_late_compilation
611 static rtl_opt_pass
*
612 make_pass_late_compilation (gcc::context
*ctxt
)
614 return new pass_late_compilation (ctxt
);
619 /* Set the static pass number of pass PASS to ID and record that
620 in the mapping from static pass number to pass. */
624 set_pass_for_id (int id
, opt_pass
*pass
)
626 pass
->static_pass_number
= id
;
627 if (passes_by_id_size
<= id
)
629 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
630 memset (passes_by_id
+ passes_by_id_size
, 0,
631 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
632 passes_by_id_size
= id
+ 1;
634 passes_by_id
[id
] = pass
;
637 /* Return the pass with the static pass number ID. */
640 pass_manager::get_pass_for_id (int id
) const
642 if (id
>= passes_by_id_size
)
644 return passes_by_id
[id
];
647 /* Iterate over the pass tree allocating dump file numbers. We want
648 to do this depth first, and independent of whether the pass is
652 register_one_dump_file (opt_pass
*pass
)
654 g
->get_passes ()->register_one_dump_file (pass
);
658 pass_manager::register_one_dump_file (opt_pass
*pass
)
660 char *dot_name
, *flag_name
, *glob_name
;
661 const char *name
, *full_name
, *prefix
;
664 int optgroup_flags
= OPTGROUP_NONE
;
665 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
667 /* See below in next_pass_1. */
669 if (pass
->static_pass_number
!= -1)
670 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
671 ? 1 : pass
->static_pass_number
));
673 /* The name is both used to identify the pass for the purposes of plugins,
674 and to specify dump file name and option.
675 The latter two might want something short which is not quite unique; for
676 that reason, we may have a disambiguating prefix, followed by a space
677 to mark the start of the following dump file name / option string. */
678 name
= strchr (pass
->name
, ' ');
679 name
= name
? name
+ 1 : pass
->name
;
680 dot_name
= concat (".", name
, num
, NULL
);
681 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
685 optgroup_flags
|= OPTGROUP_IPA
;
687 else if (pass
->type
== GIMPLE_PASS
)
698 flag_name
= concat (prefix
, name
, num
, NULL
);
699 glob_name
= concat (prefix
, name
, NULL
);
700 optgroup_flags
|= pass
->optinfo_flags
;
701 /* For any passes that do not have an optgroup set, and which are not
702 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
703 any dump messages are emitted properly under -fopt-info(-optall). */
704 if (optgroup_flags
== OPTGROUP_NONE
)
705 optgroup_flags
= OPTGROUP_OTHER
;
706 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
708 set_pass_for_id (id
, pass
);
709 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
710 register_pass_name (pass
, full_name
);
711 free (CONST_CAST (char *, full_name
));
714 /* Register the dump files for the pass_manager starting at PASS. */
717 pass_manager::register_dump_files (opt_pass
*pass
)
721 if (pass
->name
&& pass
->name
[0] != '*')
722 register_one_dump_file (pass
);
725 register_dump_files (pass
->sub
);
732 /* Helper for pass_registry hash table. */
734 struct pass_registry_hasher
: default_hashmap_traits
736 static inline hashval_t
hash (const char *);
737 static inline bool equal_keys (const char *, const char *);
740 /* Pass registry hash function. */
743 pass_registry_hasher::hash (const char *name
)
745 return htab_hash_string (name
);
748 /* Hash equal function */
751 pass_registry_hasher::equal_keys (const char *s1
, const char *s2
)
753 return !strcmp (s1
, s2
);
756 static hash_map
<const char *, opt_pass
*, pass_registry_hasher
>
759 /* Register PASS with NAME. */
762 register_pass_name (opt_pass
*pass
, const char *name
)
764 if (!name_to_pass_map
)
766 = new hash_map
<const char *, opt_pass
*, pass_registry_hasher
> (256);
768 if (name_to_pass_map
->get (name
))
769 return; /* Ignore plugin passes. */
771 const char *unique_name
= xstrdup (name
);
772 name_to_pass_map
->put (unique_name
, pass
);
775 /* Map from pass id to canonicalized pass name. */
777 typedef const char *char_ptr
;
778 static vec
<char_ptr
> pass_tab
= vNULL
;
780 /* Callback function for traversing NAME_TO_PASS_MAP. */
783 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
785 gcc_assert (pass
->static_pass_number
> 0);
786 gcc_assert (pass_tab
.exists ());
788 pass_tab
[pass
->static_pass_number
] = name
;
793 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
794 table for dumping purpose. */
797 create_pass_tab (void)
799 if (!flag_dump_passes
)
802 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
803 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
806 static bool override_gate_status (opt_pass
*, tree
, bool);
808 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
809 is turned on or not. */
812 dump_one_pass (opt_pass
*pass
, int pass_indent
)
814 int indent
= 3 * pass_indent
;
816 bool is_on
, is_really_on
;
818 is_on
= pass
->gate (cfun
);
819 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
821 if (pass
->static_pass_number
<= 0)
824 pn
= pass_tab
[pass
->static_pass_number
];
826 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
827 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
828 is_on
? " ON" : " OFF",
829 ((!is_on
) == (!is_really_on
) ? ""
830 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
833 /* Dump pass list PASS with indentation INDENT. */
836 dump_pass_list (opt_pass
*pass
, int indent
)
840 dump_one_pass (pass
, indent
);
842 dump_pass_list (pass
->sub
, indent
+ 1);
848 /* Dump all optimization passes. */
853 g
->get_passes ()->dump_passes ();
857 pass_manager::dump_passes () const
859 struct cgraph_node
*n
, *node
= NULL
;
863 FOR_EACH_FUNCTION (n
)
864 if (DECL_STRUCT_FUNCTION (n
->decl
))
873 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
875 dump_pass_list (all_lowering_passes
, 1);
876 dump_pass_list (all_small_ipa_passes
, 1);
877 dump_pass_list (all_regular_ipa_passes
, 1);
878 dump_pass_list (all_late_ipa_passes
, 1);
879 dump_pass_list (all_passes
, 1);
885 /* Returns the pass with NAME. */
888 get_pass_by_name (const char *name
)
890 opt_pass
**p
= name_to_pass_map
->get (name
);
898 /* Range [start, last]. */
904 const char *assem_name
;
905 struct uid_range
*next
;
908 typedef struct uid_range
*uid_range_p
;
911 static vec
<uid_range_p
>
912 enabled_pass_uid_range_tab
= vNULL
;
913 static vec
<uid_range_p
>
914 disabled_pass_uid_range_tab
= vNULL
;
917 /* Parse option string for -fdisable- and -fenable-
918 The syntax of the options:
921 -fdisable-<pass_name>
923 -fenable-<pass_name>=s1:e1,s2:e2,...
924 -fdisable-<pass_name>=s1:e1,s2:e2,...
928 enable_disable_pass (const char *arg
, bool is_enable
)
931 char *range_str
, *phase_name
;
932 char *argstr
= xstrdup (arg
);
933 vec
<uid_range_p
> *tab
= 0;
935 range_str
= strchr (argstr
,'=');
946 error ("unrecognized option -fenable");
948 error ("unrecognized option -fdisable");
952 pass
= get_pass_by_name (phase_name
);
953 if (!pass
|| pass
->static_pass_number
== -1)
956 error ("unknown pass %s specified in -fenable", phase_name
);
958 error ("unknown pass %s specified in -fdisable", phase_name
);
964 tab
= &enabled_pass_uid_range_tab
;
966 tab
= &disabled_pass_uid_range_tab
;
968 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
969 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
974 uid_range_p new_range
= XCNEW (struct uid_range
);
976 new_range
->start
= 0;
977 new_range
->last
= (unsigned)-1;
979 slot
= (*tab
)[pass
->static_pass_number
];
980 new_range
->next
= slot
;
981 (*tab
)[pass
->static_pass_number
] = new_range
;
983 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
984 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
986 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
987 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
991 char *next_range
= NULL
;
992 char *one_range
= range_str
;
993 char *end_val
= NULL
;
998 uid_range_p new_range
;
999 char *invalid
= NULL
;
1001 char *func_name
= NULL
;
1003 next_range
= strchr (one_range
, ',');
1010 end_val
= strchr (one_range
, ':');
1016 start
= strtol (one_range
, &invalid
, 10);
1017 if (*invalid
|| start
< 0)
1019 if (end_val
|| (one_range
[0] >= '0'
1020 && one_range
[0] <= '9'))
1022 error ("Invalid range %s in option %s",
1024 is_enable
? "-fenable" : "-fdisable");
1028 func_name
= one_range
;
1032 new_range
= XCNEW (struct uid_range
);
1035 new_range
->start
= (unsigned) start
;
1036 new_range
->last
= (unsigned) start
;
1040 new_range
->start
= (unsigned) -1;
1041 new_range
->last
= (unsigned) -1;
1042 new_range
->assem_name
= xstrdup (func_name
);
1047 long last
= strtol (end_val
, &invalid
, 10);
1048 if (*invalid
|| last
< start
)
1050 error ("Invalid range %s in option %s",
1052 is_enable
? "-fenable" : "-fdisable");
1056 new_range
= XCNEW (struct uid_range
);
1057 new_range
->start
= (unsigned) start
;
1058 new_range
->last
= (unsigned) last
;
1061 slot
= (*tab
)[pass
->static_pass_number
];
1062 new_range
->next
= slot
;
1063 (*tab
)[pass
->static_pass_number
] = new_range
;
1066 if (new_range
->assem_name
)
1067 inform (UNKNOWN_LOCATION
,
1068 "enable pass %s for function %s",
1069 phase_name
, new_range
->assem_name
);
1071 inform (UNKNOWN_LOCATION
,
1072 "enable pass %s for functions in the range of [%u, %u]",
1073 phase_name
, new_range
->start
, new_range
->last
);
1077 if (new_range
->assem_name
)
1078 inform (UNKNOWN_LOCATION
,
1079 "disable pass %s for function %s",
1080 phase_name
, new_range
->assem_name
);
1082 inform (UNKNOWN_LOCATION
,
1083 "disable pass %s for functions in the range of [%u, %u]",
1084 phase_name
, new_range
->start
, new_range
->last
);
1087 one_range
= next_range
;
1088 } while (next_range
);
1094 /* Enable pass specified by ARG. */
1097 enable_pass (const char *arg
)
1099 enable_disable_pass (arg
, true);
1102 /* Disable pass specified by ARG. */
1105 disable_pass (const char *arg
)
1107 enable_disable_pass (arg
, false);
1110 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1113 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1115 vec
<uid_range_p
> tab
)
1117 uid_range_p slot
, range
;
1119 const char *aname
= NULL
;
1122 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1123 || pass
->static_pass_number
== -1)
1126 slot
= tab
[pass
->static_pass_number
];
1130 cgraph_uid
= func
? cgraph_node::get (func
)->uid
: 0;
1131 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1132 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1137 if ((unsigned) cgraph_uid
>= range
->start
1138 && (unsigned) cgraph_uid
<= range
->last
)
1140 if (range
->assem_name
&& aname
1141 && !strcmp (range
->assem_name
, aname
))
1143 range
= range
->next
;
1150 /* Update static_pass_number for passes (and the flag
1151 TODO_mark_first_instance).
1153 Passes are constructed with static_pass_number preinitialized to 0
1155 This field is used in two different ways: initially as instance numbers
1156 of their kind, and then as ids within the entire pass manager.
1158 Within pass_manager::pass_manager:
1160 * In add_pass_instance(), as called by next_pass_1 in
1161 NEXT_PASS in init_optimization_passes
1163 * When the initial instance of a pass within a pass manager is seen,
1164 it is flagged, and its static_pass_number is set to -1
1166 * On subsequent times that it is seen, the static pass number
1167 is decremented each time, so that if there are e.g. 4 dups,
1168 they have static_pass_number -4, 2, 3, 4 respectively (note
1169 how the initial one is negative and gives the count); these
1170 can be thought of as instance numbers of the specific pass
1172 * Within the register_dump_files () traversal, set_pass_for_id()
1173 is called on each pass, using these instance numbers to create
1174 dumpfile switches, and then overwriting them with a pass id,
1175 which are global to the whole pass manager (based on
1176 (TDI_end + current value of extra_dump_files_in_use) ) */
1179 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1180 opt_pass
*initial_pass
)
1182 /* Are we dealing with the first pass of its kind, or a clone? */
1183 if (new_pass
!= initial_pass
)
1185 /* We're dealing with a clone. */
1186 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1188 /* Indicate to register_dump_files that this pass has duplicates,
1189 and so it should rename the dump file. The first instance will
1190 be -1, and be number of duplicates = -static_pass_number - 1.
1191 Subsequent instances will be > 0 and just the duplicate number. */
1192 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1194 initial_pass
->static_pass_number
-= 1;
1195 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1200 /* We're dealing with the first pass of its kind. */
1201 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1202 new_pass
->static_pass_number
= -1;
1204 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1208 /* Add a pass to the pass list. Duplicate the pass if it's already
1212 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1214 /* Every pass should have a name so that plugins can refer to them. */
1215 gcc_assert (pass
->name
!= NULL
);
1217 add_pass_instance (pass
, false, initial_pass
);
1220 return &(*list
)->next
;
1223 /* List node for an inserted pass instance. We need to keep track of all
1224 the newly-added pass instances (with 'added_pass_nodes' defined below)
1225 so that we can register their dump files after pass-positioning is finished.
1226 Registering dumping files needs to be post-processed or the
1227 static_pass_number of the opt_pass object would be modified and mess up
1228 the dump file names of future pass instances to be added. */
1230 struct pass_list_node
1233 struct pass_list_node
*next
;
1236 static struct pass_list_node
*added_pass_nodes
= NULL
;
1237 static struct pass_list_node
*prev_added_pass_node
;
1239 /* Insert the pass at the proper position. Return true if the pass
1240 is successfully added.
1242 NEW_PASS_INFO - new pass to be inserted
1243 PASS_LIST - root of the pass list to insert the new pass to */
1246 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1248 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1249 bool success
= false;
1251 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1253 /* Check if the current pass is of the same type as the new pass and
1254 matches the name and the instance number of the reference pass. */
1255 if (pass
->type
== new_pass_info
->pass
->type
1257 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1258 && ((new_pass_info
->ref_pass_instance_number
== 0)
1259 || (new_pass_info
->ref_pass_instance_number
==
1260 pass
->static_pass_number
)
1261 || (new_pass_info
->ref_pass_instance_number
== 1
1262 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1265 struct pass_list_node
*new_pass_node
;
1267 if (new_pass_info
->ref_pass_instance_number
== 0)
1269 new_pass
= new_pass_info
->pass
->clone ();
1270 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1274 new_pass
= new_pass_info
->pass
;
1275 add_pass_instance (new_pass
, true, new_pass
);
1278 /* Insert the new pass instance based on the positioning op. */
1279 switch (new_pass_info
->pos_op
)
1281 case PASS_POS_INSERT_AFTER
:
1282 new_pass
->next
= pass
->next
;
1283 pass
->next
= new_pass
;
1285 /* Skip newly inserted pass to avoid repeated
1286 insertions in the case where the new pass and the
1287 existing one have the same name. */
1290 case PASS_POS_INSERT_BEFORE
:
1291 new_pass
->next
= pass
;
1293 prev_pass
->next
= new_pass
;
1295 *pass_list
= new_pass
;
1297 case PASS_POS_REPLACE
:
1298 new_pass
->next
= pass
->next
;
1300 prev_pass
->next
= new_pass
;
1302 *pass_list
= new_pass
;
1303 new_pass
->sub
= pass
->sub
;
1304 new_pass
->tv_id
= pass
->tv_id
;
1308 error ("invalid pass positioning operation");
1312 /* Save the newly added pass (instance) in the added_pass_nodes
1313 list so that we can register its dump file later. Note that
1314 we cannot register the dump file now because doing so will modify
1315 the static_pass_number of the opt_pass object and therefore
1316 mess up the dump file name of future instances. */
1317 new_pass_node
= XCNEW (struct pass_list_node
);
1318 new_pass_node
->pass
= new_pass
;
1319 if (!added_pass_nodes
)
1320 added_pass_nodes
= new_pass_node
;
1322 prev_added_pass_node
->next
= new_pass_node
;
1323 prev_added_pass_node
= new_pass_node
;
1328 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1335 /* Hooks a new pass into the pass lists.
1337 PASS_INFO - pass information that specifies the opt_pass object,
1338 reference pass, instance number, and how to position
1342 register_pass (struct register_pass_info
*pass_info
)
1344 g
->get_passes ()->register_pass (pass_info
);
1348 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1349 const char* ref_pass_name
, int ref_pass_inst_number
)
1351 register_pass_info i
;
1353 i
.reference_pass_name
= ref_pass_name
;
1354 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1357 g
->get_passes ()->register_pass (&i
);
1361 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1363 bool all_instances
, success
;
1364 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1366 /* The checks below could fail in buggy plugins. Existing GCC
1367 passes should never fail these checks, so we mention plugin in
1369 if (!pass_info
->pass
)
1370 fatal_error ("plugin cannot register a missing pass");
1372 if (!pass_info
->pass
->name
)
1373 fatal_error ("plugin cannot register an unnamed pass");
1375 if (!pass_info
->reference_pass_name
)
1377 ("plugin cannot register pass %qs without reference pass name",
1378 pass_info
->pass
->name
);
1380 /* Try to insert the new pass to the pass lists. We need to check
1381 all five lists as the reference pass could be in one (or all) of
1383 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1384 success
= position_pass (pass_info
, &all_lowering_passes
);
1385 if (!success
|| all_instances
)
1386 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1387 if (!success
|| all_instances
)
1388 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1389 if (!success
|| all_instances
)
1390 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1391 if (!success
|| all_instances
)
1392 success
|= position_pass (pass_info
, &all_passes
);
1395 ("pass %qs not found but is referenced by new pass %qs",
1396 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1398 /* OK, we have successfully inserted the new pass. We need to register
1399 the dump files for the newly added pass and its duplicates (if any).
1400 Because the registration of plugin/backend passes happens after the
1401 command-line options are parsed, the options that specify single
1402 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1403 passes. Therefore we currently can only enable dumping of
1404 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1405 are specified. While doing so, we also delete the pass_list_node
1406 objects created during pass positioning. */
1407 while (added_pass_nodes
)
1409 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1410 enum tree_dump_index tdi
;
1411 register_one_dump_file (added_pass_nodes
->pass
);
1412 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1413 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1415 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1419 /* Check if dump-all flag is specified. */
1420 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1421 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1422 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1423 XDELETE (added_pass_nodes
);
1424 added_pass_nodes
= next_node
;
1428 /* Construct the pass tree. The sequencing of passes is driven by
1429 the cgraph routines:
1431 finalize_compilation_unit ()
1432 for each node N in the cgraph
1433 cgraph_analyze_function (N)
1434 cgraph_lower_function (N) -> all_lowering_passes
1436 If we are optimizing, compile is then invoked:
1439 ipa_passes () -> all_small_ipa_passes
1440 -> Analysis of all_regular_ipa_passes
1441 * possible LTO streaming at copmilation time *
1442 -> Execution of all_regular_ipa_passes
1443 * possible LTO streaming at link time *
1444 -> all_late_ipa_passes
1445 expand_all_functions ()
1446 for each node N in the cgraph
1447 expand_function (N) -> Transformation of all_regular_ipa_passes
1452 pass_manager::operator new (size_t sz
)
1454 /* Ensure that all fields of the pass manager are zero-initialized. */
1455 return xcalloc (1, sz
);
1458 pass_manager::pass_manager (context
*ctxt
)
1459 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1460 all_regular_ipa_passes (NULL
),
1461 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1466 /* Initialize the pass_lists array. */
1467 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1469 #undef DEF_PASS_LIST
1471 /* Build the tree of passes. */
1473 #define INSERT_PASSES_AFTER(PASS) \
1476 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1478 opt_pass **p = &(PASS ## _1)->sub;
1480 #define POP_INSERT_PASSES() \
1483 #define NEXT_PASS(PASS, NUM) \
1485 gcc_assert (NULL == PASS ## _ ## NUM); \
1487 PASS ## _1 = make_##PASS (m_ctxt); \
1490 gcc_assert (PASS ## _1); \
1491 PASS ## _ ## NUM = PASS ## _1->clone (); \
1493 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1496 #define TERMINATE_PASS_LIST() \
1499 #include "pass-instances.def"
1501 #undef INSERT_PASSES_AFTER
1502 #undef PUSH_INSERT_PASSES_WITHIN
1503 #undef POP_INSERT_PASSES
1505 #undef TERMINATE_PASS_LIST
1507 /* Register the passes with the tree dump code. */
1508 register_dump_files (all_lowering_passes
);
1509 register_dump_files (all_small_ipa_passes
);
1510 register_dump_files (all_regular_ipa_passes
);
1511 register_dump_files (all_late_ipa_passes
);
1512 register_dump_files (all_passes
);
1515 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1516 function CALLBACK for every function in the call graph. Otherwise,
1517 call CALLBACK on the current function. */
1520 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1522 if (current_function_decl
)
1523 callback (cfun
, data
);
1526 struct cgraph_node
*node
;
1527 FOR_EACH_DEFINED_FUNCTION (node
)
1528 if (node
->analyzed
&& (gimple_has_body_p (node
->decl
) && !in_lto_p
)
1529 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1530 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1534 /* Because inlining might remove no-longer reachable nodes, we need to
1535 keep the array visible to garbage collector to avoid reading collected
1538 static GTY ((length ("nnodes"))) cgraph_node
**order
;
1540 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1541 function CALLBACK for every function in the call graph. Otherwise,
1542 call CALLBACK on the current function.
1543 This function is global so that plugins can use it. */
1545 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1549 if (current_function_decl
)
1550 callback (cfun
, data
);
1553 gcc_assert (!order
);
1554 order
= ggc_vec_alloc
<cgraph_node
*> (symtab
->cgraph_count
);
1555 nnodes
= ipa_reverse_postorder (order
);
1556 for (i
= nnodes
- 1; i
>= 0; i
--)
1557 order
[i
]->process
= 1;
1558 for (i
= nnodes
- 1; i
>= 0; i
--)
1560 struct cgraph_node
*node
= order
[i
];
1562 /* Allow possibly removed nodes to be garbage collected. */
1565 if (node
->has_gimple_body_p ())
1566 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1574 /* Helper function to perform function body dump. */
1577 execute_function_dump (function
*fn
, void *data
)
1579 opt_pass
*pass
= (opt_pass
*)data
;
1585 if (fn
->curr_properties
& PROP_trees
)
1586 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1588 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1590 /* Flush the file. If verification fails, we won't be able to
1591 close the file before aborting. */
1594 if ((fn
->curr_properties
& PROP_cfg
)
1595 && (dump_flags
& TDF_GRAPH
))
1597 if (!pass
->graph_dump_initialized
)
1599 clean_graph_dump_file (dump_file_name
);
1600 pass
->graph_dump_initialized
= true;
1602 print_graph_cfg (dump_file_name
, fn
);
1609 static struct profile_record
*profile_record
;
1611 /* Do profile consistency book-keeping for the pass with static number INDEX.
1612 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1613 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1614 if we are only book-keeping on passes that may have selectively disabled
1615 themselves on a given function. */
1617 check_profile_consistency (int index
, int subpass
, bool run
)
1619 pass_manager
*passes
= g
->get_passes ();
1622 if (!profile_record
)
1623 profile_record
= XCNEWVEC (struct profile_record
,
1624 passes
->passes_by_id_size
);
1625 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1626 gcc_assert (subpass
< 2);
1627 profile_record
[index
].run
|= run
;
1628 account_profile_record (&profile_record
[index
], subpass
);
1631 /* Output profile consistency. */
1634 dump_profile_report (void)
1636 g
->get_passes ()->dump_profile_report ();
1640 pass_manager::dump_profile_report () const
1643 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1644 gcov_type last_time
= 0, last_size
= 0;
1645 double rel_time_change
, rel_size_change
;
1646 int last_reported
= 0;
1648 if (!profile_record
)
1650 fprintf (stderr
, "\nProfile consistency report:\n\n");
1651 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1652 fprintf (stderr
, " |freq count |freq count |size time\n");
1654 for (i
= 0; i
< passes_by_id_size
; i
++)
1655 for (j
= 0 ; j
< 2; j
++)
1656 if (profile_record
[i
].run
)
1659 rel_time_change
= (profile_record
[i
].time
[j
]
1660 - (double)last_time
) * 100 / (double)last_time
;
1662 rel_time_change
= 0;
1664 rel_size_change
= (profile_record
[i
].size
[j
]
1665 - (double)last_size
) * 100 / (double)last_size
;
1667 rel_size_change
= 0;
1669 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1670 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1671 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1672 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1673 || rel_time_change
|| rel_size_change
)
1676 fprintf (stderr
, "%-20s %s",
1677 passes_by_id
[i
]->name
,
1678 j
? "(after TODO)" : " ");
1679 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1680 fprintf (stderr
, "| %+5i",
1681 profile_record
[i
].num_mismatched_freq_in
[j
]
1684 fprintf (stderr
, "| ");
1685 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1686 fprintf (stderr
, " %+5i",
1687 profile_record
[i
].num_mismatched_count_in
[j
]
1690 fprintf (stderr
, " ");
1691 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1692 fprintf (stderr
, "| %+5i",
1693 profile_record
[i
].num_mismatched_freq_out
[j
]
1696 fprintf (stderr
, "| ");
1697 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1698 fprintf (stderr
, " %+5i",
1699 profile_record
[i
].num_mismatched_count_out
[j
]
1702 fprintf (stderr
, " ");
1704 /* Size/time units change across gimple and RTL. */
1705 if (i
== pass_expand_1
->static_pass_number
)
1706 fprintf (stderr
, "|----------");
1709 if (rel_size_change
)
1710 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1712 fprintf (stderr
, "| ");
1713 if (rel_time_change
)
1714 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1716 fprintf (stderr
, "\n");
1717 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1718 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1719 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1720 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1722 else if (j
&& last_reported
!= i
)
1725 fprintf (stderr
, "%-20s ------------| | |\n",
1726 passes_by_id
[i
]->name
);
1728 last_time
= profile_record
[i
].time
[j
];
1729 last_size
= profile_record
[i
].size
[j
];
1733 /* Perform all TODO actions that ought to be done on each function. */
1736 execute_function_todo (function
*fn
, void *data
)
1738 bool from_ipa_pass
= (cfun
== NULL
);
1739 unsigned int flags
= (size_t)data
;
1740 flags
&= ~fn
->last_verified
;
1746 /* Always cleanup the CFG before trying to update SSA. */
1747 if (flags
& TODO_cleanup_cfg
)
1749 cleanup_tree_cfg ();
1751 /* When cleanup_tree_cfg merges consecutive blocks, it may
1752 perform some simplistic propagation when removing single
1753 valued PHI nodes. This propagation may, in turn, cause the
1754 SSA form to become out-of-date (see PR 22037). So, even
1755 if the parent pass had not scheduled an SSA update, we may
1756 still need to do one. */
1757 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1758 flags
|= TODO_update_ssa
;
1761 if (flags
& TODO_update_ssa_any
)
1763 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1764 update_ssa (update_flags
);
1767 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1768 compute_may_aliases ();
1770 if (optimize
&& (flags
& TODO_update_address_taken
))
1771 execute_update_addresses_taken ();
1773 if (flags
& TODO_remove_unused_locals
)
1774 remove_unused_locals ();
1776 if (flags
& TODO_rebuild_frequencies
)
1777 rebuild_frequencies ();
1779 if (flags
& TODO_rebuild_cgraph_edges
)
1780 cgraph_edge::rebuild_edges ();
1782 /* If we've seen errors do not bother running any verifiers. */
1785 #if defined ENABLE_CHECKING
1786 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1787 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1789 if (flags
& TODO_verify_il
)
1791 if (cfun
->curr_properties
& PROP_trees
)
1793 if (cfun
->curr_properties
& PROP_cfg
)
1794 /* IPA passes leave stmts to be fixed up, so make sure to
1795 not verify stmts really throw. */
1796 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1798 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1800 if (cfun
->curr_properties
& PROP_ssa
)
1801 /* IPA passes leave stmts to be fixed up, so make sure to
1802 not verify SSA operands whose verifier will choke on that. */
1803 verify_ssa (true, !from_ipa_pass
);
1804 /* IPA passes leave basic-blocks unsplit, so make sure to
1805 not trip on that. */
1806 if ((cfun
->curr_properties
& PROP_cfg
)
1808 verify_flow_info ();
1810 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1811 verify_loop_closed_ssa (false);
1812 if (cfun
->curr_properties
& PROP_rtl
)
1813 verify_rtl_sharing ();
1816 /* Make sure verifiers don't change dominator state. */
1817 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1818 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1822 fn
->last_verified
= flags
& TODO_verify_all
;
1826 /* For IPA passes make sure to release dominator info, it can be
1827 computed by non-verifying TODOs. */
1830 free_dominance_info (fn
, CDI_DOMINATORS
);
1831 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1835 /* Perform all TODO actions. */
1837 execute_todo (unsigned int flags
)
1839 #if defined ENABLE_CHECKING
1841 && need_ssa_update_p (cfun
))
1842 gcc_assert (flags
& TODO_update_ssa_any
);
1845 timevar_push (TV_TODO
);
1847 /* Inform the pass whether it is the first time it is run. */
1848 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1850 statistics_fini_pass ();
1853 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1855 /* Always remove functions just as before inlining: IPA passes might be
1856 interested to see bodies of extern inline functions that are not inlined
1857 to analyze side effects. The full removal is done just at the end
1858 of IPA pass queue. */
1859 if (flags
& TODO_remove_functions
)
1862 symtab
->remove_unreachable_nodes (true, dump_file
);
1865 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1868 symtab_node::dump_table (dump_file
);
1869 /* Flush the file. If verification fails, we won't be able to
1870 close the file before aborting. */
1874 /* Now that the dumping has been done, we can get rid of the optional
1876 if (flags
& TODO_df_finish
)
1877 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1879 timevar_pop (TV_TODO
);
1882 /* Verify invariants that should hold between passes. This is a place
1883 to put simple sanity checks. */
1886 verify_interpass_invariants (void)
1888 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1891 /* Clear the last verified flag. */
1894 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
1896 fn
->last_verified
= 0;
1899 /* Helper function. Verify that the properties has been turn into the
1900 properties expected by the pass. */
1902 #ifdef ENABLE_CHECKING
1904 verify_curr_properties (function
*fn
, void *data
)
1906 unsigned int props
= (size_t)data
;
1907 gcc_assert ((fn
->curr_properties
& props
) == props
);
1911 /* Initialize pass dump file. */
1912 /* This is non-static so that the plugins can use it. */
1915 pass_init_dump_file (opt_pass
*pass
)
1917 /* If a dump file name is present, open it if enabled. */
1918 if (pass
->static_pass_number
!= -1)
1920 timevar_push (TV_DUMP
);
1921 gcc::dump_manager
*dumps
= g
->get_dumps ();
1922 bool initializing_dump
=
1923 !dumps
->dump_initialized_p (pass
->static_pass_number
);
1924 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
1925 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
1926 if (dump_file
&& current_function_decl
)
1927 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1928 if (initializing_dump
1929 && dump_file
&& (dump_flags
& TDF_GRAPH
)
1930 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1932 clean_graph_dump_file (dump_file_name
);
1933 pass
->graph_dump_initialized
= true;
1935 timevar_pop (TV_DUMP
);
1936 return initializing_dump
;
1942 /* Flush PASS dump file. */
1943 /* This is non-static so that plugins can use it. */
1946 pass_fini_dump_file (opt_pass
*pass
)
1948 timevar_push (TV_DUMP
);
1950 /* Flush and close dump file. */
1953 free (CONST_CAST (char *, dump_file_name
));
1954 dump_file_name
= NULL
;
1957 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
1958 timevar_pop (TV_DUMP
);
1961 /* After executing the pass, apply expected changes to the function
1965 update_properties_after_pass (function
*fn
, void *data
)
1967 opt_pass
*pass
= (opt_pass
*) data
;
1968 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
1969 & ~pass
->properties_destroyed
;
1972 /* Execute summary generation for all of the passes in IPA_PASS. */
1975 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
1979 opt_pass
*pass
= ipa_pass
;
1981 /* Execute all of the IPA_PASSes in the list. */
1982 if (ipa_pass
->type
== IPA_PASS
1983 && pass
->gate (cfun
)
1984 && ipa_pass
->generate_summary
)
1986 pass_init_dump_file (pass
);
1988 /* If a timevar is present, start it. */
1990 timevar_push (pass
->tv_id
);
1992 current_pass
= pass
;
1993 ipa_pass
->generate_summary ();
1997 timevar_pop (pass
->tv_id
);
1999 pass_fini_dump_file (pass
);
2001 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
2005 /* Execute IPA_PASS function transform on NODE. */
2008 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2009 ipa_opt_pass_d
*ipa_pass
)
2011 opt_pass
*pass
= ipa_pass
;
2012 unsigned int todo_after
= 0;
2014 current_pass
= pass
;
2015 if (!ipa_pass
->function_transform
)
2018 /* Note that the folders should only create gimple expressions.
2019 This is a hack until the new folder is ready. */
2020 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2022 pass_init_dump_file (pass
);
2024 /* Run pre-pass verification. */
2025 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2027 /* If a timevar is present, start it. */
2028 if (pass
->tv_id
!= TV_NONE
)
2029 timevar_push (pass
->tv_id
);
2032 todo_after
= ipa_pass
->function_transform (node
);
2035 if (pass
->tv_id
!= TV_NONE
)
2036 timevar_pop (pass
->tv_id
);
2038 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2039 check_profile_consistency (pass
->static_pass_number
, 0, true);
2041 /* Run post-pass cleanup and verification. */
2042 execute_todo (todo_after
);
2043 verify_interpass_invariants ();
2044 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2045 check_profile_consistency (pass
->static_pass_number
, 1, true);
2048 do_per_function (execute_function_dump
, NULL
);
2049 pass_fini_dump_file (pass
);
2051 current_pass
= NULL
;
2053 /* Signal this is a suitable GC collection point. */
2054 if (!(todo_after
& TODO_do_not_ggc_collect
))
2058 /* For the current function, execute all ipa transforms. */
2061 execute_all_ipa_transforms (void)
2063 struct cgraph_node
*node
;
2066 node
= cgraph_node::get (current_function_decl
);
2068 if (node
->ipa_transforms_to_apply
.exists ())
2072 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2073 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2074 node
->ipa_transforms_to_apply
.release ();
2078 /* Check if PASS is explicitly disabled or enabled and return
2079 the gate status. FUNC is the function to be processed, and
2080 GATE_STATUS is the gate status determined by pass manager by
2084 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2086 bool explicitly_enabled
= false;
2087 bool explicitly_disabled
= false;
2090 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2091 enabled_pass_uid_range_tab
);
2093 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2094 disabled_pass_uid_range_tab
);
2096 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2105 execute_one_pass (opt_pass
*pass
)
2107 unsigned int todo_after
= 0;
2111 /* IPA passes are executed on whole program, so cfun should be NULL.
2112 Other passes need function context set. */
2113 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2114 gcc_assert (!cfun
&& !current_function_decl
);
2116 gcc_assert (cfun
&& current_function_decl
);
2118 current_pass
= pass
;
2120 /* Check whether gate check should be avoided.
2121 User controls the value of the gate through the parameter "gate_status". */
2122 gate_status
= pass
->gate (cfun
);
2123 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2125 /* Override gate with plugin. */
2126 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2130 /* Run so passes selectively disabling themselves on a given function
2131 are not miscounted. */
2132 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2134 check_profile_consistency (pass
->static_pass_number
, 0, false);
2135 check_profile_consistency (pass
->static_pass_number
, 1, false);
2137 current_pass
= NULL
;
2141 /* Pass execution event trigger: useful to identify passes being
2143 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2145 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2146 Apply all trnasforms first. */
2147 if (pass
->type
== SIMPLE_IPA_PASS
)
2149 struct cgraph_node
*node
;
2150 bool applied
= false;
2151 FOR_EACH_DEFINED_FUNCTION (node
)
2153 && node
->has_gimple_body_p ()
2154 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
2156 if (!node
->global
.inlined_to
2157 && node
->ipa_transforms_to_apply
.exists ())
2160 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2161 execute_all_ipa_transforms ();
2162 cgraph_edge::rebuild_edges ();
2163 free_dominance_info (CDI_DOMINATORS
);
2164 free_dominance_info (CDI_POST_DOMINATORS
);
2170 symtab
->remove_unreachable_nodes (false, dump_file
);
2171 /* Restore current_pass. */
2172 current_pass
= pass
;
2175 if (!quiet_flag
&& !cfun
)
2176 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2178 /* Note that the folders should only create gimple expressions.
2179 This is a hack until the new folder is ready. */
2180 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2182 pass_init_dump_file (pass
);
2184 /* Run pre-pass verification. */
2185 execute_todo (pass
->todo_flags_start
);
2187 #ifdef ENABLE_CHECKING
2188 do_per_function (verify_curr_properties
,
2189 (void *)(size_t)pass
->properties_required
);
2192 /* If a timevar is present, start it. */
2193 if (pass
->tv_id
!= TV_NONE
)
2194 timevar_push (pass
->tv_id
);
2197 todo_after
= pass
->execute (cfun
);
2198 do_per_function (clear_last_verified
, NULL
);
2201 if (pass
->tv_id
!= TV_NONE
)
2202 timevar_pop (pass
->tv_id
);
2204 do_per_function (update_properties_after_pass
, pass
);
2206 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2207 check_profile_consistency (pass
->static_pass_number
, 0, true);
2209 /* Run post-pass cleanup and verification. */
2210 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2211 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2212 check_profile_consistency (pass
->static_pass_number
, 1, true);
2214 verify_interpass_invariants ();
2216 do_per_function (execute_function_dump
, pass
);
2217 if (pass
->type
== IPA_PASS
)
2219 struct cgraph_node
*node
;
2220 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2221 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2224 if (!current_function_decl
)
2225 symtab
->process_new_functions ();
2227 pass_fini_dump_file (pass
);
2229 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2230 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2231 || pass
->type
!= RTL_PASS
);
2233 current_pass
= NULL
;
2235 /* Signal this is a suitable GC collection point. */
2236 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2243 execute_pass_list_1 (opt_pass
*pass
)
2247 gcc_assert (pass
->type
== GIMPLE_PASS
2248 || pass
->type
== RTL_PASS
);
2249 if (execute_one_pass (pass
) && pass
->sub
)
2250 execute_pass_list_1 (pass
->sub
);
2257 execute_pass_list (function
*fn
, opt_pass
*pass
)
2260 execute_pass_list_1 (pass
);
2263 free_dominance_info (CDI_DOMINATORS
);
2264 free_dominance_info (CDI_POST_DOMINATORS
);
2269 /* Write out all LTO data. */
2273 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2275 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2276 timevar_push (TV_IPA_LTO_DECL_OUT
);
2277 produce_asm_for_decls ();
2278 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2281 /* Same as execute_pass_list but assume that subpasses of IPA passes
2282 are local passes. If SET is not NULL, write out summaries of only
2283 those node in SET. */
2286 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2290 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2291 gcc_assert (!current_function_decl
);
2293 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2294 if (pass
->type
== IPA_PASS
2295 && ipa_pass
->write_summary
2296 && pass
->gate (cfun
))
2298 /* If a timevar is present, start it. */
2300 timevar_push (pass
->tv_id
);
2302 pass_init_dump_file (pass
);
2304 current_pass
= pass
;
2305 ipa_pass
->write_summary ();
2307 pass_fini_dump_file (pass
);
2309 /* If a timevar is present, start it. */
2311 timevar_pop (pass
->tv_id
);
2314 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2315 ipa_write_summaries_2 (pass
->sub
, state
);
2321 /* Helper function of ipa_write_summaries. Creates and destroys the
2322 decl state and calls ipa_write_summaries_2 for all passes that have
2323 summaries. SET is the set of nodes to be written. */
2326 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2328 pass_manager
*passes
= g
->get_passes ();
2329 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2330 state
->symtab_node_encoder
= encoder
;
2332 lto_push_out_decl_state (state
);
2334 gcc_assert (!flag_wpa
);
2335 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2339 gcc_assert (lto_get_out_decl_state () == state
);
2340 lto_pop_out_decl_state ();
2341 lto_delete_out_decl_state (state
);
2344 /* Write out summaries for all the nodes in the callgraph. */
2347 ipa_write_summaries (void)
2349 lto_symtab_encoder_t encoder
;
2351 varpool_node
*vnode
;
2352 struct cgraph_node
*node
;
2353 struct cgraph_node
**order
;
2355 if (!flag_generate_lto
|| seen_error ())
2358 encoder
= lto_symtab_encoder_new (false);
2360 /* Create the callgraph set in the same order used in
2361 cgraph_expand_all_functions. This mostly facilitates debugging,
2362 since it causes the gimple file to be processed in the same order
2363 as the source code. */
2364 order
= XCNEWVEC (struct cgraph_node
*, symtab
->cgraph_count
);
2365 order_pos
= ipa_reverse_postorder (order
);
2366 gcc_assert (order_pos
== symtab
->cgraph_count
);
2368 for (i
= order_pos
- 1; i
>= 0; i
--)
2370 struct cgraph_node
*node
= order
[i
];
2372 if (node
->has_gimple_body_p ())
2374 /* When streaming out references to statements as part of some IPA
2375 pass summary, the statements need to have uids assigned and the
2376 following does that for all the IPA passes here. Naturally, this
2377 ordering then matches the one IPA-passes get in their stmt_fixup
2380 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2381 renumber_gimple_stmt_uids ();
2384 if (node
->definition
)
2385 lto_set_symtab_encoder_in_partition (encoder
, node
);
2388 FOR_EACH_DEFINED_FUNCTION (node
)
2390 lto_set_symtab_encoder_in_partition (encoder
, node
);
2391 FOR_EACH_DEFINED_VARIABLE (vnode
)
2392 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2394 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2399 /* Same as execute_pass_list but assume that subpasses of IPA passes
2400 are local passes. If SET is not NULL, write out optimization summaries of
2401 only those node in SET. */
2404 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2405 struct lto_out_decl_state
*state
)
2409 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2410 gcc_assert (!current_function_decl
);
2412 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2413 if (pass
->type
== IPA_PASS
2414 && ipa_pass
->write_optimization_summary
2415 && pass
->gate (cfun
))
2417 /* If a timevar is present, start it. */
2419 timevar_push (pass
->tv_id
);
2421 pass_init_dump_file (pass
);
2423 current_pass
= pass
;
2424 ipa_pass
->write_optimization_summary ();
2426 pass_fini_dump_file (pass
);
2428 /* If a timevar is present, start it. */
2430 timevar_pop (pass
->tv_id
);
2433 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2434 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2440 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2441 NULL, write out all summaries of all nodes. */
2444 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2446 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2447 lto_symtab_encoder_iterator lsei
;
2448 state
->symtab_node_encoder
= encoder
;
2450 lto_push_out_decl_state (state
);
2451 for (lsei
= lsei_start_function_in_partition (encoder
);
2452 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2454 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2455 /* When streaming out references to statements as part of some IPA
2456 pass summary, the statements need to have uids assigned.
2458 For functions newly born at WPA stage we need to initialize
2460 if (node
->definition
2461 && gimple_has_body_p (node
->decl
))
2463 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2464 renumber_gimple_stmt_uids ();
2469 gcc_assert (flag_wpa
);
2470 pass_manager
*passes
= g
->get_passes ();
2471 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2475 gcc_assert (lto_get_out_decl_state () == state
);
2476 lto_pop_out_decl_state ();
2477 lto_delete_out_decl_state (state
);
2480 /* Same as execute_pass_list but assume that subpasses of IPA passes
2481 are local passes. */
2484 ipa_read_summaries_1 (opt_pass
*pass
)
2488 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
);
2494 if (pass
->gate (cfun
))
2496 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2498 /* If a timevar is present, start it. */
2500 timevar_push (pass
->tv_id
);
2502 pass_init_dump_file (pass
);
2504 current_pass
= pass
;
2505 ipa_pass
->read_summary ();
2507 pass_fini_dump_file (pass
);
2511 timevar_pop (pass
->tv_id
);
2514 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2515 ipa_read_summaries_1 (pass
->sub
);
2522 /* Read all the summaries for all_regular_ipa_passes. */
2525 ipa_read_summaries (void)
2527 pass_manager
*passes
= g
->get_passes ();
2528 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2531 /* Same as execute_pass_list but assume that subpasses of IPA passes
2532 are local passes. */
2535 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2539 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2541 gcc_assert (!current_function_decl
);
2543 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2545 if (pass
->gate (cfun
))
2547 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2549 /* If a timevar is present, start it. */
2551 timevar_push (pass
->tv_id
);
2553 pass_init_dump_file (pass
);
2555 current_pass
= pass
;
2556 ipa_pass
->read_optimization_summary ();
2558 pass_fini_dump_file (pass
);
2562 timevar_pop (pass
->tv_id
);
2565 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2566 ipa_read_optimization_summaries_1 (pass
->sub
);
2572 /* Read all the summaries for all_regular_ipa_passes. */
2575 ipa_read_optimization_summaries (void)
2577 pass_manager
*passes
= g
->get_passes ();
2578 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2581 /* Same as execute_pass_list but assume that subpasses of IPA passes
2582 are local passes. */
2584 execute_ipa_pass_list (opt_pass
*pass
)
2588 gcc_assert (!current_function_decl
);
2590 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2591 if (execute_one_pass (pass
) && pass
->sub
)
2593 if (pass
->sub
->type
== GIMPLE_PASS
)
2595 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2596 do_per_function_toporder ((void (*)(function
*, void *))
2599 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2601 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2602 || pass
->sub
->type
== IPA_PASS
)
2603 execute_ipa_pass_list (pass
->sub
);
2607 gcc_assert (!current_function_decl
);
2608 symtab
->process_new_functions ();
2614 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2617 execute_ipa_stmt_fixups (opt_pass
*pass
,
2618 struct cgraph_node
*node
, gimple
*stmts
)
2622 /* Execute all of the IPA_PASSes in the list. */
2623 if (pass
->type
== IPA_PASS
2624 && pass
->gate (cfun
))
2626 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2628 if (ipa_pass
->stmt_fixup
)
2630 pass_init_dump_file (pass
);
2631 /* If a timevar is present, start it. */
2633 timevar_push (pass
->tv_id
);
2635 current_pass
= pass
;
2636 ipa_pass
->stmt_fixup (node
, stmts
);
2640 timevar_pop (pass
->tv_id
);
2641 pass_fini_dump_file (pass
);
2644 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2650 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2653 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2655 pass_manager
*passes
= g
->get_passes ();
2656 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2660 extern void debug_properties (unsigned int);
2661 extern void dump_properties (FILE *, unsigned int);
2664 dump_properties (FILE *dump
, unsigned int props
)
2666 fprintf (dump
, "Properties:\n");
2667 if (props
& PROP_gimple_any
)
2668 fprintf (dump
, "PROP_gimple_any\n");
2669 if (props
& PROP_gimple_lcf
)
2670 fprintf (dump
, "PROP_gimple_lcf\n");
2671 if (props
& PROP_gimple_leh
)
2672 fprintf (dump
, "PROP_gimple_leh\n");
2673 if (props
& PROP_cfg
)
2674 fprintf (dump
, "PROP_cfg\n");
2675 if (props
& PROP_ssa
)
2676 fprintf (dump
, "PROP_ssa\n");
2677 if (props
& PROP_no_crit_edges
)
2678 fprintf (dump
, "PROP_no_crit_edges\n");
2679 if (props
& PROP_rtl
)
2680 fprintf (dump
, "PROP_rtl\n");
2681 if (props
& PROP_gimple_lomp
)
2682 fprintf (dump
, "PROP_gimple_lomp\n");
2683 if (props
& PROP_gimple_lcx
)
2684 fprintf (dump
, "PROP_gimple_lcx\n");
2685 if (props
& PROP_gimple_lvec
)
2686 fprintf (dump
, "PROP_gimple_lvec\n");
2687 if (props
& PROP_cfglayout
)
2688 fprintf (dump
, "PROP_cfglayout\n");
2692 debug_properties (unsigned int props
)
2694 dump_properties (stderr
, props
);
2697 /* Called by local passes to see if function is called by already processed nodes.
2698 Because we process nodes in topological order, this means that function is
2699 in recursive cycle or we introduced new direct calls. */
2701 function_called_by_processed_nodes_p (void)
2703 struct cgraph_edge
*e
;
2704 for (e
= cgraph_node::get (current_function_decl
)->callers
;
2708 if (e
->caller
->decl
== current_function_decl
)
2710 if (!e
->caller
->has_gimple_body_p ())
2712 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2714 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2719 fprintf (dump_file
, "Already processed call to:\n");
2720 e
->caller
->dump (dump_file
);
2725 #include "gt-passes.h"