1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987-2013 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"
30 #include "hash-table.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"
51 #include "diagnostic-core.h"
56 #include "langhooks.h"
58 #include "hosthooks.h"
62 #include "value-prof.h"
63 #include "tree-inline.h"
65 #include "tree-pass.h"
66 #include "tree-dump.h"
69 #include "lto-streamer.h"
71 #include "ipa-utils.h"
72 #include "tree-pretty-print.h" /* for dump_function_header */
74 #include "pass_manager.h"
75 #include "tree-ssa-live.h" /* For remove_unused_locals. */
76 #include "tree-cfgcleanup.h"
80 /* This is used for debugging. It allows the current pass to printed
81 from anywhere in compilation.
82 The variable current_pass is also used for statistics and plugins. */
83 struct opt_pass
*current_pass
;
85 static void register_pass_name (struct opt_pass
*, const char *);
87 /* Most passes are single-instance (within their context) and thus don't
88 need to implement cloning, but passes that support multiple instances
89 *must* provide their own implementation of the clone method.
91 Handle this by providing a default implemenation, but make it a fatal
97 internal_error ("pass %s does not support cloning", name
);
112 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
116 static_pass_number (0),
123 pass_manager::execute_early_local_passes ()
125 execute_pass_list (pass_early_local_passes_1
->sub
);
129 pass_manager::execute_pass_mode_switching ()
131 return pass_mode_switching_1
->execute ();
135 /* Call from anywhere to find out what pass this is. Useful for
136 printing out debugging information deep inside an service
139 print_current_pass (FILE *file
)
142 fprintf (file
, "current pass = %s (%d)\n",
143 current_pass
->name
, current_pass
->static_pass_number
);
145 fprintf (file
, "no current pass.\n");
149 /* Call from the debugger to get the current pass name. */
153 print_current_pass (stderr
);
158 /* Global variables used to communicate with passes. */
160 bool first_pass_instance
;
163 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
166 This does nothing for local (non-static) variables, unless the
167 variable is a register variable with DECL_ASSEMBLER_NAME set. In
168 that case, or if the variable is not an automatic, it sets up the
169 RTL and outputs any assembler code (label definition, storage
170 allocation and initialization).
172 DECL is the declaration. TOP_LEVEL is nonzero
173 if this declaration is not within a function. */
176 rest_of_decl_compilation (tree decl
,
180 /* We deferred calling assemble_alias so that we could collect
181 other attributes such as visibility. Emit the alias now. */
185 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
188 alias
= TREE_VALUE (TREE_VALUE (alias
));
189 alias
= get_identifier (TREE_STRING_POINTER (alias
));
190 /* A quirk of the initial implementation of aliases required that the
191 user add "extern" to all of them. Which is silly, but now
192 historical. Do note that the symbol is in fact locally defined. */
193 DECL_EXTERNAL (decl
) = 0;
194 TREE_STATIC (decl
) = 1;
195 assemble_alias (decl
, alias
);
199 /* Can't defer this, because it needs to happen before any
200 later function definitions are processed. */
201 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
202 make_decl_rtl (decl
);
204 /* Forward declarations for nested functions are not "external",
205 but we need to treat them as if they were. */
206 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
207 || TREE_CODE (decl
) == FUNCTION_DECL
)
209 timevar_push (TV_VARCONST
);
211 /* Don't output anything when a tentative file-scope definition
212 is seen. But at end of compilation, do output code for them.
214 We do output all variables and rely on
215 callgraph code to defer them except for forward declarations
216 (see gcc.c-torture/compile/920624-1.c) */
218 || !DECL_DEFER_OUTPUT (decl
)
219 || DECL_INITIAL (decl
))
220 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
221 && !DECL_EXTERNAL (decl
))
223 /* When reading LTO unit, we also read varpool, so do not
225 if (in_lto_p
&& !at_end
)
227 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
228 varpool_finalize_decl (decl
);
231 #ifdef ASM_FINISH_DECLARE_OBJECT
232 if (decl
== last_assemble_variable_decl
)
234 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
239 timevar_pop (TV_VARCONST
);
241 else if (TREE_CODE (decl
) == TYPE_DECL
242 /* Like in rest_of_type_compilation, avoid confusing the debug
243 information machinery when there are errors. */
246 timevar_push (TV_SYMOUT
);
247 debug_hooks
->type_decl (decl
, !top_level
);
248 timevar_pop (TV_SYMOUT
);
251 /* Let cgraph know about the existence of variables. */
252 if (in_lto_p
&& !at_end
)
254 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
255 && TREE_STATIC (decl
))
256 varpool_node_for_decl (decl
);
259 /* Called after finishing a record, union or enumeral type. */
262 rest_of_type_compilation (tree type
, int toplev
)
264 /* Avoid confusing the debug information machinery when there are
269 timevar_push (TV_SYMOUT
);
270 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
271 timevar_pop (TV_SYMOUT
);
278 finish_optimization_passes (void)
281 struct dump_file_info
*dfi
;
283 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
285 timevar_push (TV_DUMP
);
286 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
288 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
290 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
295 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
296 print_combine_total_stats ();
297 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
300 /* Do whatever is necessary to finish printing the graphs. */
301 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
302 if (dumps
->dump_initialized_p (i
)
303 && (dfi
->pflags
& TDF_GRAPH
) != 0
304 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
306 finish_graph_dump_file (name
);
310 timevar_pop (TV_DUMP
);
314 execute_all_early_local_passes (void)
316 /* Once this pass (and its sub-passes) are complete, all functions
317 will be in SSA form. Technically this state change is happening
318 a tad early, since the sub-passes have not yet run, but since
319 none of the sub-passes are IPA passes and do not create new
320 functions, this is ok. We're setting this value for the benefit
321 of IPA passes that follow. */
322 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
323 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
327 /* Gate: execute, or not, all of the non-trivial optimizations. */
330 gate_all_early_local_passes (void)
332 /* Don't bother doing anything if the program has errors. */
333 return (!seen_error () && !in_lto_p
);
338 const pass_data pass_data_early_local_passes
=
340 SIMPLE_IPA_PASS
, /* type */
341 "early_local_cleanups", /* name */
342 OPTGROUP_NONE
, /* optinfo_flags */
344 true, /* has_execute */
345 TV_EARLY_LOCAL
, /* tv_id */
346 0, /* properties_required */
347 0, /* properties_provided */
348 0, /* properties_destroyed */
349 0, /* todo_flags_start */
350 TODO_remove_functions
, /* todo_flags_finish */
353 class pass_early_local_passes
: public simple_ipa_opt_pass
356 pass_early_local_passes (gcc::context
*ctxt
)
357 : simple_ipa_opt_pass (pass_data_early_local_passes
, ctxt
)
360 /* opt_pass methods: */
361 bool gate () { return gate_all_early_local_passes (); }
362 unsigned int execute () { return execute_all_early_local_passes (); }
364 }; // class pass_early_local_passes
368 simple_ipa_opt_pass
*
369 make_pass_early_local_passes (gcc::context
*ctxt
)
371 return new pass_early_local_passes (ctxt
);
374 /* Gate: execute, or not, all of the non-trivial optimizations. */
377 gate_all_early_optimizations (void)
379 return (optimize
>= 1
380 /* Don't bother doing anything if the program has errors. */
386 const pass_data pass_data_all_early_optimizations
=
388 GIMPLE_PASS
, /* type */
389 "early_optimizations", /* name */
390 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 bool gate () { return gate_all_early_optimizations (); }
411 }; // class pass_all_early_optimizations
415 static gimple_opt_pass
*
416 make_pass_all_early_optimizations (gcc::context
*ctxt
)
418 return new pass_all_early_optimizations (ctxt
);
421 /* Gate: execute, or not, all of the non-trivial optimizations. */
424 gate_all_optimizations (void)
426 return optimize
>= 1 && !optimize_debug
;
431 const pass_data pass_data_all_optimizations
=
433 GIMPLE_PASS
, /* type */
434 "*all_optimizations", /* name */
435 OPTGROUP_NONE
, /* optinfo_flags */
437 false, /* has_execute */
438 TV_OPTIMIZE
, /* tv_id */
439 0, /* properties_required */
440 0, /* properties_provided */
441 0, /* properties_destroyed */
442 0, /* todo_flags_start */
443 0, /* todo_flags_finish */
446 class pass_all_optimizations
: public gimple_opt_pass
449 pass_all_optimizations (gcc::context
*ctxt
)
450 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
453 /* opt_pass methods: */
454 bool gate () { return gate_all_optimizations (); }
456 }; // class pass_all_optimizations
460 static gimple_opt_pass
*
461 make_pass_all_optimizations (gcc::context
*ctxt
)
463 return new pass_all_optimizations (ctxt
);
466 /* Gate: execute, or not, all of the non-trivial optimizations. */
469 gate_all_optimizations_g (void)
471 return optimize
>= 1 && optimize_debug
;
476 const pass_data pass_data_all_optimizations_g
=
478 GIMPLE_PASS
, /* type */
479 "*all_optimizations_g", /* name */
480 OPTGROUP_NONE
, /* optinfo_flags */
482 false, /* has_execute */
483 TV_OPTIMIZE
, /* tv_id */
484 0, /* properties_required */
485 0, /* properties_provided */
486 0, /* properties_destroyed */
487 0, /* todo_flags_start */
488 0, /* todo_flags_finish */
491 class pass_all_optimizations_g
: public gimple_opt_pass
494 pass_all_optimizations_g (gcc::context
*ctxt
)
495 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
498 /* opt_pass methods: */
499 bool gate () { return gate_all_optimizations_g (); }
501 }; // class pass_all_optimizations_g
505 static gimple_opt_pass
*
506 make_pass_all_optimizations_g (gcc::context
*ctxt
)
508 return new pass_all_optimizations_g (ctxt
);
512 gate_rest_of_compilation (void)
514 /* Early return if there were errors. We can run afoul of our
515 consistency checks, and there's not really much point in fixing them. */
516 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
521 const pass_data pass_data_rest_of_compilation
=
524 "*rest_of_compilation", /* name */
525 OPTGROUP_NONE
, /* optinfo_flags */
527 false, /* has_execute */
528 TV_REST_OF_COMPILATION
, /* tv_id */
529 PROP_rtl
, /* properties_required */
530 0, /* properties_provided */
531 0, /* properties_destroyed */
532 0, /* todo_flags_start */
533 0, /* todo_flags_finish */
536 class pass_rest_of_compilation
: public rtl_opt_pass
539 pass_rest_of_compilation (gcc::context
*ctxt
)
540 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
543 /* opt_pass methods: */
544 bool gate () { return gate_rest_of_compilation (); }
546 }; // class pass_rest_of_compilation
550 static rtl_opt_pass
*
551 make_pass_rest_of_compilation (gcc::context
*ctxt
)
553 return new pass_rest_of_compilation (ctxt
);
557 gate_postreload (void)
559 return reload_completed
;
564 const pass_data pass_data_postreload
=
567 "*all-postreload", /* name */
568 OPTGROUP_NONE
, /* optinfo_flags */
570 false, /* has_execute */
571 TV_POSTRELOAD
, /* tv_id */
572 PROP_rtl
, /* properties_required */
573 0, /* properties_provided */
574 0, /* properties_destroyed */
575 0, /* todo_flags_start */
576 TODO_verify_rtl_sharing
, /* todo_flags_finish */
579 class pass_postreload
: public rtl_opt_pass
582 pass_postreload (gcc::context
*ctxt
)
583 : rtl_opt_pass (pass_data_postreload
, ctxt
)
586 /* opt_pass methods: */
587 bool gate () { return gate_postreload (); }
589 }; // class pass_postreload
593 static rtl_opt_pass
*
594 make_pass_postreload (gcc::context
*ctxt
)
596 return new pass_postreload (ctxt
);
601 /* Set the static pass number of pass PASS to ID and record that
602 in the mapping from static pass number to pass. */
606 set_pass_for_id (int id
, struct opt_pass
*pass
)
608 pass
->static_pass_number
= id
;
609 if (passes_by_id_size
<= id
)
611 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
612 memset (passes_by_id
+ passes_by_id_size
, 0,
613 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
614 passes_by_id_size
= id
+ 1;
616 passes_by_id
[id
] = pass
;
619 /* Return the pass with the static pass number ID. */
622 pass_manager::get_pass_for_id (int id
) const
624 if (id
>= passes_by_id_size
)
626 return passes_by_id
[id
];
629 /* Iterate over the pass tree allocating dump file numbers. We want
630 to do this depth first, and independent of whether the pass is
634 register_one_dump_file (struct opt_pass
*pass
)
636 g
->get_passes ()->register_one_dump_file (pass
);
640 pass_manager::register_one_dump_file (struct opt_pass
*pass
)
642 char *dot_name
, *flag_name
, *glob_name
;
643 const char *name
, *full_name
, *prefix
;
646 int optgroup_flags
= OPTGROUP_NONE
;
647 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
649 /* See below in next_pass_1. */
651 if (pass
->static_pass_number
!= -1)
652 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
653 ? 1 : pass
->static_pass_number
));
655 /* The name is both used to identify the pass for the purposes of plugins,
656 and to specify dump file name and option.
657 The latter two might want something short which is not quite unique; for
658 that reason, we may have a disambiguating prefix, followed by a space
659 to mark the start of the following dump file name / option string. */
660 name
= strchr (pass
->name
, ' ');
661 name
= name
? name
+ 1 : pass
->name
;
662 dot_name
= concat (".", name
, num
, NULL
);
663 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
667 optgroup_flags
|= OPTGROUP_IPA
;
669 else if (pass
->type
== GIMPLE_PASS
)
680 flag_name
= concat (prefix
, name
, num
, NULL
);
681 glob_name
= concat (prefix
, name
, NULL
);
682 optgroup_flags
|= pass
->optinfo_flags
;
683 /* For any passes that do not have an optgroup set, and which are not
684 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
685 any dump messages are emitted properly under -fopt-info(-optall). */
686 if (optgroup_flags
== OPTGROUP_NONE
)
687 optgroup_flags
= OPTGROUP_OTHER
;
688 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
690 set_pass_for_id (id
, pass
);
691 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
692 register_pass_name (pass
, full_name
);
693 free (CONST_CAST (char *, full_name
));
696 /* Recursive worker function for register_dump_files. */
700 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
704 int new_properties
= (properties
| pass
->properties_provided
)
705 & ~pass
->properties_destroyed
;
707 if (pass
->name
&& pass
->name
[0] != '*')
708 register_one_dump_file (pass
);
711 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
713 /* If we have a gate, combine the properties that we could have with
714 and without the pass being examined. */
716 properties
&= new_properties
;
718 properties
= new_properties
;
727 /* Register the dump files for the pass_manager starting at PASS.
728 PROPERTIES reflects the properties that are guaranteed to be available at
729 the beginning of the pipeline. */
733 register_dump_files (struct opt_pass
*pass
,int properties
)
735 pass
->properties_required
|= properties
;
736 register_dump_files_1 (pass
, properties
);
741 const char* unique_name
;
742 struct opt_pass
*pass
;
745 /* Helper for pass_registry hash table. */
747 struct pass_registry_hasher
: typed_noop_remove
<pass_registry
>
749 typedef pass_registry value_type
;
750 typedef pass_registry compare_type
;
751 static inline hashval_t
hash (const value_type
*);
752 static inline bool equal (const value_type
*, const compare_type
*);
755 /* Pass registry hash function. */
758 pass_registry_hasher::hash (const value_type
*s
)
760 return htab_hash_string (s
->unique_name
);
763 /* Hash equal function */
766 pass_registry_hasher::equal (const value_type
*s1
, const compare_type
*s2
)
768 return !strcmp (s1
->unique_name
, s2
->unique_name
);
771 static hash_table
<pass_registry_hasher
> name_to_pass_map
;
773 /* Register PASS with NAME. */
776 register_pass_name (struct opt_pass
*pass
, const char *name
)
778 struct pass_registry
**slot
;
779 struct pass_registry pr
;
781 if (!name_to_pass_map
.is_created ())
782 name_to_pass_map
.create (256);
784 pr
.unique_name
= name
;
785 slot
= name_to_pass_map
.find_slot (&pr
, INSERT
);
788 struct pass_registry
*new_pr
;
790 new_pr
= XCNEW (struct pass_registry
);
791 new_pr
->unique_name
= xstrdup (name
);
796 return; /* Ignore plugin passes. */
799 /* Map from pass id to canonicalized pass name. */
801 typedef const char *char_ptr
;
802 static vec
<char_ptr
> pass_tab
= vNULL
;
804 /* Callback function for traversing NAME_TO_PASS_MAP. */
807 passes_pass_traverse (pass_registry
**p
, void *data ATTRIBUTE_UNUSED
)
809 struct opt_pass
*pass
= (*p
)->pass
;
811 gcc_assert (pass
->static_pass_number
> 0);
812 gcc_assert (pass_tab
.exists ());
814 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
819 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
820 table for dumping purpose. */
823 create_pass_tab (void)
825 if (!flag_dump_passes
)
828 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
829 name_to_pass_map
.traverse
<void *, passes_pass_traverse
> (NULL
);
832 static bool override_gate_status (struct opt_pass
*, tree
, bool);
834 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
835 is turned on or not. */
838 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
840 int indent
= 3 * pass_indent
;
842 bool is_on
, is_really_on
;
844 is_on
= pass
->has_gate
? pass
->gate () : true;
845 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
847 if (pass
->static_pass_number
<= 0)
850 pn
= pass_tab
[pass
->static_pass_number
];
852 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
853 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
854 is_on
? " ON" : " OFF",
855 ((!is_on
) == (!is_really_on
) ? ""
856 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
859 /* Dump pass list PASS with indentation INDENT. */
862 dump_pass_list (struct opt_pass
*pass
, int indent
)
866 dump_one_pass (pass
, indent
);
868 dump_pass_list (pass
->sub
, indent
+ 1);
874 /* Dump all optimization passes. */
879 g
->get_passes ()->dump_passes ();
883 pass_manager::dump_passes () const
885 struct cgraph_node
*n
, *node
= NULL
;
889 FOR_EACH_FUNCTION (n
)
890 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
899 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
901 dump_pass_list (all_lowering_passes
, 1);
902 dump_pass_list (all_small_ipa_passes
, 1);
903 dump_pass_list (all_regular_ipa_passes
, 1);
904 dump_pass_list (all_lto_gen_passes
, 1);
905 dump_pass_list (all_late_ipa_passes
, 1);
906 dump_pass_list (all_passes
, 1);
912 /* Returns the pass with NAME. */
914 static struct opt_pass
*
915 get_pass_by_name (const char *name
)
917 struct pass_registry
**slot
, pr
;
919 pr
.unique_name
= name
;
920 slot
= name_to_pass_map
.find_slot (&pr
, NO_INSERT
);
925 return (*slot
)->pass
;
929 /* Range [start, last]. */
935 const char *assem_name
;
936 struct uid_range
*next
;
939 typedef struct uid_range
*uid_range_p
;
942 static vec
<uid_range_p
>
943 enabled_pass_uid_range_tab
= vNULL
;
944 static vec
<uid_range_p
>
945 disabled_pass_uid_range_tab
= vNULL
;
948 /* Parse option string for -fdisable- and -fenable-
949 The syntax of the options:
952 -fdisable-<pass_name>
954 -fenable-<pass_name>=s1:e1,s2:e2,...
955 -fdisable-<pass_name>=s1:e1,s2:e2,...
959 enable_disable_pass (const char *arg
, bool is_enable
)
961 struct opt_pass
*pass
;
962 char *range_str
, *phase_name
;
963 char *argstr
= xstrdup (arg
);
964 vec
<uid_range_p
> *tab
= 0;
966 range_str
= strchr (argstr
,'=');
977 error ("unrecognized option -fenable");
979 error ("unrecognized option -fdisable");
983 pass
= get_pass_by_name (phase_name
);
984 if (!pass
|| pass
->static_pass_number
== -1)
987 error ("unknown pass %s specified in -fenable", phase_name
);
989 error ("unknown pass %s specified in -fdisable", phase_name
);
995 tab
= &enabled_pass_uid_range_tab
;
997 tab
= &disabled_pass_uid_range_tab
;
999 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1000 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1005 uid_range_p new_range
= XCNEW (struct uid_range
);
1007 new_range
->start
= 0;
1008 new_range
->last
= (unsigned)-1;
1010 slot
= (*tab
)[pass
->static_pass_number
];
1011 new_range
->next
= slot
;
1012 (*tab
)[pass
->static_pass_number
] = new_range
;
1014 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1015 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1017 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1018 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1022 char *next_range
= NULL
;
1023 char *one_range
= range_str
;
1024 char *end_val
= NULL
;
1029 uid_range_p new_range
;
1030 char *invalid
= NULL
;
1032 char *func_name
= NULL
;
1034 next_range
= strchr (one_range
, ',');
1041 end_val
= strchr (one_range
, ':');
1047 start
= strtol (one_range
, &invalid
, 10);
1048 if (*invalid
|| start
< 0)
1050 if (end_val
|| (one_range
[0] >= '0'
1051 && one_range
[0] <= '9'))
1053 error ("Invalid range %s in option %s",
1055 is_enable
? "-fenable" : "-fdisable");
1059 func_name
= one_range
;
1063 new_range
= XCNEW (struct uid_range
);
1066 new_range
->start
= (unsigned) start
;
1067 new_range
->last
= (unsigned) start
;
1071 new_range
->start
= (unsigned) -1;
1072 new_range
->last
= (unsigned) -1;
1073 new_range
->assem_name
= xstrdup (func_name
);
1078 long last
= strtol (end_val
, &invalid
, 10);
1079 if (*invalid
|| last
< start
)
1081 error ("Invalid range %s in option %s",
1083 is_enable
? "-fenable" : "-fdisable");
1087 new_range
= XCNEW (struct uid_range
);
1088 new_range
->start
= (unsigned) start
;
1089 new_range
->last
= (unsigned) last
;
1092 slot
= (*tab
)[pass
->static_pass_number
];
1093 new_range
->next
= slot
;
1094 (*tab
)[pass
->static_pass_number
] = new_range
;
1097 if (new_range
->assem_name
)
1098 inform (UNKNOWN_LOCATION
,
1099 "enable pass %s for function %s",
1100 phase_name
, new_range
->assem_name
);
1102 inform (UNKNOWN_LOCATION
,
1103 "enable pass %s for functions in the range of [%u, %u]",
1104 phase_name
, new_range
->start
, new_range
->last
);
1108 if (new_range
->assem_name
)
1109 inform (UNKNOWN_LOCATION
,
1110 "disable pass %s for function %s",
1111 phase_name
, new_range
->assem_name
);
1113 inform (UNKNOWN_LOCATION
,
1114 "disable pass %s for functions in the range of [%u, %u]",
1115 phase_name
, new_range
->start
, new_range
->last
);
1118 one_range
= next_range
;
1119 } while (next_range
);
1125 /* Enable pass specified by ARG. */
1128 enable_pass (const char *arg
)
1130 enable_disable_pass (arg
, true);
1133 /* Disable pass specified by ARG. */
1136 disable_pass (const char *arg
)
1138 enable_disable_pass (arg
, false);
1141 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1144 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
1146 vec
<uid_range_p
> tab
)
1148 uid_range_p slot
, range
;
1150 const char *aname
= NULL
;
1153 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1154 || pass
->static_pass_number
== -1)
1157 slot
= tab
[pass
->static_pass_number
];
1161 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
1162 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1163 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1168 if ((unsigned) cgraph_uid
>= range
->start
1169 && (unsigned) cgraph_uid
<= range
->last
)
1171 if (range
->assem_name
&& aname
1172 && !strcmp (range
->assem_name
, aname
))
1174 range
= range
->next
;
1181 /* Update static_pass_number for passes (and the flag
1182 TODO_mark_first_instance).
1184 Passes are constructed with static_pass_number preinitialized to 0
1186 This field is used in two different ways: initially as instance numbers
1187 of their kind, and then as ids within the entire pass manager.
1189 Within pass_manager::pass_manager:
1191 * In add_pass_instance(), as called by next_pass_1 in
1192 NEXT_PASS in init_optimization_passes
1194 * When the initial instance of a pass within a pass manager is seen,
1195 it is flagged, and its static_pass_number is set to -1
1197 * On subsequent times that it is seen, the static pass number
1198 is decremented each time, so that if there are e.g. 4 dups,
1199 they have static_pass_number -4, 2, 3, 4 respectively (note
1200 how the initial one is negative and gives the count); these
1201 can be thought of as instance numbers of the specific pass
1203 * Within the register_dump_files () traversal, set_pass_for_id()
1204 is called on each pass, using these instance numbers to create
1205 dumpfile switches, and then overwriting them with a pass id,
1206 which are global to the whole pass manager (based on
1207 (TDI_end + current value of extra_dump_files_in_use) ) */
1210 add_pass_instance (struct opt_pass
*new_pass
, bool track_duplicates
,
1211 opt_pass
*initial_pass
)
1213 /* Are we dealing with the first pass of its kind, or a clone? */
1214 if (new_pass
!= initial_pass
)
1216 /* We're dealing with a clone. */
1217 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1219 /* Indicate to register_dump_files that this pass has duplicates,
1220 and so it should rename the dump file. The first instance will
1221 be -1, and be number of duplicates = -static_pass_number - 1.
1222 Subsequent instances will be > 0 and just the duplicate number. */
1223 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1225 initial_pass
->static_pass_number
-= 1;
1226 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1231 /* We're dealing with the first pass of its kind. */
1232 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1233 new_pass
->static_pass_number
= -1;
1235 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1239 /* Add a pass to the pass list. Duplicate the pass if it's already
1242 static struct opt_pass
**
1243 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
,
1244 struct opt_pass
*initial_pass
)
1246 /* Every pass should have a name so that plugins can refer to them. */
1247 gcc_assert (pass
->name
!= NULL
);
1249 add_pass_instance (pass
, false, initial_pass
);
1252 return &(*list
)->next
;
1255 /* List node for an inserted pass instance. We need to keep track of all
1256 the newly-added pass instances (with 'added_pass_nodes' defined below)
1257 so that we can register their dump files after pass-positioning is finished.
1258 Registering dumping files needs to be post-processed or the
1259 static_pass_number of the opt_pass object would be modified and mess up
1260 the dump file names of future pass instances to be added. */
1262 struct pass_list_node
1264 struct opt_pass
*pass
;
1265 struct pass_list_node
*next
;
1268 static struct pass_list_node
*added_pass_nodes
= NULL
;
1269 static struct pass_list_node
*prev_added_pass_node
;
1271 /* Insert the pass at the proper position. Return true if the pass
1272 is successfully added.
1274 NEW_PASS_INFO - new pass to be inserted
1275 PASS_LIST - root of the pass list to insert the new pass to */
1278 position_pass (struct register_pass_info
*new_pass_info
,
1279 struct opt_pass
**pass_list
)
1281 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1282 bool success
= false;
1284 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1286 /* Check if the current pass is of the same type as the new pass and
1287 matches the name and the instance number of the reference pass. */
1288 if (pass
->type
== new_pass_info
->pass
->type
1290 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1291 && ((new_pass_info
->ref_pass_instance_number
== 0)
1292 || (new_pass_info
->ref_pass_instance_number
==
1293 pass
->static_pass_number
)
1294 || (new_pass_info
->ref_pass_instance_number
== 1
1295 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1297 struct opt_pass
*new_pass
;
1298 struct pass_list_node
*new_pass_node
;
1300 if (new_pass_info
->ref_pass_instance_number
== 0)
1302 new_pass
= new_pass_info
->pass
->clone ();
1303 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1307 new_pass
= new_pass_info
->pass
;
1308 add_pass_instance (new_pass
, true, new_pass
);
1311 /* Insert the new pass instance based on the positioning op. */
1312 switch (new_pass_info
->pos_op
)
1314 case PASS_POS_INSERT_AFTER
:
1315 new_pass
->next
= pass
->next
;
1316 pass
->next
= new_pass
;
1318 /* Skip newly inserted pass to avoid repeated
1319 insertions in the case where the new pass and the
1320 existing one have the same name. */
1323 case PASS_POS_INSERT_BEFORE
:
1324 new_pass
->next
= pass
;
1326 prev_pass
->next
= new_pass
;
1328 *pass_list
= new_pass
;
1330 case PASS_POS_REPLACE
:
1331 new_pass
->next
= pass
->next
;
1333 prev_pass
->next
= new_pass
;
1335 *pass_list
= new_pass
;
1336 new_pass
->sub
= pass
->sub
;
1337 new_pass
->tv_id
= pass
->tv_id
;
1341 error ("invalid pass positioning operation");
1345 /* Save the newly added pass (instance) in the added_pass_nodes
1346 list so that we can register its dump file later. Note that
1347 we cannot register the dump file now because doing so will modify
1348 the static_pass_number of the opt_pass object and therefore
1349 mess up the dump file name of future instances. */
1350 new_pass_node
= XCNEW (struct pass_list_node
);
1351 new_pass_node
->pass
= new_pass
;
1352 if (!added_pass_nodes
)
1353 added_pass_nodes
= new_pass_node
;
1355 prev_added_pass_node
->next
= new_pass_node
;
1356 prev_added_pass_node
= new_pass_node
;
1361 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1368 /* Hooks a new pass into the pass lists.
1370 PASS_INFO - pass information that specifies the opt_pass object,
1371 reference pass, instance number, and how to position
1375 register_pass (struct register_pass_info
*pass_info
)
1377 g
->get_passes ()->register_pass (pass_info
);
1381 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1382 const char* ref_pass_name
, int ref_pass_inst_number
)
1384 register_pass_info i
;
1386 i
.reference_pass_name
= ref_pass_name
;
1387 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1390 g
->get_passes ()->register_pass (&i
);
1394 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1396 bool all_instances
, success
;
1397 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1399 /* The checks below could fail in buggy plugins. Existing GCC
1400 passes should never fail these checks, so we mention plugin in
1402 if (!pass_info
->pass
)
1403 fatal_error ("plugin cannot register a missing pass");
1405 if (!pass_info
->pass
->name
)
1406 fatal_error ("plugin cannot register an unnamed pass");
1408 if (!pass_info
->reference_pass_name
)
1410 ("plugin cannot register pass %qs without reference pass name",
1411 pass_info
->pass
->name
);
1413 /* Try to insert the new pass to the pass lists. We need to check
1414 all five lists as the reference pass could be in one (or all) of
1416 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1417 success
= position_pass (pass_info
, &all_lowering_passes
);
1418 if (!success
|| all_instances
)
1419 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1420 if (!success
|| all_instances
)
1421 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1422 if (!success
|| all_instances
)
1423 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1424 if (!success
|| all_instances
)
1425 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1426 if (!success
|| all_instances
)
1427 success
|= position_pass (pass_info
, &all_passes
);
1430 ("pass %qs not found but is referenced by new pass %qs",
1431 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1433 /* OK, we have successfully inserted the new pass. We need to register
1434 the dump files for the newly added pass and its duplicates (if any).
1435 Because the registration of plugin/backend passes happens after the
1436 command-line options are parsed, the options that specify single
1437 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1438 passes. Therefore we currently can only enable dumping of
1439 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1440 are specified. While doing so, we also delete the pass_list_node
1441 objects created during pass positioning. */
1442 while (added_pass_nodes
)
1444 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1445 enum tree_dump_index tdi
;
1446 register_one_dump_file (added_pass_nodes
->pass
);
1447 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1448 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1450 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1454 /* Check if dump-all flag is specified. */
1455 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1456 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1457 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1458 XDELETE (added_pass_nodes
);
1459 added_pass_nodes
= next_node
;
1463 /* Construct the pass tree. The sequencing of passes is driven by
1464 the cgraph routines:
1466 finalize_compilation_unit ()
1467 for each node N in the cgraph
1468 cgraph_analyze_function (N)
1469 cgraph_lower_function (N) -> all_lowering_passes
1471 If we are optimizing, compile is then invoked:
1474 ipa_passes () -> all_small_ipa_passes
1475 -> Analysis of all_regular_ipa_passes
1476 * possible LTO streaming at copmilation time *
1477 -> Execution of all_regular_ipa_passes
1478 * possible LTO streaming at link time *
1479 -> all_late_ipa_passes
1480 expand_all_functions ()
1481 for each node N in the cgraph
1482 expand_function (N) -> Transformation of all_regular_ipa_passes
1487 pass_manager::operator new (size_t sz
)
1489 /* Ensure that all fields of the pass manager are zero-initialized. */
1490 return xcalloc (1, sz
);
1493 pass_manager::pass_manager (context
*ctxt
)
1494 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1495 all_regular_ipa_passes (NULL
), all_lto_gen_passes (NULL
),
1496 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1499 struct opt_pass
**p
;
1501 /* Initialize the pass_lists array. */
1502 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1504 #undef DEF_PASS_LIST
1506 /* Build the tree of passes. */
1508 #define INSERT_PASSES_AFTER(PASS) \
1511 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1513 struct opt_pass **p = &(PASS ## _1)->sub;
1515 #define POP_INSERT_PASSES() \
1518 #define NEXT_PASS(PASS, NUM) \
1520 gcc_assert (NULL == PASS ## _ ## NUM); \
1522 PASS ## _1 = make_##PASS (m_ctxt); \
1525 gcc_assert (PASS ## _1); \
1526 PASS ## _ ## NUM = PASS ## _1->clone (); \
1528 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1531 #define TERMINATE_PASS_LIST() \
1534 #include "pass-instances.def"
1536 #undef INSERT_PASSES_AFTER
1537 #undef PUSH_INSERT_PASSES_WITHIN
1538 #undef POP_INSERT_PASSES
1540 #undef TERMINATE_PASS_LIST
1542 /* Register the passes with the tree dump code. */
1543 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1544 register_dump_files (all_small_ipa_passes
,
1545 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1547 register_dump_files (all_regular_ipa_passes
,
1548 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1550 register_dump_files (all_lto_gen_passes
,
1551 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1553 register_dump_files (all_late_ipa_passes
,
1554 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1556 register_dump_files (all_passes
,
1557 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1561 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1562 function CALLBACK for every function in the call graph. Otherwise,
1563 call CALLBACK on the current function. */
1566 do_per_function (void (*callback
) (void *data
), void *data
)
1568 if (current_function_decl
)
1572 struct cgraph_node
*node
;
1573 FOR_EACH_DEFINED_FUNCTION (node
)
1574 if (node
->symbol
.analyzed
&& gimple_has_body_p (node
->symbol
.decl
)
1575 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1577 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1581 free_dominance_info (CDI_DOMINATORS
);
1582 free_dominance_info (CDI_POST_DOMINATORS
);
1590 /* Because inlining might remove no-longer reachable nodes, we need to
1591 keep the array visible to garbage collector to avoid reading collected
1594 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1596 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1597 function CALLBACK for every function in the call graph. Otherwise,
1598 call CALLBACK on the current function.
1599 This function is global so that plugins can use it. */
1601 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1605 if (current_function_decl
)
1609 gcc_assert (!order
);
1610 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1611 nnodes
= ipa_reverse_postorder (order
);
1612 for (i
= nnodes
- 1; i
>= 0; i
--)
1613 order
[i
]->process
= 1;
1614 for (i
= nnodes
- 1; i
>= 0; i
--)
1616 struct cgraph_node
*node
= order
[i
];
1618 /* Allow possibly removed nodes to be garbage collected. */
1621 if (cgraph_function_with_gimple_body_p (node
))
1623 cgraph_get_body (node
);
1624 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1626 free_dominance_info (CDI_DOMINATORS
);
1627 free_dominance_info (CDI_POST_DOMINATORS
);
1638 /* Helper function to perform function body dump. */
1641 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1643 if (dump_file
&& current_function_decl
)
1645 if (cfun
->curr_properties
& PROP_trees
)
1646 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1648 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1650 /* Flush the file. If verification fails, we won't be able to
1651 close the file before aborting. */
1654 if ((cfun
->curr_properties
& PROP_cfg
)
1655 && (dump_flags
& TDF_GRAPH
))
1656 print_graph_cfg (dump_file_name
, cfun
);
1660 static struct profile_record
*profile_record
;
1662 /* Do profile consistency book-keeping for the pass with static number INDEX.
1663 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1664 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1665 if we are only book-keeping on passes that may have selectively disabled
1666 themselves on a given function. */
1668 check_profile_consistency (int index
, int subpass
, bool run
)
1670 pass_manager
*passes
= g
->get_passes ();
1673 if (!profile_record
)
1674 profile_record
= XCNEWVEC (struct profile_record
,
1675 passes
->passes_by_id_size
);
1676 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1677 gcc_assert (subpass
< 2);
1678 profile_record
[index
].run
|= run
;
1679 account_profile_record (&profile_record
[index
], subpass
);
1682 /* Output profile consistency. */
1685 dump_profile_report (void)
1687 g
->get_passes ()->dump_profile_report ();
1691 pass_manager::dump_profile_report () const
1694 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1695 gcov_type last_time
= 0, last_size
= 0;
1696 double rel_time_change
, rel_size_change
;
1697 int last_reported
= 0;
1699 if (!profile_record
)
1701 fprintf (stderr
, "\nProfile consistency report:\n\n");
1702 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1703 fprintf (stderr
, " |freq count |freq count |size time\n");
1705 for (i
= 0; i
< passes_by_id_size
; i
++)
1706 for (j
= 0 ; j
< 2; j
++)
1707 if (profile_record
[i
].run
)
1710 rel_time_change
= (profile_record
[i
].time
[j
]
1711 - (double)last_time
) * 100 / (double)last_time
;
1713 rel_time_change
= 0;
1715 rel_size_change
= (profile_record
[i
].size
[j
]
1716 - (double)last_size
) * 100 / (double)last_size
;
1718 rel_size_change
= 0;
1720 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1721 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1722 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1723 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1724 || rel_time_change
|| rel_size_change
)
1727 fprintf (stderr
, "%-20s %s",
1728 passes_by_id
[i
]->name
,
1729 j
? "(after TODO)" : " ");
1730 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1731 fprintf (stderr
, "| %+5i",
1732 profile_record
[i
].num_mismatched_freq_in
[j
]
1735 fprintf (stderr
, "| ");
1736 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1737 fprintf (stderr
, " %+5i",
1738 profile_record
[i
].num_mismatched_count_in
[j
]
1741 fprintf (stderr
, " ");
1742 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1743 fprintf (stderr
, "| %+5i",
1744 profile_record
[i
].num_mismatched_freq_out
[j
]
1747 fprintf (stderr
, "| ");
1748 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1749 fprintf (stderr
, " %+5i",
1750 profile_record
[i
].num_mismatched_count_out
[j
]
1753 fprintf (stderr
, " ");
1755 /* Size/time units change across gimple and RTL. */
1756 if (i
== pass_expand_1
->static_pass_number
)
1757 fprintf (stderr
, "|----------");
1760 if (rel_size_change
)
1761 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1763 fprintf (stderr
, "| ");
1764 if (rel_time_change
)
1765 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1767 fprintf (stderr
, "\n");
1768 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1769 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1770 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1771 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1773 else if (j
&& last_reported
!= i
)
1776 fprintf (stderr
, "%-20s ------------| | |\n",
1777 passes_by_id
[i
]->name
);
1779 last_time
= profile_record
[i
].time
[j
];
1780 last_size
= profile_record
[i
].size
[j
];
1784 /* Perform all TODO actions that ought to be done on each function. */
1787 execute_function_todo (void *data
)
1789 unsigned int flags
= (size_t)data
;
1790 flags
&= ~cfun
->last_verified
;
1794 /* Always cleanup the CFG before trying to update SSA. */
1795 if (flags
& TODO_cleanup_cfg
)
1797 cleanup_tree_cfg ();
1799 /* When cleanup_tree_cfg merges consecutive blocks, it may
1800 perform some simplistic propagation when removing single
1801 valued PHI nodes. This propagation may, in turn, cause the
1802 SSA form to become out-of-date (see PR 22037). So, even
1803 if the parent pass had not scheduled an SSA update, we may
1804 still need to do one. */
1805 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1806 flags
|= TODO_update_ssa
;
1809 if (flags
& TODO_update_ssa_any
)
1811 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1812 update_ssa (update_flags
);
1813 cfun
->last_verified
&= ~TODO_verify_ssa
;
1816 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1817 compute_may_aliases ();
1819 if (optimize
&& (flags
& TODO_update_address_taken
))
1820 execute_update_addresses_taken ();
1822 if (flags
& TODO_remove_unused_locals
)
1823 remove_unused_locals ();
1825 if (flags
& TODO_rebuild_frequencies
)
1826 rebuild_frequencies ();
1828 if (flags
& TODO_rebuild_cgraph_edges
)
1829 rebuild_cgraph_edges ();
1831 /* If we've seen errors do not bother running any verifiers. */
1835 #if defined ENABLE_CHECKING
1836 if (flags
& TODO_verify_ssa
1837 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1839 verify_gimple_in_cfg (cfun
);
1842 else if (flags
& TODO_verify_stmts
)
1843 verify_gimple_in_cfg (cfun
);
1844 if (flags
& TODO_verify_flow
)
1845 verify_flow_info ();
1846 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1847 verify_loop_closed_ssa (false);
1848 if (flags
& TODO_verify_rtl_sharing
)
1849 verify_rtl_sharing ();
1852 cfun
->last_verified
= flags
& TODO_verify_all
;
1855 /* Perform all TODO actions. */
1857 execute_todo (unsigned int flags
)
1859 #if defined ENABLE_CHECKING
1861 && need_ssa_update_p (cfun
))
1862 gcc_assert (flags
& TODO_update_ssa_any
);
1865 timevar_push (TV_TODO
);
1867 /* Inform the pass whether it is the first time it is run. */
1868 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1870 statistics_fini_pass ();
1872 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1874 /* Always remove functions just as before inlining: IPA passes might be
1875 interested to see bodies of extern inline functions that are not inlined
1876 to analyze side effects. The full removal is done just at the end
1877 of IPA pass queue. */
1878 if (flags
& TODO_remove_functions
)
1881 symtab_remove_unreachable_nodes (true, dump_file
);
1884 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1887 dump_symtab (dump_file
);
1888 /* Flush the file. If verification fails, we won't be able to
1889 close the file before aborting. */
1893 /* Now that the dumping has been done, we can get rid of the optional
1895 if (flags
& TODO_df_finish
)
1896 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1898 timevar_pop (TV_TODO
);
1901 /* Verify invariants that should hold between passes. This is a place
1902 to put simple sanity checks. */
1905 verify_interpass_invariants (void)
1907 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1910 /* Clear the last verified flag. */
1913 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
1915 cfun
->last_verified
= 0;
1918 /* Helper function. Verify that the properties has been turn into the
1919 properties expected by the pass. */
1921 #ifdef ENABLE_CHECKING
1923 verify_curr_properties (void *data
)
1925 unsigned int props
= (size_t)data
;
1926 gcc_assert ((cfun
->curr_properties
& props
) == props
);
1930 /* Initialize pass dump file. */
1931 /* This is non-static so that the plugins can use it. */
1934 pass_init_dump_file (struct opt_pass
*pass
)
1936 /* If a dump file name is present, open it if enabled. */
1937 if (pass
->static_pass_number
!= -1)
1939 timevar_push (TV_DUMP
);
1940 gcc::dump_manager
*dumps
= g
->get_dumps ();
1941 bool initializing_dump
=
1942 !dumps
->dump_initialized_p (pass
->static_pass_number
);
1943 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
1944 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
1945 if (dump_file
&& current_function_decl
)
1946 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1947 if (initializing_dump
1948 && dump_file
&& (dump_flags
& TDF_GRAPH
)
1949 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1950 clean_graph_dump_file (dump_file_name
);
1951 timevar_pop (TV_DUMP
);
1952 return initializing_dump
;
1958 /* Flush PASS dump file. */
1959 /* This is non-static so that plugins can use it. */
1962 pass_fini_dump_file (struct opt_pass
*pass
)
1964 timevar_push (TV_DUMP
);
1966 /* Flush and close dump file. */
1969 free (CONST_CAST (char *, dump_file_name
));
1970 dump_file_name
= NULL
;
1973 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
1974 timevar_pop (TV_DUMP
);
1977 /* After executing the pass, apply expected changes to the function
1981 update_properties_after_pass (void *data
)
1983 struct opt_pass
*pass
= (struct opt_pass
*) data
;
1984 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
1985 & ~pass
->properties_destroyed
;
1988 /* Execute summary generation for all of the passes in IPA_PASS. */
1991 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
1995 struct opt_pass
*pass
= ipa_pass
;
1997 /* Execute all of the IPA_PASSes in the list. */
1998 if (ipa_pass
->type
== IPA_PASS
1999 && ((!pass
->has_gate
) || pass
->gate ())
2000 && ipa_pass
->generate_summary
)
2002 pass_init_dump_file (pass
);
2004 /* If a timevar is present, start it. */
2006 timevar_push (pass
->tv_id
);
2008 ipa_pass
->generate_summary ();
2012 timevar_pop (pass
->tv_id
);
2014 pass_fini_dump_file (pass
);
2016 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->next
;
2020 /* Execute IPA_PASS function transform on NODE. */
2023 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2024 struct ipa_opt_pass_d
*ipa_pass
)
2026 struct opt_pass
*pass
= ipa_pass
;
2027 unsigned int todo_after
= 0;
2029 current_pass
= pass
;
2030 if (!ipa_pass
->function_transform
)
2033 /* Note that the folders should only create gimple expressions.
2034 This is a hack until the new folder is ready. */
2035 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2037 pass_init_dump_file (pass
);
2039 /* Run pre-pass verification. */
2040 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2042 /* If a timevar is present, start it. */
2043 if (pass
->tv_id
!= TV_NONE
)
2044 timevar_push (pass
->tv_id
);
2047 todo_after
= ipa_pass
->function_transform (node
);
2050 if (pass
->tv_id
!= TV_NONE
)
2051 timevar_pop (pass
->tv_id
);
2053 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2054 check_profile_consistency (pass
->static_pass_number
, 0, true);
2056 /* Run post-pass cleanup and verification. */
2057 execute_todo (todo_after
);
2058 verify_interpass_invariants ();
2059 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2060 check_profile_consistency (pass
->static_pass_number
, 1, true);
2062 do_per_function (execute_function_dump
, NULL
);
2063 pass_fini_dump_file (pass
);
2065 current_pass
= NULL
;
2067 /* Signal this is a suitable GC collection point. */
2068 if (!(todo_after
& TODO_do_not_ggc_collect
))
2072 /* For the current function, execute all ipa transforms. */
2075 execute_all_ipa_transforms (void)
2077 struct cgraph_node
*node
;
2080 node
= cgraph_get_node (current_function_decl
);
2082 if (node
->ipa_transforms_to_apply
.exists ())
2086 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2087 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2088 node
->ipa_transforms_to_apply
.release ();
2092 /* Callback for do_per_function to apply all IPA transforms. */
2095 apply_ipa_transforms (void *data
)
2097 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2098 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2100 *(bool *)data
= true;
2101 execute_all_ipa_transforms ();
2102 rebuild_cgraph_edges ();
2106 /* Check if PASS is explicitly disabled or enabled and return
2107 the gate status. FUNC is the function to be processed, and
2108 GATE_STATUS is the gate status determined by pass manager by
2112 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2114 bool explicitly_enabled
= false;
2115 bool explicitly_disabled
= false;
2118 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2119 enabled_pass_uid_range_tab
);
2121 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2122 disabled_pass_uid_range_tab
);
2124 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2133 execute_one_pass (struct opt_pass
*pass
)
2135 unsigned int todo_after
= 0;
2139 /* IPA passes are executed on whole program, so cfun should be NULL.
2140 Other passes need function context set. */
2141 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2142 gcc_assert (!cfun
&& !current_function_decl
);
2144 gcc_assert (cfun
&& current_function_decl
);
2146 current_pass
= pass
;
2148 /* Check whether gate check should be avoided.
2149 User controls the value of the gate through the parameter "gate_status". */
2150 gate_status
= pass
->has_gate
? pass
->gate () : true;
2151 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2153 /* Override gate with plugin. */
2154 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2158 /* Run so passes selectively disabling themselves on a given function
2159 are not miscounted. */
2160 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2162 check_profile_consistency (pass
->static_pass_number
, 0, false);
2163 check_profile_consistency (pass
->static_pass_number
, 1, false);
2165 current_pass
= NULL
;
2169 /* Pass execution event trigger: useful to identify passes being
2171 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2173 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2174 Apply all trnasforms first. */
2175 if (pass
->type
== SIMPLE_IPA_PASS
)
2177 bool applied
= false;
2178 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2180 symtab_remove_unreachable_nodes (true, dump_file
);
2181 /* Restore current_pass. */
2182 current_pass
= pass
;
2185 if (!quiet_flag
&& !cfun
)
2186 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2188 /* Note that the folders should only create gimple expressions.
2189 This is a hack until the new folder is ready. */
2190 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2192 pass_init_dump_file (pass
);
2194 /* Run pre-pass verification. */
2195 execute_todo (pass
->todo_flags_start
);
2197 #ifdef ENABLE_CHECKING
2198 do_per_function (verify_curr_properties
,
2199 (void *)(size_t)pass
->properties_required
);
2202 /* If a timevar is present, start it. */
2203 if (pass
->tv_id
!= TV_NONE
)
2204 timevar_push (pass
->tv_id
);
2207 if (pass
->has_execute
)
2209 todo_after
= pass
->execute ();
2210 do_per_function (clear_last_verified
, NULL
);
2214 if (pass
->tv_id
!= TV_NONE
)
2215 timevar_pop (pass
->tv_id
);
2217 do_per_function (update_properties_after_pass
, pass
);
2219 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2220 check_profile_consistency (pass
->static_pass_number
, 0, true);
2222 /* Run post-pass cleanup and verification. */
2223 execute_todo (todo_after
| pass
->todo_flags_finish
);
2224 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2225 check_profile_consistency (pass
->static_pass_number
, 1, true);
2227 verify_interpass_invariants ();
2228 do_per_function (execute_function_dump
, NULL
);
2229 if (pass
->type
== IPA_PASS
)
2231 struct cgraph_node
*node
;
2232 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2233 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2236 if (!current_function_decl
)
2237 cgraph_process_new_functions ();
2239 pass_fini_dump_file (pass
);
2241 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2242 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2243 || pass
->type
!= RTL_PASS
);
2245 current_pass
= NULL
;
2247 /* Signal this is a suitable GC collection point. */
2248 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2255 execute_pass_list (struct opt_pass
*pass
)
2259 gcc_assert (pass
->type
== GIMPLE_PASS
2260 || pass
->type
== RTL_PASS
);
2261 if (execute_one_pass (pass
) && pass
->sub
)
2262 execute_pass_list (pass
->sub
);
2268 /* Same as execute_pass_list but assume that subpasses of IPA passes
2269 are local passes. If SET is not NULL, write out summaries of only
2270 those node in SET. */
2273 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2277 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2278 gcc_assert (!current_function_decl
);
2280 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2281 if (pass
->type
== IPA_PASS
2282 && ipa_pass
->write_summary
2283 && ((!pass
->has_gate
) || pass
->gate ()))
2285 /* If a timevar is present, start it. */
2287 timevar_push (pass
->tv_id
);
2289 pass_init_dump_file (pass
);
2291 ipa_pass
->write_summary ();
2293 pass_fini_dump_file (pass
);
2295 /* If a timevar is present, start it. */
2297 timevar_pop (pass
->tv_id
);
2300 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2301 ipa_write_summaries_2 (pass
->sub
, state
);
2307 /* Helper function of ipa_write_summaries. Creates and destroys the
2308 decl state and calls ipa_write_summaries_2 for all passes that have
2309 summaries. SET is the set of nodes to be written. */
2312 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2314 pass_manager
*passes
= g
->get_passes ();
2315 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2316 state
->symtab_node_encoder
= encoder
;
2318 lto_push_out_decl_state (state
);
2320 gcc_assert (!flag_wpa
);
2321 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2322 ipa_write_summaries_2 (passes
->all_lto_gen_passes
, state
);
2324 gcc_assert (lto_get_out_decl_state () == state
);
2325 lto_pop_out_decl_state ();
2326 lto_delete_out_decl_state (state
);
2329 /* Write out summaries for all the nodes in the callgraph. */
2332 ipa_write_summaries (void)
2334 lto_symtab_encoder_t encoder
;
2336 struct varpool_node
*vnode
;
2337 struct cgraph_node
*node
;
2338 struct cgraph_node
**order
;
2340 if (!flag_generate_lto
|| seen_error ())
2343 encoder
= lto_symtab_encoder_new (false);
2345 /* Create the callgraph set in the same order used in
2346 cgraph_expand_all_functions. This mostly facilitates debugging,
2347 since it causes the gimple file to be processed in the same order
2348 as the source code. */
2349 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2350 order_pos
= ipa_reverse_postorder (order
);
2351 gcc_assert (order_pos
== cgraph_n_nodes
);
2353 for (i
= order_pos
- 1; i
>= 0; i
--)
2355 struct cgraph_node
*node
= order
[i
];
2357 if (cgraph_function_with_gimple_body_p (node
))
2359 /* When streaming out references to statements as part of some IPA
2360 pass summary, the statements need to have uids assigned and the
2361 following does that for all the IPA passes here. Naturally, this
2362 ordering then matches the one IPA-passes get in their stmt_fixup
2365 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2366 renumber_gimple_stmt_uids ();
2369 if (node
->symbol
.definition
)
2370 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2373 FOR_EACH_DEFINED_FUNCTION (node
)
2374 if (node
->symbol
.alias
)
2375 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2376 FOR_EACH_DEFINED_VARIABLE (vnode
)
2377 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2379 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2384 /* Same as execute_pass_list but assume that subpasses of IPA passes
2385 are local passes. If SET is not NULL, write out optimization summaries of
2386 only those node in SET. */
2389 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2393 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2394 gcc_assert (!current_function_decl
);
2396 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2397 if (pass
->type
== IPA_PASS
2398 && ipa_pass
->write_optimization_summary
2399 && ((!pass
->has_gate
) || pass
->gate ()))
2401 /* If a timevar is present, start it. */
2403 timevar_push (pass
->tv_id
);
2405 pass_init_dump_file (pass
);
2407 ipa_pass
->write_optimization_summary ();
2409 pass_fini_dump_file (pass
);
2411 /* If a timevar is present, start it. */
2413 timevar_pop (pass
->tv_id
);
2416 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2417 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2423 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2424 NULL, write out all summaries of all nodes. */
2427 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2429 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2430 lto_symtab_encoder_iterator lsei
;
2431 state
->symtab_node_encoder
= encoder
;
2433 lto_push_out_decl_state (state
);
2434 for (lsei
= lsei_start_function_in_partition (encoder
);
2435 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2437 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2438 /* When streaming out references to statements as part of some IPA
2439 pass summary, the statements need to have uids assigned.
2441 For functions newly born at WPA stage we need to initialize
2443 if (node
->symbol
.definition
2444 && gimple_has_body_p (node
->symbol
.decl
))
2446 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2447 renumber_gimple_stmt_uids ();
2452 gcc_assert (flag_wpa
);
2453 pass_manager
*passes
= g
->get_passes ();
2454 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2455 ipa_write_optimization_summaries_1 (passes
->all_lto_gen_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 (struct opt_pass
*pass
)
2470 struct ipa_opt_pass_d
*ipa_pass
= (struct 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
->has_gate
) || pass
->gate ())
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 and all_lto_gen_passes. */
2506 ipa_read_summaries (void)
2508 pass_manager
*passes
= g
->get_passes ();
2509 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2510 ipa_read_summaries_1 (passes
->all_lto_gen_passes
);
2513 /* Same as execute_pass_list but assume that subpasses of IPA passes
2514 are local passes. */
2517 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2521 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2523 gcc_assert (!current_function_decl
);
2525 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2527 if ((!pass
->has_gate
) || pass
->gate ())
2529 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2531 /* If a timevar is present, start it. */
2533 timevar_push (pass
->tv_id
);
2535 pass_init_dump_file (pass
);
2537 ipa_pass
->read_optimization_summary ();
2539 pass_fini_dump_file (pass
);
2543 timevar_pop (pass
->tv_id
);
2546 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2547 ipa_read_optimization_summaries_1 (pass
->sub
);
2553 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2556 ipa_read_optimization_summaries (void)
2558 pass_manager
*passes
= g
->get_passes ();
2559 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2560 ipa_read_optimization_summaries_1 (passes
->all_lto_gen_passes
);
2563 /* Same as execute_pass_list but assume that subpasses of IPA passes
2564 are local passes. */
2566 execute_ipa_pass_list (struct opt_pass
*pass
)
2570 gcc_assert (!current_function_decl
);
2572 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2573 if (execute_one_pass (pass
) && pass
->sub
)
2575 if (pass
->sub
->type
== GIMPLE_PASS
)
2577 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2578 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2580 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2582 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2583 || pass
->sub
->type
== IPA_PASS
)
2584 execute_ipa_pass_list (pass
->sub
);
2588 gcc_assert (!current_function_decl
);
2589 cgraph_process_new_functions ();
2595 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2598 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2599 struct cgraph_node
*node
, gimple
*stmts
)
2603 /* Execute all of the IPA_PASSes in the list. */
2604 if (pass
->type
== IPA_PASS
2605 && ((!pass
->has_gate
) || pass
->gate ()))
2607 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2609 if (ipa_pass
->stmt_fixup
)
2611 pass_init_dump_file (pass
);
2612 /* If a timevar is present, start it. */
2614 timevar_push (pass
->tv_id
);
2616 ipa_pass
->stmt_fixup (node
, stmts
);
2620 timevar_pop (pass
->tv_id
);
2621 pass_fini_dump_file (pass
);
2624 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2630 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2633 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2635 pass_manager
*passes
= g
->get_passes ();
2636 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2640 extern void debug_properties (unsigned int);
2641 extern void dump_properties (FILE *, unsigned int);
2644 dump_properties (FILE *dump
, unsigned int props
)
2646 fprintf (dump
, "Properties:\n");
2647 if (props
& PROP_gimple_any
)
2648 fprintf (dump
, "PROP_gimple_any\n");
2649 if (props
& PROP_gimple_lcf
)
2650 fprintf (dump
, "PROP_gimple_lcf\n");
2651 if (props
& PROP_gimple_leh
)
2652 fprintf (dump
, "PROP_gimple_leh\n");
2653 if (props
& PROP_cfg
)
2654 fprintf (dump
, "PROP_cfg\n");
2655 if (props
& PROP_ssa
)
2656 fprintf (dump
, "PROP_ssa\n");
2657 if (props
& PROP_no_crit_edges
)
2658 fprintf (dump
, "PROP_no_crit_edges\n");
2659 if (props
& PROP_rtl
)
2660 fprintf (dump
, "PROP_rtl\n");
2661 if (props
& PROP_gimple_lomp
)
2662 fprintf (dump
, "PROP_gimple_lomp\n");
2663 if (props
& PROP_gimple_lcx
)
2664 fprintf (dump
, "PROP_gimple_lcx\n");
2665 if (props
& PROP_gimple_lvec
)
2666 fprintf (dump
, "PROP_gimple_lvec\n");
2667 if (props
& PROP_cfglayout
)
2668 fprintf (dump
, "PROP_cfglayout\n");
2672 debug_properties (unsigned int props
)
2674 dump_properties (stderr
, props
);
2677 /* Called by local passes to see if function is called by already processed nodes.
2678 Because we process nodes in topological order, this means that function is
2679 in recursive cycle or we introduced new direct calls. */
2681 function_called_by_processed_nodes_p (void)
2683 struct cgraph_edge
*e
;
2684 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2688 if (e
->caller
->symbol
.decl
== current_function_decl
)
2690 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2692 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2694 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2699 fprintf (dump_file
, "Already processed call to:\n");
2700 dump_cgraph_node (dump_file
, e
->caller
);
2705 #include "gt-passes.h"