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"
46 #include "basic-block.h"
50 #include "diagnostic-core.h"
55 #include "langhooks.h"
57 #include "hosthooks.h"
60 #include "value-prof.h"
61 #include "tree-inline.h"
62 #include "tree-ssa-alias.h"
63 #include "internal-fn.h"
64 #include "gimple-expr.h"
67 #include "gimple-ssa.h"
69 #include "stringpool.h"
70 #include "tree-ssanames.h"
71 #include "tree-ssa-loop-manip.h"
72 #include "tree-into-ssa.h"
75 #include "tree-pass.h"
76 #include "tree-dump.h"
79 #include "lto-streamer.h"
81 #include "ipa-utils.h"
82 #include "tree-pretty-print.h" /* for dump_function_header */
84 #include "pass_manager.h"
85 #include "tree-ssa-live.h" /* For remove_unused_locals. */
86 #include "tree-cfgcleanup.h"
90 /* This is used for debugging. It allows the current pass to printed
91 from anywhere in compilation.
92 The variable current_pass is also used for statistics and plugins. */
93 opt_pass
*current_pass
;
95 static void register_pass_name (opt_pass
*, const char *);
97 /* Most passes are single-instance (within their context) and thus don't
98 need to implement cloning, but passes that support multiple instances
99 *must* provide their own implementation of the clone method.
101 Handle this by providing a default implemenation, but make it a fatal
107 internal_error ("pass %s does not support cloning", name
);
111 opt_pass::gate (function
*)
117 opt_pass::execute (function
*)
122 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
126 static_pass_number (0),
133 pass_manager::execute_early_local_passes ()
135 execute_pass_list (cfun
, pass_early_local_passes_1
->sub
);
139 pass_manager::execute_pass_mode_switching ()
141 return pass_mode_switching_1
->execute (cfun
);
145 /* Call from anywhere to find out what pass this is. Useful for
146 printing out debugging information deep inside an service
149 print_current_pass (FILE *file
)
152 fprintf (file
, "current pass = %s (%d)\n",
153 current_pass
->name
, current_pass
->static_pass_number
);
155 fprintf (file
, "no current pass.\n");
159 /* Call from the debugger to get the current pass name. */
163 print_current_pass (stderr
);
168 /* Global variables used to communicate with passes. */
170 bool first_pass_instance
;
173 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
176 This does nothing for local (non-static) variables, unless the
177 variable is a register variable with DECL_ASSEMBLER_NAME set. In
178 that case, or if the variable is not an automatic, it sets up the
179 RTL and outputs any assembler code (label definition, storage
180 allocation and initialization).
182 DECL is the declaration. TOP_LEVEL is nonzero
183 if this declaration is not within a function. */
186 rest_of_decl_compilation (tree decl
,
190 bool finalize
= true;
192 /* We deferred calling assemble_alias so that we could collect
193 other attributes such as visibility. Emit the alias now. */
197 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
200 alias
= TREE_VALUE (TREE_VALUE (alias
));
201 alias
= get_identifier (TREE_STRING_POINTER (alias
));
202 /* A quirk of the initial implementation of aliases required that the
203 user add "extern" to all of them. Which is silly, but now
204 historical. Do note that the symbol is in fact locally defined. */
205 DECL_EXTERNAL (decl
) = 0;
206 TREE_STATIC (decl
) = 1;
207 assemble_alias (decl
, alias
);
212 /* Can't defer this, because it needs to happen before any
213 later function definitions are processed. */
214 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
215 make_decl_rtl (decl
);
217 /* Forward declarations for nested functions are not "external",
218 but we need to treat them as if they were. */
219 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
220 || TREE_CODE (decl
) == FUNCTION_DECL
)
222 timevar_push (TV_VARCONST
);
224 /* Don't output anything when a tentative file-scope definition
225 is seen. But at end of compilation, do output code for them.
227 We do output all variables and rely on
228 callgraph code to defer them except for forward declarations
229 (see gcc.c-torture/compile/920624-1.c) */
231 || !DECL_DEFER_OUTPUT (decl
)
232 || DECL_INITIAL (decl
))
233 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
234 && !DECL_EXTERNAL (decl
))
236 /* When reading LTO unit, we also read varpool, so do not
238 if (in_lto_p
&& !at_end
)
240 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
241 varpool_finalize_decl (decl
);
244 #ifdef ASM_FINISH_DECLARE_OBJECT
245 if (decl
== last_assemble_variable_decl
)
247 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
252 timevar_pop (TV_VARCONST
);
254 else if (TREE_CODE (decl
) == TYPE_DECL
255 /* Like in rest_of_type_compilation, avoid confusing the debug
256 information machinery when there are errors. */
259 timevar_push (TV_SYMOUT
);
260 debug_hooks
->type_decl (decl
, !top_level
);
261 timevar_pop (TV_SYMOUT
);
264 /* Let cgraph know about the existence of variables. */
265 if (in_lto_p
&& !at_end
)
267 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
268 && TREE_STATIC (decl
))
269 varpool_node_for_decl (decl
);
272 /* Called after finishing a record, union or enumeral type. */
275 rest_of_type_compilation (tree type
, int toplev
)
277 /* Avoid confusing the debug information machinery when there are
282 timevar_push (TV_SYMOUT
);
283 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
284 timevar_pop (TV_SYMOUT
);
291 finish_optimization_passes (void)
294 struct dump_file_info
*dfi
;
296 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
298 timevar_push (TV_DUMP
);
299 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
301 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
303 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
308 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
309 print_combine_total_stats ();
310 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
313 /* Do whatever is necessary to finish printing the graphs. */
314 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
315 if (dumps
->dump_initialized_p (i
)
316 && (dfi
->pflags
& TDF_GRAPH
) != 0
317 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
319 finish_graph_dump_file (name
);
323 timevar_pop (TV_DUMP
);
327 execute_all_early_local_passes (void)
329 /* Once this pass (and its sub-passes) are complete, all functions
330 will be in SSA form. Technically this state change is happening
331 a tad early, since the sub-passes have not yet run, but since
332 none of the sub-passes are IPA passes and do not create new
333 functions, this is ok. We're setting this value for the benefit
334 of IPA passes that follow. */
335 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
336 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
342 const pass_data pass_data_early_local_passes
=
344 SIMPLE_IPA_PASS
, /* type */
345 "early_local_cleanups", /* name */
346 OPTGROUP_NONE
, /* optinfo_flags */
347 true, /* has_execute */
348 TV_EARLY_LOCAL
, /* tv_id */
349 0, /* properties_required */
350 0, /* properties_provided */
351 0, /* properties_destroyed */
352 0, /* todo_flags_start */
353 TODO_remove_functions
, /* todo_flags_finish */
356 class pass_early_local_passes
: public simple_ipa_opt_pass
359 pass_early_local_passes (gcc::context
*ctxt
)
360 : simple_ipa_opt_pass (pass_data_early_local_passes
, ctxt
)
363 /* opt_pass methods: */
364 virtual bool gate (function
*)
366 /* Don't bother doing anything if the program has errors. */
367 return (!seen_error () && !in_lto_p
);
370 virtual unsigned int execute (function
*)
372 return execute_all_early_local_passes ();
375 }; // class pass_early_local_passes
379 simple_ipa_opt_pass
*
380 make_pass_early_local_passes (gcc::context
*ctxt
)
382 return new pass_early_local_passes (ctxt
);
387 const pass_data pass_data_all_early_optimizations
=
389 GIMPLE_PASS
, /* type */
390 "early_optimizations", /* name */
391 OPTGROUP_NONE
, /* optinfo_flags */
392 false, /* has_execute */
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_all_early_optimizations
: public gimple_opt_pass
404 pass_all_early_optimizations (gcc::context
*ctxt
)
405 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
408 /* opt_pass methods: */
409 virtual bool gate (function
*)
411 return (optimize
>= 1
412 /* Don't bother doing anything if the program has errors. */
416 }; // class pass_all_early_optimizations
420 static gimple_opt_pass
*
421 make_pass_all_early_optimizations (gcc::context
*ctxt
)
423 return new pass_all_early_optimizations (ctxt
);
428 const pass_data pass_data_all_optimizations
=
430 GIMPLE_PASS
, /* type */
431 "*all_optimizations", /* name */
432 OPTGROUP_NONE
, /* optinfo_flags */
433 false, /* has_execute */
434 TV_OPTIMIZE
, /* tv_id */
435 0, /* properties_required */
436 0, /* properties_provided */
437 0, /* properties_destroyed */
438 0, /* todo_flags_start */
439 0, /* todo_flags_finish */
442 class pass_all_optimizations
: public gimple_opt_pass
445 pass_all_optimizations (gcc::context
*ctxt
)
446 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
449 /* opt_pass methods: */
450 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
452 }; // class pass_all_optimizations
456 static gimple_opt_pass
*
457 make_pass_all_optimizations (gcc::context
*ctxt
)
459 return new pass_all_optimizations (ctxt
);
464 const pass_data pass_data_all_optimizations_g
=
466 GIMPLE_PASS
, /* type */
467 "*all_optimizations_g", /* name */
468 OPTGROUP_NONE
, /* optinfo_flags */
469 false, /* has_execute */
470 TV_OPTIMIZE
, /* tv_id */
471 0, /* properties_required */
472 0, /* properties_provided */
473 0, /* properties_destroyed */
474 0, /* todo_flags_start */
475 0, /* todo_flags_finish */
478 class pass_all_optimizations_g
: public gimple_opt_pass
481 pass_all_optimizations_g (gcc::context
*ctxt
)
482 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
485 /* opt_pass methods: */
486 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
488 }; // class pass_all_optimizations_g
492 static gimple_opt_pass
*
493 make_pass_all_optimizations_g (gcc::context
*ctxt
)
495 return new pass_all_optimizations_g (ctxt
);
500 const pass_data pass_data_rest_of_compilation
=
503 "*rest_of_compilation", /* name */
504 OPTGROUP_NONE
, /* optinfo_flags */
505 false, /* has_execute */
506 TV_REST_OF_COMPILATION
, /* tv_id */
507 PROP_rtl
, /* properties_required */
508 0, /* properties_provided */
509 0, /* properties_destroyed */
510 0, /* todo_flags_start */
511 0, /* todo_flags_finish */
514 class pass_rest_of_compilation
: public rtl_opt_pass
517 pass_rest_of_compilation (gcc::context
*ctxt
)
518 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
521 /* opt_pass methods: */
522 virtual bool gate (function
*)
524 /* Early return if there were errors. We can run afoul of our
525 consistency checks, and there's not really much point in fixing them. */
526 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
529 }; // class pass_rest_of_compilation
533 static rtl_opt_pass
*
534 make_pass_rest_of_compilation (gcc::context
*ctxt
)
536 return new pass_rest_of_compilation (ctxt
);
541 const pass_data pass_data_postreload
=
544 "*all-postreload", /* name */
545 OPTGROUP_NONE
, /* optinfo_flags */
546 false, /* has_execute */
547 TV_POSTRELOAD
, /* tv_id */
548 PROP_rtl
, /* properties_required */
549 0, /* properties_provided */
550 0, /* properties_destroyed */
551 0, /* todo_flags_start */
552 TODO_verify_rtl_sharing
, /* todo_flags_finish */
555 class pass_postreload
: public rtl_opt_pass
558 pass_postreload (gcc::context
*ctxt
)
559 : rtl_opt_pass (pass_data_postreload
, ctxt
)
562 /* opt_pass methods: */
563 virtual bool gate (function
*) { return reload_completed
; }
565 }; // class pass_postreload
569 static rtl_opt_pass
*
570 make_pass_postreload (gcc::context
*ctxt
)
572 return new pass_postreload (ctxt
);
577 /* Set the static pass number of pass PASS to ID and record that
578 in the mapping from static pass number to pass. */
582 set_pass_for_id (int id
, opt_pass
*pass
)
584 pass
->static_pass_number
= id
;
585 if (passes_by_id_size
<= id
)
587 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
588 memset (passes_by_id
+ passes_by_id_size
, 0,
589 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
590 passes_by_id_size
= id
+ 1;
592 passes_by_id
[id
] = pass
;
595 /* Return the pass with the static pass number ID. */
598 pass_manager::get_pass_for_id (int id
) const
600 if (id
>= passes_by_id_size
)
602 return passes_by_id
[id
];
605 /* Iterate over the pass tree allocating dump file numbers. We want
606 to do this depth first, and independent of whether the pass is
610 register_one_dump_file (opt_pass
*pass
)
612 g
->get_passes ()->register_one_dump_file (pass
);
616 pass_manager::register_one_dump_file (opt_pass
*pass
)
618 char *dot_name
, *flag_name
, *glob_name
;
619 const char *name
, *full_name
, *prefix
;
622 int optgroup_flags
= OPTGROUP_NONE
;
623 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
625 /* See below in next_pass_1. */
627 if (pass
->static_pass_number
!= -1)
628 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
629 ? 1 : pass
->static_pass_number
));
631 /* The name is both used to identify the pass for the purposes of plugins,
632 and to specify dump file name and option.
633 The latter two might want something short which is not quite unique; for
634 that reason, we may have a disambiguating prefix, followed by a space
635 to mark the start of the following dump file name / option string. */
636 name
= strchr (pass
->name
, ' ');
637 name
= name
? name
+ 1 : pass
->name
;
638 dot_name
= concat (".", name
, num
, NULL
);
639 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
643 optgroup_flags
|= OPTGROUP_IPA
;
645 else if (pass
->type
== GIMPLE_PASS
)
656 flag_name
= concat (prefix
, name
, num
, NULL
);
657 glob_name
= concat (prefix
, name
, NULL
);
658 optgroup_flags
|= pass
->optinfo_flags
;
659 /* For any passes that do not have an optgroup set, and which are not
660 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
661 any dump messages are emitted properly under -fopt-info(-optall). */
662 if (optgroup_flags
== OPTGROUP_NONE
)
663 optgroup_flags
= OPTGROUP_OTHER
;
664 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
666 set_pass_for_id (id
, pass
);
667 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
668 register_pass_name (pass
, full_name
);
669 free (CONST_CAST (char *, full_name
));
672 /* Register the dump files for the pass_manager starting at PASS. */
675 pass_manager::register_dump_files (opt_pass
*pass
)
679 if (pass
->name
&& pass
->name
[0] != '*')
680 register_one_dump_file (pass
);
683 register_dump_files (pass
->sub
);
692 const char* unique_name
;
696 /* Helper for pass_registry hash table. */
698 struct pass_registry_hasher
: typed_noop_remove
<pass_registry
>
700 typedef pass_registry value_type
;
701 typedef pass_registry compare_type
;
702 static inline hashval_t
hash (const value_type
*);
703 static inline bool equal (const value_type
*, const compare_type
*);
706 /* Pass registry hash function. */
709 pass_registry_hasher::hash (const value_type
*s
)
711 return htab_hash_string (s
->unique_name
);
714 /* Hash equal function */
717 pass_registry_hasher::equal (const value_type
*s1
, const compare_type
*s2
)
719 return !strcmp (s1
->unique_name
, s2
->unique_name
);
722 static hash_table
<pass_registry_hasher
> name_to_pass_map
;
724 /* Register PASS with NAME. */
727 register_pass_name (opt_pass
*pass
, const char *name
)
729 struct pass_registry
**slot
;
730 struct pass_registry pr
;
732 if (!name_to_pass_map
.is_created ())
733 name_to_pass_map
.create (256);
735 pr
.unique_name
= name
;
736 slot
= name_to_pass_map
.find_slot (&pr
, INSERT
);
739 struct pass_registry
*new_pr
;
741 new_pr
= XCNEW (struct pass_registry
);
742 new_pr
->unique_name
= xstrdup (name
);
747 return; /* Ignore plugin passes. */
750 /* Map from pass id to canonicalized pass name. */
752 typedef const char *char_ptr
;
753 static vec
<char_ptr
> pass_tab
= vNULL
;
755 /* Callback function for traversing NAME_TO_PASS_MAP. */
758 passes_pass_traverse (pass_registry
**p
, void *data ATTRIBUTE_UNUSED
)
760 opt_pass
*pass
= (*p
)->pass
;
762 gcc_assert (pass
->static_pass_number
> 0);
763 gcc_assert (pass_tab
.exists ());
765 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
770 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
771 table for dumping purpose. */
774 create_pass_tab (void)
776 if (!flag_dump_passes
)
779 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
780 name_to_pass_map
.traverse
<void *, passes_pass_traverse
> (NULL
);
783 static bool override_gate_status (opt_pass
*, tree
, bool);
785 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
786 is turned on or not. */
789 dump_one_pass (opt_pass
*pass
, int pass_indent
)
791 int indent
= 3 * pass_indent
;
793 bool is_on
, is_really_on
;
795 is_on
= pass
->gate (cfun
);
796 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
798 if (pass
->static_pass_number
<= 0)
801 pn
= pass_tab
[pass
->static_pass_number
];
803 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
804 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
805 is_on
? " ON" : " OFF",
806 ((!is_on
) == (!is_really_on
) ? ""
807 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
810 /* Dump pass list PASS with indentation INDENT. */
813 dump_pass_list (opt_pass
*pass
, int indent
)
817 dump_one_pass (pass
, indent
);
819 dump_pass_list (pass
->sub
, indent
+ 1);
825 /* Dump all optimization passes. */
830 g
->get_passes ()->dump_passes ();
834 pass_manager::dump_passes () const
836 struct cgraph_node
*n
, *node
= NULL
;
840 FOR_EACH_FUNCTION (n
)
841 if (DECL_STRUCT_FUNCTION (n
->decl
))
850 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
852 dump_pass_list (all_lowering_passes
, 1);
853 dump_pass_list (all_small_ipa_passes
, 1);
854 dump_pass_list (all_regular_ipa_passes
, 1);
855 dump_pass_list (all_late_ipa_passes
, 1);
856 dump_pass_list (all_passes
, 1);
862 /* Returns the pass with NAME. */
865 get_pass_by_name (const char *name
)
867 struct pass_registry
**slot
, pr
;
869 pr
.unique_name
= name
;
870 slot
= name_to_pass_map
.find_slot (&pr
, NO_INSERT
);
875 return (*slot
)->pass
;
879 /* Range [start, last]. */
885 const char *assem_name
;
886 struct uid_range
*next
;
889 typedef struct uid_range
*uid_range_p
;
892 static vec
<uid_range_p
>
893 enabled_pass_uid_range_tab
= vNULL
;
894 static vec
<uid_range_p
>
895 disabled_pass_uid_range_tab
= vNULL
;
898 /* Parse option string for -fdisable- and -fenable-
899 The syntax of the options:
902 -fdisable-<pass_name>
904 -fenable-<pass_name>=s1:e1,s2:e2,...
905 -fdisable-<pass_name>=s1:e1,s2:e2,...
909 enable_disable_pass (const char *arg
, bool is_enable
)
912 char *range_str
, *phase_name
;
913 char *argstr
= xstrdup (arg
);
914 vec
<uid_range_p
> *tab
= 0;
916 range_str
= strchr (argstr
,'=');
927 error ("unrecognized option -fenable");
929 error ("unrecognized option -fdisable");
933 pass
= get_pass_by_name (phase_name
);
934 if (!pass
|| pass
->static_pass_number
== -1)
937 error ("unknown pass %s specified in -fenable", phase_name
);
939 error ("unknown pass %s specified in -fdisable", phase_name
);
945 tab
= &enabled_pass_uid_range_tab
;
947 tab
= &disabled_pass_uid_range_tab
;
949 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
950 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
955 uid_range_p new_range
= XCNEW (struct uid_range
);
957 new_range
->start
= 0;
958 new_range
->last
= (unsigned)-1;
960 slot
= (*tab
)[pass
->static_pass_number
];
961 new_range
->next
= slot
;
962 (*tab
)[pass
->static_pass_number
] = new_range
;
964 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
965 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
967 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
968 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
972 char *next_range
= NULL
;
973 char *one_range
= range_str
;
974 char *end_val
= NULL
;
979 uid_range_p new_range
;
980 char *invalid
= NULL
;
982 char *func_name
= NULL
;
984 next_range
= strchr (one_range
, ',');
991 end_val
= strchr (one_range
, ':');
997 start
= strtol (one_range
, &invalid
, 10);
998 if (*invalid
|| start
< 0)
1000 if (end_val
|| (one_range
[0] >= '0'
1001 && one_range
[0] <= '9'))
1003 error ("Invalid range %s in option %s",
1005 is_enable
? "-fenable" : "-fdisable");
1009 func_name
= one_range
;
1013 new_range
= XCNEW (struct uid_range
);
1016 new_range
->start
= (unsigned) start
;
1017 new_range
->last
= (unsigned) start
;
1021 new_range
->start
= (unsigned) -1;
1022 new_range
->last
= (unsigned) -1;
1023 new_range
->assem_name
= xstrdup (func_name
);
1028 long last
= strtol (end_val
, &invalid
, 10);
1029 if (*invalid
|| last
< start
)
1031 error ("Invalid range %s in option %s",
1033 is_enable
? "-fenable" : "-fdisable");
1037 new_range
= XCNEW (struct uid_range
);
1038 new_range
->start
= (unsigned) start
;
1039 new_range
->last
= (unsigned) last
;
1042 slot
= (*tab
)[pass
->static_pass_number
];
1043 new_range
->next
= slot
;
1044 (*tab
)[pass
->static_pass_number
] = new_range
;
1047 if (new_range
->assem_name
)
1048 inform (UNKNOWN_LOCATION
,
1049 "enable pass %s for function %s",
1050 phase_name
, new_range
->assem_name
);
1052 inform (UNKNOWN_LOCATION
,
1053 "enable pass %s for functions in the range of [%u, %u]",
1054 phase_name
, new_range
->start
, new_range
->last
);
1058 if (new_range
->assem_name
)
1059 inform (UNKNOWN_LOCATION
,
1060 "disable pass %s for function %s",
1061 phase_name
, new_range
->assem_name
);
1063 inform (UNKNOWN_LOCATION
,
1064 "disable pass %s for functions in the range of [%u, %u]",
1065 phase_name
, new_range
->start
, new_range
->last
);
1068 one_range
= next_range
;
1069 } while (next_range
);
1075 /* Enable pass specified by ARG. */
1078 enable_pass (const char *arg
)
1080 enable_disable_pass (arg
, true);
1083 /* Disable pass specified by ARG. */
1086 disable_pass (const char *arg
)
1088 enable_disable_pass (arg
, false);
1091 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1094 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1096 vec
<uid_range_p
> tab
)
1098 uid_range_p slot
, range
;
1100 const char *aname
= NULL
;
1103 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1104 || pass
->static_pass_number
== -1)
1107 slot
= tab
[pass
->static_pass_number
];
1111 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
1112 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1113 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1118 if ((unsigned) cgraph_uid
>= range
->start
1119 && (unsigned) cgraph_uid
<= range
->last
)
1121 if (range
->assem_name
&& aname
1122 && !strcmp (range
->assem_name
, aname
))
1124 range
= range
->next
;
1131 /* Update static_pass_number for passes (and the flag
1132 TODO_mark_first_instance).
1134 Passes are constructed with static_pass_number preinitialized to 0
1136 This field is used in two different ways: initially as instance numbers
1137 of their kind, and then as ids within the entire pass manager.
1139 Within pass_manager::pass_manager:
1141 * In add_pass_instance(), as called by next_pass_1 in
1142 NEXT_PASS in init_optimization_passes
1144 * When the initial instance of a pass within a pass manager is seen,
1145 it is flagged, and its static_pass_number is set to -1
1147 * On subsequent times that it is seen, the static pass number
1148 is decremented each time, so that if there are e.g. 4 dups,
1149 they have static_pass_number -4, 2, 3, 4 respectively (note
1150 how the initial one is negative and gives the count); these
1151 can be thought of as instance numbers of the specific pass
1153 * Within the register_dump_files () traversal, set_pass_for_id()
1154 is called on each pass, using these instance numbers to create
1155 dumpfile switches, and then overwriting them with a pass id,
1156 which are global to the whole pass manager (based on
1157 (TDI_end + current value of extra_dump_files_in_use) ) */
1160 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1161 opt_pass
*initial_pass
)
1163 /* Are we dealing with the first pass of its kind, or a clone? */
1164 if (new_pass
!= initial_pass
)
1166 /* We're dealing with a clone. */
1167 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1169 /* Indicate to register_dump_files that this pass has duplicates,
1170 and so it should rename the dump file. The first instance will
1171 be -1, and be number of duplicates = -static_pass_number - 1.
1172 Subsequent instances will be > 0 and just the duplicate number. */
1173 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1175 initial_pass
->static_pass_number
-= 1;
1176 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1181 /* We're dealing with the first pass of its kind. */
1182 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1183 new_pass
->static_pass_number
= -1;
1185 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1189 /* Add a pass to the pass list. Duplicate the pass if it's already
1193 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1195 /* Every pass should have a name so that plugins can refer to them. */
1196 gcc_assert (pass
->name
!= NULL
);
1198 add_pass_instance (pass
, false, initial_pass
);
1201 return &(*list
)->next
;
1204 /* List node for an inserted pass instance. We need to keep track of all
1205 the newly-added pass instances (with 'added_pass_nodes' defined below)
1206 so that we can register their dump files after pass-positioning is finished.
1207 Registering dumping files needs to be post-processed or the
1208 static_pass_number of the opt_pass object would be modified and mess up
1209 the dump file names of future pass instances to be added. */
1211 struct pass_list_node
1214 struct pass_list_node
*next
;
1217 static struct pass_list_node
*added_pass_nodes
= NULL
;
1218 static struct pass_list_node
*prev_added_pass_node
;
1220 /* Insert the pass at the proper position. Return true if the pass
1221 is successfully added.
1223 NEW_PASS_INFO - new pass to be inserted
1224 PASS_LIST - root of the pass list to insert the new pass to */
1227 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1229 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1230 bool success
= false;
1232 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1234 /* Check if the current pass is of the same type as the new pass and
1235 matches the name and the instance number of the reference pass. */
1236 if (pass
->type
== new_pass_info
->pass
->type
1238 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1239 && ((new_pass_info
->ref_pass_instance_number
== 0)
1240 || (new_pass_info
->ref_pass_instance_number
==
1241 pass
->static_pass_number
)
1242 || (new_pass_info
->ref_pass_instance_number
== 1
1243 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1246 struct pass_list_node
*new_pass_node
;
1248 if (new_pass_info
->ref_pass_instance_number
== 0)
1250 new_pass
= new_pass_info
->pass
->clone ();
1251 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1255 new_pass
= new_pass_info
->pass
;
1256 add_pass_instance (new_pass
, true, new_pass
);
1259 /* Insert the new pass instance based on the positioning op. */
1260 switch (new_pass_info
->pos_op
)
1262 case PASS_POS_INSERT_AFTER
:
1263 new_pass
->next
= pass
->next
;
1264 pass
->next
= new_pass
;
1266 /* Skip newly inserted pass to avoid repeated
1267 insertions in the case where the new pass and the
1268 existing one have the same name. */
1271 case PASS_POS_INSERT_BEFORE
:
1272 new_pass
->next
= pass
;
1274 prev_pass
->next
= new_pass
;
1276 *pass_list
= new_pass
;
1278 case PASS_POS_REPLACE
:
1279 new_pass
->next
= pass
->next
;
1281 prev_pass
->next
= new_pass
;
1283 *pass_list
= new_pass
;
1284 new_pass
->sub
= pass
->sub
;
1285 new_pass
->tv_id
= pass
->tv_id
;
1289 error ("invalid pass positioning operation");
1293 /* Save the newly added pass (instance) in the added_pass_nodes
1294 list so that we can register its dump file later. Note that
1295 we cannot register the dump file now because doing so will modify
1296 the static_pass_number of the opt_pass object and therefore
1297 mess up the dump file name of future instances. */
1298 new_pass_node
= XCNEW (struct pass_list_node
);
1299 new_pass_node
->pass
= new_pass
;
1300 if (!added_pass_nodes
)
1301 added_pass_nodes
= new_pass_node
;
1303 prev_added_pass_node
->next
= new_pass_node
;
1304 prev_added_pass_node
= new_pass_node
;
1309 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1316 /* Hooks a new pass into the pass lists.
1318 PASS_INFO - pass information that specifies the opt_pass object,
1319 reference pass, instance number, and how to position
1323 register_pass (struct register_pass_info
*pass_info
)
1325 g
->get_passes ()->register_pass (pass_info
);
1329 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1330 const char* ref_pass_name
, int ref_pass_inst_number
)
1332 register_pass_info i
;
1334 i
.reference_pass_name
= ref_pass_name
;
1335 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1338 g
->get_passes ()->register_pass (&i
);
1342 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1344 bool all_instances
, success
;
1345 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1347 /* The checks below could fail in buggy plugins. Existing GCC
1348 passes should never fail these checks, so we mention plugin in
1350 if (!pass_info
->pass
)
1351 fatal_error ("plugin cannot register a missing pass");
1353 if (!pass_info
->pass
->name
)
1354 fatal_error ("plugin cannot register an unnamed pass");
1356 if (!pass_info
->reference_pass_name
)
1358 ("plugin cannot register pass %qs without reference pass name",
1359 pass_info
->pass
->name
);
1361 /* Try to insert the new pass to the pass lists. We need to check
1362 all five lists as the reference pass could be in one (or all) of
1364 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1365 success
= position_pass (pass_info
, &all_lowering_passes
);
1366 if (!success
|| all_instances
)
1367 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1368 if (!success
|| all_instances
)
1369 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1370 if (!success
|| all_instances
)
1371 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1372 if (!success
|| all_instances
)
1373 success
|= position_pass (pass_info
, &all_passes
);
1376 ("pass %qs not found but is referenced by new pass %qs",
1377 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1379 /* OK, we have successfully inserted the new pass. We need to register
1380 the dump files for the newly added pass and its duplicates (if any).
1381 Because the registration of plugin/backend passes happens after the
1382 command-line options are parsed, the options that specify single
1383 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1384 passes. Therefore we currently can only enable dumping of
1385 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1386 are specified. While doing so, we also delete the pass_list_node
1387 objects created during pass positioning. */
1388 while (added_pass_nodes
)
1390 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1391 enum tree_dump_index tdi
;
1392 register_one_dump_file (added_pass_nodes
->pass
);
1393 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1394 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1396 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1400 /* Check if dump-all flag is specified. */
1401 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1402 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1403 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1404 XDELETE (added_pass_nodes
);
1405 added_pass_nodes
= next_node
;
1409 /* Construct the pass tree. The sequencing of passes is driven by
1410 the cgraph routines:
1412 finalize_compilation_unit ()
1413 for each node N in the cgraph
1414 cgraph_analyze_function (N)
1415 cgraph_lower_function (N) -> all_lowering_passes
1417 If we are optimizing, compile is then invoked:
1420 ipa_passes () -> all_small_ipa_passes
1421 -> Analysis of all_regular_ipa_passes
1422 * possible LTO streaming at copmilation time *
1423 -> Execution of all_regular_ipa_passes
1424 * possible LTO streaming at link time *
1425 -> all_late_ipa_passes
1426 expand_all_functions ()
1427 for each node N in the cgraph
1428 expand_function (N) -> Transformation of all_regular_ipa_passes
1433 pass_manager::operator new (size_t sz
)
1435 /* Ensure that all fields of the pass manager are zero-initialized. */
1436 return xcalloc (1, sz
);
1439 pass_manager::pass_manager (context
*ctxt
)
1440 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1441 all_regular_ipa_passes (NULL
),
1442 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1447 /* Initialize the pass_lists array. */
1448 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1450 #undef DEF_PASS_LIST
1452 /* Build the tree of passes. */
1454 #define INSERT_PASSES_AFTER(PASS) \
1457 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1459 opt_pass **p = &(PASS ## _1)->sub;
1461 #define POP_INSERT_PASSES() \
1464 #define NEXT_PASS(PASS, NUM) \
1466 gcc_assert (NULL == PASS ## _ ## NUM); \
1468 PASS ## _1 = make_##PASS (m_ctxt); \
1471 gcc_assert (PASS ## _1); \
1472 PASS ## _ ## NUM = PASS ## _1->clone (); \
1474 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1477 #define TERMINATE_PASS_LIST() \
1480 #include "pass-instances.def"
1482 #undef INSERT_PASSES_AFTER
1483 #undef PUSH_INSERT_PASSES_WITHIN
1484 #undef POP_INSERT_PASSES
1486 #undef TERMINATE_PASS_LIST
1488 /* Register the passes with the tree dump code. */
1489 register_dump_files (all_lowering_passes
);
1490 register_dump_files (all_small_ipa_passes
);
1491 register_dump_files (all_regular_ipa_passes
);
1492 register_dump_files (all_late_ipa_passes
);
1493 register_dump_files (all_passes
);
1496 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1497 function CALLBACK for every function in the call graph. Otherwise,
1498 call CALLBACK on the current function. */
1501 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1503 if (current_function_decl
)
1504 callback (cfun
, data
);
1507 struct cgraph_node
*node
;
1508 FOR_EACH_DEFINED_FUNCTION (node
)
1509 if (node
->analyzed
&& gimple_has_body_p (node
->decl
)
1510 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1511 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1515 /* Because inlining might remove no-longer reachable nodes, we need to
1516 keep the array visible to garbage collector to avoid reading collected
1519 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1521 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1522 function CALLBACK for every function in the call graph. Otherwise,
1523 call CALLBACK on the current function.
1524 This function is global so that plugins can use it. */
1526 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1530 if (current_function_decl
)
1531 callback (cfun
, data
);
1534 gcc_assert (!order
);
1535 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1536 nnodes
= ipa_reverse_postorder (order
);
1537 for (i
= nnodes
- 1; i
>= 0; i
--)
1538 order
[i
]->process
= 1;
1539 for (i
= nnodes
- 1; i
>= 0; i
--)
1541 struct cgraph_node
*node
= order
[i
];
1543 /* Allow possibly removed nodes to be garbage collected. */
1546 if (cgraph_function_with_gimple_body_p (node
))
1547 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1555 /* Helper function to perform function body dump. */
1558 execute_function_dump (function
*fn
, void *data
)
1560 opt_pass
*pass
= (opt_pass
*)data
;
1566 if (fn
->curr_properties
& PROP_trees
)
1567 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1569 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1571 /* Flush the file. If verification fails, we won't be able to
1572 close the file before aborting. */
1575 if ((fn
->curr_properties
& PROP_cfg
)
1576 && (dump_flags
& TDF_GRAPH
))
1578 if (!pass
->graph_dump_initialized
)
1580 clean_graph_dump_file (dump_file_name
);
1581 pass
->graph_dump_initialized
= true;
1583 print_graph_cfg (dump_file_name
, fn
);
1590 static struct profile_record
*profile_record
;
1592 /* Do profile consistency book-keeping for the pass with static number INDEX.
1593 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1594 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1595 if we are only book-keeping on passes that may have selectively disabled
1596 themselves on a given function. */
1598 check_profile_consistency (int index
, int subpass
, bool run
)
1600 pass_manager
*passes
= g
->get_passes ();
1603 if (!profile_record
)
1604 profile_record
= XCNEWVEC (struct profile_record
,
1605 passes
->passes_by_id_size
);
1606 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1607 gcc_assert (subpass
< 2);
1608 profile_record
[index
].run
|= run
;
1609 account_profile_record (&profile_record
[index
], subpass
);
1612 /* Output profile consistency. */
1615 dump_profile_report (void)
1617 g
->get_passes ()->dump_profile_report ();
1621 pass_manager::dump_profile_report () const
1624 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1625 gcov_type last_time
= 0, last_size
= 0;
1626 double rel_time_change
, rel_size_change
;
1627 int last_reported
= 0;
1629 if (!profile_record
)
1631 fprintf (stderr
, "\nProfile consistency report:\n\n");
1632 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1633 fprintf (stderr
, " |freq count |freq count |size time\n");
1635 for (i
= 0; i
< passes_by_id_size
; i
++)
1636 for (j
= 0 ; j
< 2; j
++)
1637 if (profile_record
[i
].run
)
1640 rel_time_change
= (profile_record
[i
].time
[j
]
1641 - (double)last_time
) * 100 / (double)last_time
;
1643 rel_time_change
= 0;
1645 rel_size_change
= (profile_record
[i
].size
[j
]
1646 - (double)last_size
) * 100 / (double)last_size
;
1648 rel_size_change
= 0;
1650 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1651 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1652 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1653 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1654 || rel_time_change
|| rel_size_change
)
1657 fprintf (stderr
, "%-20s %s",
1658 passes_by_id
[i
]->name
,
1659 j
? "(after TODO)" : " ");
1660 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1661 fprintf (stderr
, "| %+5i",
1662 profile_record
[i
].num_mismatched_freq_in
[j
]
1665 fprintf (stderr
, "| ");
1666 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1667 fprintf (stderr
, " %+5i",
1668 profile_record
[i
].num_mismatched_count_in
[j
]
1671 fprintf (stderr
, " ");
1672 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1673 fprintf (stderr
, "| %+5i",
1674 profile_record
[i
].num_mismatched_freq_out
[j
]
1677 fprintf (stderr
, "| ");
1678 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1679 fprintf (stderr
, " %+5i",
1680 profile_record
[i
].num_mismatched_count_out
[j
]
1683 fprintf (stderr
, " ");
1685 /* Size/time units change across gimple and RTL. */
1686 if (i
== pass_expand_1
->static_pass_number
)
1687 fprintf (stderr
, "|----------");
1690 if (rel_size_change
)
1691 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1693 fprintf (stderr
, "| ");
1694 if (rel_time_change
)
1695 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1697 fprintf (stderr
, "\n");
1698 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1699 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1700 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1701 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1703 else if (j
&& last_reported
!= i
)
1706 fprintf (stderr
, "%-20s ------------| | |\n",
1707 passes_by_id
[i
]->name
);
1709 last_time
= profile_record
[i
].time
[j
];
1710 last_size
= profile_record
[i
].size
[j
];
1714 /* Perform all TODO actions that ought to be done on each function. */
1717 execute_function_todo (function
*fn
, void *data
)
1719 bool from_ipa_pass
= (cfun
== NULL
);
1720 unsigned int flags
= (size_t)data
;
1721 flags
&= ~fn
->last_verified
;
1727 /* Always cleanup the CFG before trying to update SSA. */
1728 if (flags
& TODO_cleanup_cfg
)
1730 cleanup_tree_cfg ();
1732 /* When cleanup_tree_cfg merges consecutive blocks, it may
1733 perform some simplistic propagation when removing single
1734 valued PHI nodes. This propagation may, in turn, cause the
1735 SSA form to become out-of-date (see PR 22037). So, even
1736 if the parent pass had not scheduled an SSA update, we may
1737 still need to do one. */
1738 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1739 flags
|= TODO_update_ssa
;
1742 if (flags
& TODO_update_ssa_any
)
1744 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1745 update_ssa (update_flags
);
1748 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1749 compute_may_aliases ();
1751 if (optimize
&& (flags
& TODO_update_address_taken
))
1752 execute_update_addresses_taken ();
1754 if (flags
& TODO_remove_unused_locals
)
1755 remove_unused_locals ();
1757 if (flags
& TODO_rebuild_frequencies
)
1758 rebuild_frequencies ();
1760 if (flags
& TODO_rebuild_cgraph_edges
)
1761 rebuild_cgraph_edges ();
1763 /* If we've seen errors do not bother running any verifiers. */
1766 #if defined ENABLE_CHECKING
1767 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1768 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1770 if (flags
& TODO_verify_il
)
1772 if (cfun
->curr_properties
& PROP_trees
)
1774 if (cfun
->curr_properties
& PROP_cfg
)
1775 /* IPA passes leave stmts to be fixed up, so make sure to
1776 not verify stmts really throw. */
1777 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1779 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1781 if (cfun
->curr_properties
& PROP_ssa
)
1782 /* IPA passes leave stmts to be fixed up, so make sure to
1783 not verify SSA operands whose verifier will choke on that. */
1784 verify_ssa (true, !from_ipa_pass
);
1785 /* IPA passes leave basic-blocks unsplit, so make sure to
1786 not trip on that. */
1787 if ((cfun
->curr_properties
& PROP_cfg
)
1789 verify_flow_info ();
1791 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1792 verify_loop_closed_ssa (false);
1793 if (cfun
->curr_properties
& PROP_rtl
)
1794 verify_rtl_sharing ();
1797 /* Make sure verifiers don't change dominator state. */
1798 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1799 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1803 fn
->last_verified
= flags
& TODO_verify_all
;
1807 /* For IPA passes make sure to release dominator info, it can be
1808 computed by non-verifying TODOs. */
1811 free_dominance_info (fn
, CDI_DOMINATORS
);
1812 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1816 /* Perform all TODO actions. */
1818 execute_todo (unsigned int flags
)
1820 #if defined ENABLE_CHECKING
1822 && need_ssa_update_p (cfun
))
1823 gcc_assert (flags
& TODO_update_ssa_any
);
1826 timevar_push (TV_TODO
);
1828 /* Inform the pass whether it is the first time it is run. */
1829 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1831 statistics_fini_pass ();
1834 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1836 /* Always remove functions just as before inlining: IPA passes might be
1837 interested to see bodies of extern inline functions that are not inlined
1838 to analyze side effects. The full removal is done just at the end
1839 of IPA pass queue. */
1840 if (flags
& TODO_remove_functions
)
1843 symtab_remove_unreachable_nodes (true, dump_file
);
1846 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1849 dump_symtab (dump_file
);
1850 /* Flush the file. If verification fails, we won't be able to
1851 close the file before aborting. */
1855 /* Now that the dumping has been done, we can get rid of the optional
1857 if (flags
& TODO_df_finish
)
1858 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1860 timevar_pop (TV_TODO
);
1863 /* Verify invariants that should hold between passes. This is a place
1864 to put simple sanity checks. */
1867 verify_interpass_invariants (void)
1869 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1872 /* Clear the last verified flag. */
1875 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
1877 fn
->last_verified
= 0;
1880 /* Helper function. Verify that the properties has been turn into the
1881 properties expected by the pass. */
1883 #ifdef ENABLE_CHECKING
1885 verify_curr_properties (function
*fn
, void *data
)
1887 unsigned int props
= (size_t)data
;
1888 gcc_assert ((fn
->curr_properties
& props
) == props
);
1892 /* Initialize pass dump file. */
1893 /* This is non-static so that the plugins can use it. */
1896 pass_init_dump_file (opt_pass
*pass
)
1898 pass
->graph_dump_initialized
= false;
1899 /* If a dump file name is present, open it if enabled. */
1900 if (pass
->static_pass_number
!= -1)
1902 timevar_push (TV_DUMP
);
1903 gcc::dump_manager
*dumps
= g
->get_dumps ();
1904 bool initializing_dump
=
1905 !dumps
->dump_initialized_p (pass
->static_pass_number
);
1906 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
1907 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
1908 if (dump_file
&& current_function_decl
)
1909 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1910 if (initializing_dump
1911 && dump_file
&& (dump_flags
& TDF_GRAPH
)
1912 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1914 clean_graph_dump_file (dump_file_name
);
1915 pass
->graph_dump_initialized
= true;
1917 timevar_pop (TV_DUMP
);
1918 return initializing_dump
;
1924 /* Flush PASS dump file. */
1925 /* This is non-static so that plugins can use it. */
1928 pass_fini_dump_file (opt_pass
*pass
)
1930 timevar_push (TV_DUMP
);
1932 /* Flush and close dump file. */
1935 free (CONST_CAST (char *, dump_file_name
));
1936 dump_file_name
= NULL
;
1939 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
1940 timevar_pop (TV_DUMP
);
1943 /* After executing the pass, apply expected changes to the function
1947 update_properties_after_pass (function
*fn
, void *data
)
1949 opt_pass
*pass
= (opt_pass
*) data
;
1950 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
1951 & ~pass
->properties_destroyed
;
1954 /* Execute summary generation for all of the passes in IPA_PASS. */
1957 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
1961 opt_pass
*pass
= ipa_pass
;
1963 /* Execute all of the IPA_PASSes in the list. */
1964 if (ipa_pass
->type
== IPA_PASS
1965 && pass
->gate (cfun
)
1966 && ipa_pass
->generate_summary
)
1968 pass_init_dump_file (pass
);
1970 /* If a timevar is present, start it. */
1972 timevar_push (pass
->tv_id
);
1974 ipa_pass
->generate_summary ();
1978 timevar_pop (pass
->tv_id
);
1980 pass_fini_dump_file (pass
);
1982 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
1986 /* Execute IPA_PASS function transform on NODE. */
1989 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
1990 ipa_opt_pass_d
*ipa_pass
)
1992 opt_pass
*pass
= ipa_pass
;
1993 unsigned int todo_after
= 0;
1995 current_pass
= pass
;
1996 if (!ipa_pass
->function_transform
)
1999 /* Note that the folders should only create gimple expressions.
2000 This is a hack until the new folder is ready. */
2001 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2003 pass_init_dump_file (pass
);
2005 /* Run pre-pass verification. */
2006 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2008 /* If a timevar is present, start it. */
2009 if (pass
->tv_id
!= TV_NONE
)
2010 timevar_push (pass
->tv_id
);
2013 todo_after
= ipa_pass
->function_transform (node
);
2016 if (pass
->tv_id
!= TV_NONE
)
2017 timevar_pop (pass
->tv_id
);
2019 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2020 check_profile_consistency (pass
->static_pass_number
, 0, true);
2022 /* Run post-pass cleanup and verification. */
2023 execute_todo (todo_after
);
2024 verify_interpass_invariants ();
2025 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2026 check_profile_consistency (pass
->static_pass_number
, 1, true);
2029 do_per_function (execute_function_dump
, NULL
);
2030 pass_fini_dump_file (pass
);
2032 current_pass
= NULL
;
2034 /* Signal this is a suitable GC collection point. */
2035 if (!(todo_after
& TODO_do_not_ggc_collect
))
2039 /* For the current function, execute all ipa transforms. */
2042 execute_all_ipa_transforms (void)
2044 struct cgraph_node
*node
;
2047 node
= cgraph_get_node (current_function_decl
);
2049 if (node
->ipa_transforms_to_apply
.exists ())
2053 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2054 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2055 node
->ipa_transforms_to_apply
.release ();
2059 /* Check if PASS is explicitly disabled or enabled and return
2060 the gate status. FUNC is the function to be processed, and
2061 GATE_STATUS is the gate status determined by pass manager by
2065 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2067 bool explicitly_enabled
= false;
2068 bool explicitly_disabled
= false;
2071 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2072 enabled_pass_uid_range_tab
);
2074 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2075 disabled_pass_uid_range_tab
);
2077 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2086 execute_one_pass (opt_pass
*pass
)
2088 unsigned int todo_after
= 0;
2092 /* IPA passes are executed on whole program, so cfun should be NULL.
2093 Other passes need function context set. */
2094 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2095 gcc_assert (!cfun
&& !current_function_decl
);
2097 gcc_assert (cfun
&& current_function_decl
);
2099 current_pass
= pass
;
2101 /* Check whether gate check should be avoided.
2102 User controls the value of the gate through the parameter "gate_status". */
2103 gate_status
= pass
->gate (cfun
);
2104 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2106 /* Override gate with plugin. */
2107 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2111 /* Run so passes selectively disabling themselves on a given function
2112 are not miscounted. */
2113 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2115 check_profile_consistency (pass
->static_pass_number
, 0, false);
2116 check_profile_consistency (pass
->static_pass_number
, 1, false);
2118 current_pass
= NULL
;
2122 /* Pass execution event trigger: useful to identify passes being
2124 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2126 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2127 Apply all trnasforms first. */
2128 if (pass
->type
== SIMPLE_IPA_PASS
)
2130 struct cgraph_node
*node
;
2131 bool applied
= false;
2132 FOR_EACH_DEFINED_FUNCTION (node
)
2134 && cgraph_function_with_gimple_body_p (node
)
2135 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
2137 if (!node
->global
.inlined_to
2138 && node
->ipa_transforms_to_apply
.exists ())
2140 cgraph_get_body (node
);
2141 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2142 execute_all_ipa_transforms ();
2143 rebuild_cgraph_edges ();
2144 free_dominance_info (CDI_DOMINATORS
);
2145 free_dominance_info (CDI_POST_DOMINATORS
);
2151 symtab_remove_unreachable_nodes (true, dump_file
);
2152 /* Restore current_pass. */
2153 current_pass
= pass
;
2156 if (!quiet_flag
&& !cfun
)
2157 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2159 /* Note that the folders should only create gimple expressions.
2160 This is a hack until the new folder is ready. */
2161 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2163 pass_init_dump_file (pass
);
2165 /* Run pre-pass verification. */
2166 execute_todo (pass
->todo_flags_start
);
2168 #ifdef ENABLE_CHECKING
2169 do_per_function (verify_curr_properties
,
2170 (void *)(size_t)pass
->properties_required
);
2173 /* If a timevar is present, start it. */
2174 if (pass
->tv_id
!= TV_NONE
)
2175 timevar_push (pass
->tv_id
);
2178 if (pass
->has_execute
)
2180 todo_after
= pass
->execute (cfun
);
2181 do_per_function (clear_last_verified
, NULL
);
2185 if (pass
->tv_id
!= TV_NONE
)
2186 timevar_pop (pass
->tv_id
);
2188 do_per_function (update_properties_after_pass
, pass
);
2190 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2191 check_profile_consistency (pass
->static_pass_number
, 0, true);
2193 /* Run post-pass cleanup and verification. */
2194 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2195 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2196 check_profile_consistency (pass
->static_pass_number
, 1, true);
2198 verify_interpass_invariants ();
2200 do_per_function (execute_function_dump
, pass
);
2201 if (pass
->type
== IPA_PASS
)
2203 struct cgraph_node
*node
;
2204 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2205 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2208 if (!current_function_decl
)
2209 cgraph_process_new_functions ();
2211 pass_fini_dump_file (pass
);
2213 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2214 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2215 || pass
->type
!= RTL_PASS
);
2217 current_pass
= NULL
;
2219 /* Signal this is a suitable GC collection point. */
2220 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2227 execute_pass_list_1 (opt_pass
*pass
)
2231 gcc_assert (pass
->type
== GIMPLE_PASS
2232 || pass
->type
== RTL_PASS
);
2233 if (execute_one_pass (pass
) && pass
->sub
)
2234 execute_pass_list_1 (pass
->sub
);
2241 execute_pass_list (function
*fn
, opt_pass
*pass
)
2244 execute_pass_list_1 (pass
);
2247 free_dominance_info (CDI_DOMINATORS
);
2248 free_dominance_info (CDI_POST_DOMINATORS
);
2253 /* Write out all LTO data. */
2257 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2259 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2260 timevar_push (TV_IPA_LTO_DECL_OUT
);
2261 produce_asm_for_decls ();
2262 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2265 /* Same as execute_pass_list but assume that subpasses of IPA passes
2266 are local passes. If SET is not NULL, write out summaries of only
2267 those node in SET. */
2270 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2274 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2275 gcc_assert (!current_function_decl
);
2277 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2278 if (pass
->type
== IPA_PASS
2279 && ipa_pass
->write_summary
2280 && pass
->gate (cfun
))
2282 /* If a timevar is present, start it. */
2284 timevar_push (pass
->tv_id
);
2286 pass_init_dump_file (pass
);
2288 ipa_pass
->write_summary ();
2290 pass_fini_dump_file (pass
);
2292 /* If a timevar is present, start it. */
2294 timevar_pop (pass
->tv_id
);
2297 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2298 ipa_write_summaries_2 (pass
->sub
, state
);
2304 /* Helper function of ipa_write_summaries. Creates and destroys the
2305 decl state and calls ipa_write_summaries_2 for all passes that have
2306 summaries. SET is the set of nodes to be written. */
2309 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2311 pass_manager
*passes
= g
->get_passes ();
2312 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2313 state
->symtab_node_encoder
= encoder
;
2315 lto_push_out_decl_state (state
);
2317 gcc_assert (!flag_wpa
);
2318 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2322 gcc_assert (lto_get_out_decl_state () == state
);
2323 lto_pop_out_decl_state ();
2324 lto_delete_out_decl_state (state
);
2327 /* Write out summaries for all the nodes in the callgraph. */
2330 ipa_write_summaries (void)
2332 lto_symtab_encoder_t encoder
;
2334 varpool_node
*vnode
;
2335 struct cgraph_node
*node
;
2336 struct cgraph_node
**order
;
2338 if (!flag_generate_lto
|| seen_error ())
2341 encoder
= lto_symtab_encoder_new (false);
2343 /* Create the callgraph set in the same order used in
2344 cgraph_expand_all_functions. This mostly facilitates debugging,
2345 since it causes the gimple file to be processed in the same order
2346 as the source code. */
2347 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2348 order_pos
= ipa_reverse_postorder (order
);
2349 gcc_assert (order_pos
== cgraph_n_nodes
);
2351 for (i
= order_pos
- 1; i
>= 0; i
--)
2353 struct cgraph_node
*node
= order
[i
];
2355 if (cgraph_function_with_gimple_body_p (node
))
2357 /* When streaming out references to statements as part of some IPA
2358 pass summary, the statements need to have uids assigned and the
2359 following does that for all the IPA passes here. Naturally, this
2360 ordering then matches the one IPA-passes get in their stmt_fixup
2363 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2364 renumber_gimple_stmt_uids ();
2367 if (node
->definition
)
2368 lto_set_symtab_encoder_in_partition (encoder
, node
);
2371 FOR_EACH_DEFINED_FUNCTION (node
)
2373 lto_set_symtab_encoder_in_partition (encoder
, node
);
2374 FOR_EACH_DEFINED_VARIABLE (vnode
)
2375 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2377 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2382 /* Same as execute_pass_list but assume that subpasses of IPA passes
2383 are local passes. If SET is not NULL, write out optimization summaries of
2384 only those node in SET. */
2387 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2388 struct lto_out_decl_state
*state
)
2392 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2393 gcc_assert (!current_function_decl
);
2395 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2396 if (pass
->type
== IPA_PASS
2397 && ipa_pass
->write_optimization_summary
2398 && pass
->gate (cfun
))
2400 /* If a timevar is present, start it. */
2402 timevar_push (pass
->tv_id
);
2404 pass_init_dump_file (pass
);
2406 ipa_pass
->write_optimization_summary ();
2408 pass_fini_dump_file (pass
);
2410 /* If a timevar is present, start it. */
2412 timevar_pop (pass
->tv_id
);
2415 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2416 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2422 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2423 NULL, write out all summaries of all nodes. */
2426 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2428 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2429 lto_symtab_encoder_iterator lsei
;
2430 state
->symtab_node_encoder
= encoder
;
2432 lto_push_out_decl_state (state
);
2433 for (lsei
= lsei_start_function_in_partition (encoder
);
2434 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2436 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2437 /* When streaming out references to statements as part of some IPA
2438 pass summary, the statements need to have uids assigned.
2440 For functions newly born at WPA stage we need to initialize
2442 if (node
->definition
2443 && gimple_has_body_p (node
->decl
))
2445 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2446 renumber_gimple_stmt_uids ();
2451 gcc_assert (flag_wpa
);
2452 pass_manager
*passes
= g
->get_passes ();
2453 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2457 gcc_assert (lto_get_out_decl_state () == state
);
2458 lto_pop_out_decl_state ();
2459 lto_delete_out_decl_state (state
);
2462 /* Same as execute_pass_list but assume that subpasses of IPA passes
2463 are local passes. */
2466 ipa_read_summaries_1 (opt_pass
*pass
)
2470 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2472 gcc_assert (!current_function_decl
);
2474 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2476 if (pass
->gate (cfun
))
2478 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2480 /* If a timevar is present, start it. */
2482 timevar_push (pass
->tv_id
);
2484 pass_init_dump_file (pass
);
2486 ipa_pass
->read_summary ();
2488 pass_fini_dump_file (pass
);
2492 timevar_pop (pass
->tv_id
);
2495 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2496 ipa_read_summaries_1 (pass
->sub
);
2503 /* Read all the summaries for all_regular_ipa_passes. */
2506 ipa_read_summaries (void)
2508 pass_manager
*passes
= g
->get_passes ();
2509 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2512 /* Same as execute_pass_list but assume that subpasses of IPA passes
2513 are local passes. */
2516 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2520 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2522 gcc_assert (!current_function_decl
);
2524 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2526 if (pass
->gate (cfun
))
2528 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2530 /* If a timevar is present, start it. */
2532 timevar_push (pass
->tv_id
);
2534 pass_init_dump_file (pass
);
2536 ipa_pass
->read_optimization_summary ();
2538 pass_fini_dump_file (pass
);
2542 timevar_pop (pass
->tv_id
);
2545 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2546 ipa_read_optimization_summaries_1 (pass
->sub
);
2552 /* Read all the summaries for all_regular_ipa_passes. */
2555 ipa_read_optimization_summaries (void)
2557 pass_manager
*passes
= g
->get_passes ();
2558 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2561 /* Same as execute_pass_list but assume that subpasses of IPA passes
2562 are local passes. */
2564 execute_ipa_pass_list (opt_pass
*pass
)
2568 gcc_assert (!current_function_decl
);
2570 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2571 if (execute_one_pass (pass
) && pass
->sub
)
2573 if (pass
->sub
->type
== GIMPLE_PASS
)
2575 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2576 do_per_function_toporder ((void (*)(function
*, void *))
2579 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2581 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2582 || pass
->sub
->type
== IPA_PASS
)
2583 execute_ipa_pass_list (pass
->sub
);
2587 gcc_assert (!current_function_decl
);
2588 cgraph_process_new_functions ();
2594 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2597 execute_ipa_stmt_fixups (opt_pass
*pass
,
2598 struct cgraph_node
*node
, gimple
*stmts
)
2602 /* Execute all of the IPA_PASSes in the list. */
2603 if (pass
->type
== IPA_PASS
2604 && pass
->gate (cfun
))
2606 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2608 if (ipa_pass
->stmt_fixup
)
2610 pass_init_dump_file (pass
);
2611 /* If a timevar is present, start it. */
2613 timevar_push (pass
->tv_id
);
2615 ipa_pass
->stmt_fixup (node
, stmts
);
2619 timevar_pop (pass
->tv_id
);
2620 pass_fini_dump_file (pass
);
2623 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2629 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2632 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2634 pass_manager
*passes
= g
->get_passes ();
2635 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2639 extern void debug_properties (unsigned int);
2640 extern void dump_properties (FILE *, unsigned int);
2643 dump_properties (FILE *dump
, unsigned int props
)
2645 fprintf (dump
, "Properties:\n");
2646 if (props
& PROP_gimple_any
)
2647 fprintf (dump
, "PROP_gimple_any\n");
2648 if (props
& PROP_gimple_lcf
)
2649 fprintf (dump
, "PROP_gimple_lcf\n");
2650 if (props
& PROP_gimple_leh
)
2651 fprintf (dump
, "PROP_gimple_leh\n");
2652 if (props
& PROP_cfg
)
2653 fprintf (dump
, "PROP_cfg\n");
2654 if (props
& PROP_ssa
)
2655 fprintf (dump
, "PROP_ssa\n");
2656 if (props
& PROP_no_crit_edges
)
2657 fprintf (dump
, "PROP_no_crit_edges\n");
2658 if (props
& PROP_rtl
)
2659 fprintf (dump
, "PROP_rtl\n");
2660 if (props
& PROP_gimple_lomp
)
2661 fprintf (dump
, "PROP_gimple_lomp\n");
2662 if (props
& PROP_gimple_lcx
)
2663 fprintf (dump
, "PROP_gimple_lcx\n");
2664 if (props
& PROP_gimple_lvec
)
2665 fprintf (dump
, "PROP_gimple_lvec\n");
2666 if (props
& PROP_cfglayout
)
2667 fprintf (dump
, "PROP_cfglayout\n");
2671 debug_properties (unsigned int props
)
2673 dump_properties (stderr
, props
);
2676 /* Called by local passes to see if function is called by already processed nodes.
2677 Because we process nodes in topological order, this means that function is
2678 in recursive cycle or we introduced new direct calls. */
2680 function_called_by_processed_nodes_p (void)
2682 struct cgraph_edge
*e
;
2683 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2687 if (e
->caller
->decl
== current_function_decl
)
2689 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2691 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2693 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2698 fprintf (dump_file
, "Already processed call to:\n");
2699 dump_cgraph_node (dump_file
, e
->caller
);
2704 #include "gt-passes.h"