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"
91 /* This is used for debugging. It allows the current pass to printed
92 from anywhere in compilation.
93 The variable current_pass is also used for statistics and plugins. */
94 opt_pass
*current_pass
;
96 static void register_pass_name (opt_pass
*, const char *);
98 /* Most passes are single-instance (within their context) and thus don't
99 need to implement cloning, but passes that support multiple instances
100 *must* provide their own implementation of the clone method.
102 Handle this by providing a default implemenation, but make it a fatal
108 internal_error ("pass %s does not support cloning", name
);
112 opt_pass::gate (function
*)
118 opt_pass::execute (function
*)
123 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
127 static_pass_number (0),
134 pass_manager::execute_early_local_passes ()
136 execute_pass_list (cfun
, pass_early_local_passes_1
->sub
);
140 pass_manager::execute_pass_mode_switching ()
142 return pass_mode_switching_1
->execute (cfun
);
146 /* Call from anywhere to find out what pass this is. Useful for
147 printing out debugging information deep inside an service
150 print_current_pass (FILE *file
)
153 fprintf (file
, "current pass = %s (%d)\n",
154 current_pass
->name
, current_pass
->static_pass_number
);
156 fprintf (file
, "no current pass.\n");
160 /* Call from the debugger to get the current pass name. */
164 print_current_pass (stderr
);
169 /* Global variables used to communicate with passes. */
171 bool first_pass_instance
;
174 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
177 This does nothing for local (non-static) variables, unless the
178 variable is a register variable with DECL_ASSEMBLER_NAME set. In
179 that case, or if the variable is not an automatic, it sets up the
180 RTL and outputs any assembler code (label definition, storage
181 allocation and initialization).
183 DECL is the declaration. TOP_LEVEL is nonzero
184 if this declaration is not within a function. */
187 rest_of_decl_compilation (tree decl
,
191 bool finalize
= true;
193 /* We deferred calling assemble_alias so that we could collect
194 other attributes such as visibility. Emit the alias now. */
198 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
201 alias
= TREE_VALUE (TREE_VALUE (alias
));
202 alias
= get_identifier (TREE_STRING_POINTER (alias
));
203 /* A quirk of the initial implementation of aliases required that the
204 user add "extern" to all of them. Which is silly, but now
205 historical. Do note that the symbol is in fact locally defined. */
206 DECL_EXTERNAL (decl
) = 0;
207 TREE_STATIC (decl
) = 1;
208 assemble_alias (decl
, alias
);
213 /* Can't defer this, because it needs to happen before any
214 later function definitions are processed. */
215 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
216 make_decl_rtl (decl
);
218 /* Forward declarations for nested functions are not "external",
219 but we need to treat them as if they were. */
220 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
221 || TREE_CODE (decl
) == FUNCTION_DECL
)
223 timevar_push (TV_VARCONST
);
225 /* Don't output anything when a tentative file-scope definition
226 is seen. But at end of compilation, do output code for them.
228 We do output all variables and rely on
229 callgraph code to defer them except for forward declarations
230 (see gcc.c-torture/compile/920624-1.c) */
232 || !DECL_DEFER_OUTPUT (decl
)
233 || DECL_INITIAL (decl
))
234 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
235 && !DECL_EXTERNAL (decl
))
237 /* When reading LTO unit, we also read varpool, so do not
239 if (in_lto_p
&& !at_end
)
241 else if (finalize
&& TREE_CODE (decl
) != FUNCTION_DECL
)
242 varpool_finalize_decl (decl
);
245 #ifdef ASM_FINISH_DECLARE_OBJECT
246 if (decl
== last_assemble_variable_decl
)
248 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
253 timevar_pop (TV_VARCONST
);
255 else if (TREE_CODE (decl
) == TYPE_DECL
256 /* Like in rest_of_type_compilation, avoid confusing the debug
257 information machinery when there are errors. */
260 timevar_push (TV_SYMOUT
);
261 debug_hooks
->type_decl (decl
, !top_level
);
262 timevar_pop (TV_SYMOUT
);
265 /* Let cgraph know about the existence of variables. */
266 if (in_lto_p
&& !at_end
)
268 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
269 && TREE_STATIC (decl
))
270 varpool_node_for_decl (decl
);
273 /* Called after finishing a record, union or enumeral type. */
276 rest_of_type_compilation (tree type
, int toplev
)
278 /* Avoid confusing the debug information machinery when there are
283 timevar_push (TV_SYMOUT
);
284 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
285 timevar_pop (TV_SYMOUT
);
292 finish_optimization_passes (void)
295 struct dump_file_info
*dfi
;
297 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
299 timevar_push (TV_DUMP
);
300 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
302 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
304 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
309 dumps
->dump_start (pass_profile_1
->static_pass_number
, NULL
);
310 print_combine_total_stats ();
311 dumps
->dump_finish (pass_profile_1
->static_pass_number
);
314 /* Do whatever is necessary to finish printing the graphs. */
315 for (i
= TDI_end
; (dfi
= dumps
->get_dump_file_info (i
)) != NULL
; ++i
)
316 if (dumps
->dump_initialized_p (i
)
317 && (dfi
->pflags
& TDF_GRAPH
) != 0
318 && (name
= dumps
->get_dump_file_name (i
)) != NULL
)
320 finish_graph_dump_file (name
);
324 timevar_pop (TV_DUMP
);
328 execute_all_early_local_passes (void)
330 /* Once this pass (and its sub-passes) are complete, all functions
331 will be in SSA form. Technically this state change is happening
332 a tad early, since the sub-passes have not yet run, but since
333 none of the sub-passes are IPA passes and do not create new
334 functions, this is ok. We're setting this value for the benefit
335 of IPA passes that follow. */
336 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
337 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
343 const pass_data pass_data_early_local_passes
=
345 SIMPLE_IPA_PASS
, /* type */
346 "early_local_cleanups", /* name */
347 OPTGROUP_NONE
, /* optinfo_flags */
348 true, /* has_execute */
349 TV_EARLY_LOCAL
, /* tv_id */
350 0, /* properties_required */
351 0, /* properties_provided */
352 0, /* properties_destroyed */
353 0, /* todo_flags_start */
354 TODO_remove_functions
, /* todo_flags_finish */
357 class pass_early_local_passes
: public simple_ipa_opt_pass
360 pass_early_local_passes (gcc::context
*ctxt
)
361 : simple_ipa_opt_pass (pass_data_early_local_passes
, ctxt
)
364 /* opt_pass methods: */
365 virtual bool gate (function
*)
367 /* Don't bother doing anything if the program has errors. */
368 return (!seen_error () && !in_lto_p
);
371 virtual unsigned int execute (function
*)
373 return execute_all_early_local_passes ();
376 }; // class pass_early_local_passes
380 simple_ipa_opt_pass
*
381 make_pass_early_local_passes (gcc::context
*ctxt
)
383 return new pass_early_local_passes (ctxt
);
388 const pass_data pass_data_all_early_optimizations
=
390 GIMPLE_PASS
, /* type */
391 "early_optimizations", /* name */
392 OPTGROUP_NONE
, /* optinfo_flags */
393 false, /* has_execute */
395 0, /* properties_required */
396 0, /* properties_provided */
397 0, /* properties_destroyed */
398 0, /* todo_flags_start */
399 0, /* todo_flags_finish */
402 class pass_all_early_optimizations
: public gimple_opt_pass
405 pass_all_early_optimizations (gcc::context
*ctxt
)
406 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
409 /* opt_pass methods: */
410 virtual bool gate (function
*)
412 return (optimize
>= 1
413 /* Don't bother doing anything if the program has errors. */
417 }; // class pass_all_early_optimizations
421 static gimple_opt_pass
*
422 make_pass_all_early_optimizations (gcc::context
*ctxt
)
424 return new pass_all_early_optimizations (ctxt
);
429 const pass_data pass_data_all_optimizations
=
431 GIMPLE_PASS
, /* type */
432 "*all_optimizations", /* name */
433 OPTGROUP_NONE
, /* optinfo_flags */
434 false, /* has_execute */
435 TV_OPTIMIZE
, /* tv_id */
436 0, /* properties_required */
437 0, /* properties_provided */
438 0, /* properties_destroyed */
439 0, /* todo_flags_start */
440 0, /* todo_flags_finish */
443 class pass_all_optimizations
: public gimple_opt_pass
446 pass_all_optimizations (gcc::context
*ctxt
)
447 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
450 /* opt_pass methods: */
451 virtual bool gate (function
*) { return optimize
>= 1 && !optimize_debug
; }
453 }; // class pass_all_optimizations
457 static gimple_opt_pass
*
458 make_pass_all_optimizations (gcc::context
*ctxt
)
460 return new pass_all_optimizations (ctxt
);
465 const pass_data pass_data_all_optimizations_g
=
467 GIMPLE_PASS
, /* type */
468 "*all_optimizations_g", /* name */
469 OPTGROUP_NONE
, /* optinfo_flags */
470 false, /* has_execute */
471 TV_OPTIMIZE
, /* tv_id */
472 0, /* properties_required */
473 0, /* properties_provided */
474 0, /* properties_destroyed */
475 0, /* todo_flags_start */
476 0, /* todo_flags_finish */
479 class pass_all_optimizations_g
: public gimple_opt_pass
482 pass_all_optimizations_g (gcc::context
*ctxt
)
483 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
486 /* opt_pass methods: */
487 virtual bool gate (function
*) { return optimize
>= 1 && optimize_debug
; }
489 }; // class pass_all_optimizations_g
493 static gimple_opt_pass
*
494 make_pass_all_optimizations_g (gcc::context
*ctxt
)
496 return new pass_all_optimizations_g (ctxt
);
501 const pass_data pass_data_rest_of_compilation
=
504 "*rest_of_compilation", /* name */
505 OPTGROUP_NONE
, /* optinfo_flags */
506 false, /* has_execute */
507 TV_REST_OF_COMPILATION
, /* tv_id */
508 PROP_rtl
, /* properties_required */
509 0, /* properties_provided */
510 0, /* properties_destroyed */
511 0, /* todo_flags_start */
512 0, /* todo_flags_finish */
515 class pass_rest_of_compilation
: public rtl_opt_pass
518 pass_rest_of_compilation (gcc::context
*ctxt
)
519 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
522 /* opt_pass methods: */
523 virtual bool gate (function
*)
525 /* Early return if there were errors. We can run afoul of our
526 consistency checks, and there's not really much point in fixing them. */
527 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
530 }; // class pass_rest_of_compilation
534 static rtl_opt_pass
*
535 make_pass_rest_of_compilation (gcc::context
*ctxt
)
537 return new pass_rest_of_compilation (ctxt
);
542 const pass_data pass_data_postreload
=
545 "*all-postreload", /* name */
546 OPTGROUP_NONE
, /* optinfo_flags */
547 false, /* has_execute */
548 TV_POSTRELOAD
, /* tv_id */
549 PROP_rtl
, /* properties_required */
550 0, /* properties_provided */
551 0, /* properties_destroyed */
552 0, /* todo_flags_start */
553 0, /* todo_flags_finish */
556 class pass_postreload
: public rtl_opt_pass
559 pass_postreload (gcc::context
*ctxt
)
560 : rtl_opt_pass (pass_data_postreload
, ctxt
)
563 /* opt_pass methods: */
564 virtual bool gate (function
*) { return reload_completed
; }
566 }; // class pass_postreload
570 static rtl_opt_pass
*
571 make_pass_postreload (gcc::context
*ctxt
)
573 return new pass_postreload (ctxt
);
578 /* Set the static pass number of pass PASS to ID and record that
579 in the mapping from static pass number to pass. */
583 set_pass_for_id (int id
, opt_pass
*pass
)
585 pass
->static_pass_number
= id
;
586 if (passes_by_id_size
<= id
)
588 passes_by_id
= XRESIZEVEC (opt_pass
*, passes_by_id
, id
+ 1);
589 memset (passes_by_id
+ passes_by_id_size
, 0,
590 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
591 passes_by_id_size
= id
+ 1;
593 passes_by_id
[id
] = pass
;
596 /* Return the pass with the static pass number ID. */
599 pass_manager::get_pass_for_id (int id
) const
601 if (id
>= passes_by_id_size
)
603 return passes_by_id
[id
];
606 /* Iterate over the pass tree allocating dump file numbers. We want
607 to do this depth first, and independent of whether the pass is
611 register_one_dump_file (opt_pass
*pass
)
613 g
->get_passes ()->register_one_dump_file (pass
);
617 pass_manager::register_one_dump_file (opt_pass
*pass
)
619 char *dot_name
, *flag_name
, *glob_name
;
620 const char *name
, *full_name
, *prefix
;
623 int optgroup_flags
= OPTGROUP_NONE
;
624 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
626 /* See below in next_pass_1. */
628 if (pass
->static_pass_number
!= -1)
629 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
630 ? 1 : pass
->static_pass_number
));
632 /* The name is both used to identify the pass for the purposes of plugins,
633 and to specify dump file name and option.
634 The latter two might want something short which is not quite unique; for
635 that reason, we may have a disambiguating prefix, followed by a space
636 to mark the start of the following dump file name / option string. */
637 name
= strchr (pass
->name
, ' ');
638 name
= name
? name
+ 1 : pass
->name
;
639 dot_name
= concat (".", name
, num
, NULL
);
640 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
644 optgroup_flags
|= OPTGROUP_IPA
;
646 else if (pass
->type
== GIMPLE_PASS
)
657 flag_name
= concat (prefix
, name
, num
, NULL
);
658 glob_name
= concat (prefix
, name
, NULL
);
659 optgroup_flags
|= pass
->optinfo_flags
;
660 /* For any passes that do not have an optgroup set, and which are not
661 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
662 any dump messages are emitted properly under -fopt-info(-optall). */
663 if (optgroup_flags
== OPTGROUP_NONE
)
664 optgroup_flags
= OPTGROUP_OTHER
;
665 id
= dumps
->dump_register (dot_name
, flag_name
, glob_name
, flags
,
667 set_pass_for_id (id
, pass
);
668 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
669 register_pass_name (pass
, full_name
);
670 free (CONST_CAST (char *, full_name
));
673 /* Register the dump files for the pass_manager starting at PASS. */
676 pass_manager::register_dump_files (opt_pass
*pass
)
680 if (pass
->name
&& pass
->name
[0] != '*')
681 register_one_dump_file (pass
);
684 register_dump_files (pass
->sub
);
691 /* Helper for pass_registry hash table. */
693 struct pass_registry_hasher
: default_hashmap_traits
695 static inline hashval_t
hash (const char *);
696 static inline bool equal_keys (const char *, const char *);
699 /* Pass registry hash function. */
702 pass_registry_hasher::hash (const char *name
)
704 return htab_hash_string (name
);
707 /* Hash equal function */
710 pass_registry_hasher::equal_keys (const char *s1
, const char *s2
)
712 return !strcmp (s1
, s2
);
715 static hash_map
<const char *, opt_pass
*, pass_registry_hasher
>
718 /* Register PASS with NAME. */
721 register_pass_name (opt_pass
*pass
, const char *name
)
723 if (!name_to_pass_map
)
725 = new hash_map
<const char *, opt_pass
*, pass_registry_hasher
> (256);
727 if (name_to_pass_map
->get (name
))
728 return; /* Ignore plugin passes. */
730 const char *unique_name
= xstrdup (name
);
731 name_to_pass_map
->put (unique_name
, pass
);
734 /* Map from pass id to canonicalized pass name. */
736 typedef const char *char_ptr
;
737 static vec
<char_ptr
> pass_tab
= vNULL
;
739 /* Callback function for traversing NAME_TO_PASS_MAP. */
742 passes_pass_traverse (const char *const &name
, opt_pass
*const &pass
, void *)
744 gcc_assert (pass
->static_pass_number
> 0);
745 gcc_assert (pass_tab
.exists ());
747 pass_tab
[pass
->static_pass_number
] = name
;
752 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
753 table for dumping purpose. */
756 create_pass_tab (void)
758 if (!flag_dump_passes
)
761 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
762 name_to_pass_map
->traverse
<void *, passes_pass_traverse
> (NULL
);
765 static bool override_gate_status (opt_pass
*, tree
, bool);
767 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
768 is turned on or not. */
771 dump_one_pass (opt_pass
*pass
, int pass_indent
)
773 int indent
= 3 * pass_indent
;
775 bool is_on
, is_really_on
;
777 is_on
= pass
->gate (cfun
);
778 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
780 if (pass
->static_pass_number
<= 0)
783 pn
= pass_tab
[pass
->static_pass_number
];
785 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
786 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
787 is_on
? " ON" : " OFF",
788 ((!is_on
) == (!is_really_on
) ? ""
789 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
792 /* Dump pass list PASS with indentation INDENT. */
795 dump_pass_list (opt_pass
*pass
, int indent
)
799 dump_one_pass (pass
, indent
);
801 dump_pass_list (pass
->sub
, indent
+ 1);
807 /* Dump all optimization passes. */
812 g
->get_passes ()->dump_passes ();
816 pass_manager::dump_passes () const
818 struct cgraph_node
*n
, *node
= NULL
;
822 FOR_EACH_FUNCTION (n
)
823 if (DECL_STRUCT_FUNCTION (n
->decl
))
832 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
834 dump_pass_list (all_lowering_passes
, 1);
835 dump_pass_list (all_small_ipa_passes
, 1);
836 dump_pass_list (all_regular_ipa_passes
, 1);
837 dump_pass_list (all_late_ipa_passes
, 1);
838 dump_pass_list (all_passes
, 1);
844 /* Returns the pass with NAME. */
847 get_pass_by_name (const char *name
)
849 opt_pass
**p
= name_to_pass_map
->get (name
);
857 /* Range [start, last]. */
863 const char *assem_name
;
864 struct uid_range
*next
;
867 typedef struct uid_range
*uid_range_p
;
870 static vec
<uid_range_p
>
871 enabled_pass_uid_range_tab
= vNULL
;
872 static vec
<uid_range_p
>
873 disabled_pass_uid_range_tab
= vNULL
;
876 /* Parse option string for -fdisable- and -fenable-
877 The syntax of the options:
880 -fdisable-<pass_name>
882 -fenable-<pass_name>=s1:e1,s2:e2,...
883 -fdisable-<pass_name>=s1:e1,s2:e2,...
887 enable_disable_pass (const char *arg
, bool is_enable
)
890 char *range_str
, *phase_name
;
891 char *argstr
= xstrdup (arg
);
892 vec
<uid_range_p
> *tab
= 0;
894 range_str
= strchr (argstr
,'=');
905 error ("unrecognized option -fenable");
907 error ("unrecognized option -fdisable");
911 pass
= get_pass_by_name (phase_name
);
912 if (!pass
|| pass
->static_pass_number
== -1)
915 error ("unknown pass %s specified in -fenable", phase_name
);
917 error ("unknown pass %s specified in -fdisable", phase_name
);
923 tab
= &enabled_pass_uid_range_tab
;
925 tab
= &disabled_pass_uid_range_tab
;
927 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
928 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
933 uid_range_p new_range
= XCNEW (struct uid_range
);
935 new_range
->start
= 0;
936 new_range
->last
= (unsigned)-1;
938 slot
= (*tab
)[pass
->static_pass_number
];
939 new_range
->next
= slot
;
940 (*tab
)[pass
->static_pass_number
] = new_range
;
942 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
943 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
945 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
946 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
950 char *next_range
= NULL
;
951 char *one_range
= range_str
;
952 char *end_val
= NULL
;
957 uid_range_p new_range
;
958 char *invalid
= NULL
;
960 char *func_name
= NULL
;
962 next_range
= strchr (one_range
, ',');
969 end_val
= strchr (one_range
, ':');
975 start
= strtol (one_range
, &invalid
, 10);
976 if (*invalid
|| start
< 0)
978 if (end_val
|| (one_range
[0] >= '0'
979 && one_range
[0] <= '9'))
981 error ("Invalid range %s in option %s",
983 is_enable
? "-fenable" : "-fdisable");
987 func_name
= one_range
;
991 new_range
= XCNEW (struct uid_range
);
994 new_range
->start
= (unsigned) start
;
995 new_range
->last
= (unsigned) start
;
999 new_range
->start
= (unsigned) -1;
1000 new_range
->last
= (unsigned) -1;
1001 new_range
->assem_name
= xstrdup (func_name
);
1006 long last
= strtol (end_val
, &invalid
, 10);
1007 if (*invalid
|| last
< start
)
1009 error ("Invalid range %s in option %s",
1011 is_enable
? "-fenable" : "-fdisable");
1015 new_range
= XCNEW (struct uid_range
);
1016 new_range
->start
= (unsigned) start
;
1017 new_range
->last
= (unsigned) last
;
1020 slot
= (*tab
)[pass
->static_pass_number
];
1021 new_range
->next
= slot
;
1022 (*tab
)[pass
->static_pass_number
] = new_range
;
1025 if (new_range
->assem_name
)
1026 inform (UNKNOWN_LOCATION
,
1027 "enable pass %s for function %s",
1028 phase_name
, new_range
->assem_name
);
1030 inform (UNKNOWN_LOCATION
,
1031 "enable pass %s for functions in the range of [%u, %u]",
1032 phase_name
, new_range
->start
, new_range
->last
);
1036 if (new_range
->assem_name
)
1037 inform (UNKNOWN_LOCATION
,
1038 "disable pass %s for function %s",
1039 phase_name
, new_range
->assem_name
);
1041 inform (UNKNOWN_LOCATION
,
1042 "disable pass %s for functions in the range of [%u, %u]",
1043 phase_name
, new_range
->start
, new_range
->last
);
1046 one_range
= next_range
;
1047 } while (next_range
);
1053 /* Enable pass specified by ARG. */
1056 enable_pass (const char *arg
)
1058 enable_disable_pass (arg
, true);
1061 /* Disable pass specified by ARG. */
1064 disable_pass (const char *arg
)
1066 enable_disable_pass (arg
, false);
1069 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1072 is_pass_explicitly_enabled_or_disabled (opt_pass
*pass
,
1074 vec
<uid_range_p
> tab
)
1076 uid_range_p slot
, range
;
1078 const char *aname
= NULL
;
1081 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1082 || pass
->static_pass_number
== -1)
1085 slot
= tab
[pass
->static_pass_number
];
1089 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
1090 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1091 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1096 if ((unsigned) cgraph_uid
>= range
->start
1097 && (unsigned) cgraph_uid
<= range
->last
)
1099 if (range
->assem_name
&& aname
1100 && !strcmp (range
->assem_name
, aname
))
1102 range
= range
->next
;
1109 /* Update static_pass_number for passes (and the flag
1110 TODO_mark_first_instance).
1112 Passes are constructed with static_pass_number preinitialized to 0
1114 This field is used in two different ways: initially as instance numbers
1115 of their kind, and then as ids within the entire pass manager.
1117 Within pass_manager::pass_manager:
1119 * In add_pass_instance(), as called by next_pass_1 in
1120 NEXT_PASS in init_optimization_passes
1122 * When the initial instance of a pass within a pass manager is seen,
1123 it is flagged, and its static_pass_number is set to -1
1125 * On subsequent times that it is seen, the static pass number
1126 is decremented each time, so that if there are e.g. 4 dups,
1127 they have static_pass_number -4, 2, 3, 4 respectively (note
1128 how the initial one is negative and gives the count); these
1129 can be thought of as instance numbers of the specific pass
1131 * Within the register_dump_files () traversal, set_pass_for_id()
1132 is called on each pass, using these instance numbers to create
1133 dumpfile switches, and then overwriting them with a pass id,
1134 which are global to the whole pass manager (based on
1135 (TDI_end + current value of extra_dump_files_in_use) ) */
1138 add_pass_instance (opt_pass
*new_pass
, bool track_duplicates
,
1139 opt_pass
*initial_pass
)
1141 /* Are we dealing with the first pass of its kind, or a clone? */
1142 if (new_pass
!= initial_pass
)
1144 /* We're dealing with a clone. */
1145 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1147 /* Indicate to register_dump_files that this pass has duplicates,
1148 and so it should rename the dump file. The first instance will
1149 be -1, and be number of duplicates = -static_pass_number - 1.
1150 Subsequent instances will be > 0 and just the duplicate number. */
1151 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1153 initial_pass
->static_pass_number
-= 1;
1154 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1159 /* We're dealing with the first pass of its kind. */
1160 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1161 new_pass
->static_pass_number
= -1;
1163 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1167 /* Add a pass to the pass list. Duplicate the pass if it's already
1171 next_pass_1 (opt_pass
**list
, opt_pass
*pass
, opt_pass
*initial_pass
)
1173 /* Every pass should have a name so that plugins can refer to them. */
1174 gcc_assert (pass
->name
!= NULL
);
1176 add_pass_instance (pass
, false, initial_pass
);
1179 return &(*list
)->next
;
1182 /* List node for an inserted pass instance. We need to keep track of all
1183 the newly-added pass instances (with 'added_pass_nodes' defined below)
1184 so that we can register their dump files after pass-positioning is finished.
1185 Registering dumping files needs to be post-processed or the
1186 static_pass_number of the opt_pass object would be modified and mess up
1187 the dump file names of future pass instances to be added. */
1189 struct pass_list_node
1192 struct pass_list_node
*next
;
1195 static struct pass_list_node
*added_pass_nodes
= NULL
;
1196 static struct pass_list_node
*prev_added_pass_node
;
1198 /* Insert the pass at the proper position. Return true if the pass
1199 is successfully added.
1201 NEW_PASS_INFO - new pass to be inserted
1202 PASS_LIST - root of the pass list to insert the new pass to */
1205 position_pass (struct register_pass_info
*new_pass_info
, opt_pass
**pass_list
)
1207 opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1208 bool success
= false;
1210 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1212 /* Check if the current pass is of the same type as the new pass and
1213 matches the name and the instance number of the reference pass. */
1214 if (pass
->type
== new_pass_info
->pass
->type
1216 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1217 && ((new_pass_info
->ref_pass_instance_number
== 0)
1218 || (new_pass_info
->ref_pass_instance_number
==
1219 pass
->static_pass_number
)
1220 || (new_pass_info
->ref_pass_instance_number
== 1
1221 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1224 struct pass_list_node
*new_pass_node
;
1226 if (new_pass_info
->ref_pass_instance_number
== 0)
1228 new_pass
= new_pass_info
->pass
->clone ();
1229 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1233 new_pass
= new_pass_info
->pass
;
1234 add_pass_instance (new_pass
, true, new_pass
);
1237 /* Insert the new pass instance based on the positioning op. */
1238 switch (new_pass_info
->pos_op
)
1240 case PASS_POS_INSERT_AFTER
:
1241 new_pass
->next
= pass
->next
;
1242 pass
->next
= new_pass
;
1244 /* Skip newly inserted pass to avoid repeated
1245 insertions in the case where the new pass and the
1246 existing one have the same name. */
1249 case PASS_POS_INSERT_BEFORE
:
1250 new_pass
->next
= pass
;
1252 prev_pass
->next
= new_pass
;
1254 *pass_list
= new_pass
;
1256 case PASS_POS_REPLACE
:
1257 new_pass
->next
= pass
->next
;
1259 prev_pass
->next
= new_pass
;
1261 *pass_list
= new_pass
;
1262 new_pass
->sub
= pass
->sub
;
1263 new_pass
->tv_id
= pass
->tv_id
;
1267 error ("invalid pass positioning operation");
1271 /* Save the newly added pass (instance) in the added_pass_nodes
1272 list so that we can register its dump file later. Note that
1273 we cannot register the dump file now because doing so will modify
1274 the static_pass_number of the opt_pass object and therefore
1275 mess up the dump file name of future instances. */
1276 new_pass_node
= XCNEW (struct pass_list_node
);
1277 new_pass_node
->pass
= new_pass
;
1278 if (!added_pass_nodes
)
1279 added_pass_nodes
= new_pass_node
;
1281 prev_added_pass_node
->next
= new_pass_node
;
1282 prev_added_pass_node
= new_pass_node
;
1287 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1294 /* Hooks a new pass into the pass lists.
1296 PASS_INFO - pass information that specifies the opt_pass object,
1297 reference pass, instance number, and how to position
1301 register_pass (struct register_pass_info
*pass_info
)
1303 g
->get_passes ()->register_pass (pass_info
);
1307 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1308 const char* ref_pass_name
, int ref_pass_inst_number
)
1310 register_pass_info i
;
1312 i
.reference_pass_name
= ref_pass_name
;
1313 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1316 g
->get_passes ()->register_pass (&i
);
1320 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1322 bool all_instances
, success
;
1323 gcc::dump_manager
*dumps
= m_ctxt
->get_dumps ();
1325 /* The checks below could fail in buggy plugins. Existing GCC
1326 passes should never fail these checks, so we mention plugin in
1328 if (!pass_info
->pass
)
1329 fatal_error ("plugin cannot register a missing pass");
1331 if (!pass_info
->pass
->name
)
1332 fatal_error ("plugin cannot register an unnamed pass");
1334 if (!pass_info
->reference_pass_name
)
1336 ("plugin cannot register pass %qs without reference pass name",
1337 pass_info
->pass
->name
);
1339 /* Try to insert the new pass to the pass lists. We need to check
1340 all five lists as the reference pass could be in one (or all) of
1342 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1343 success
= position_pass (pass_info
, &all_lowering_passes
);
1344 if (!success
|| all_instances
)
1345 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1346 if (!success
|| all_instances
)
1347 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1348 if (!success
|| all_instances
)
1349 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1350 if (!success
|| all_instances
)
1351 success
|= position_pass (pass_info
, &all_passes
);
1354 ("pass %qs not found but is referenced by new pass %qs",
1355 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1357 /* OK, we have successfully inserted the new pass. We need to register
1358 the dump files for the newly added pass and its duplicates (if any).
1359 Because the registration of plugin/backend passes happens after the
1360 command-line options are parsed, the options that specify single
1361 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1362 passes. Therefore we currently can only enable dumping of
1363 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1364 are specified. While doing so, we also delete the pass_list_node
1365 objects created during pass positioning. */
1366 while (added_pass_nodes
)
1368 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1369 enum tree_dump_index tdi
;
1370 register_one_dump_file (added_pass_nodes
->pass
);
1371 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1372 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1374 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1378 /* Check if dump-all flag is specified. */
1379 if (dumps
->get_dump_file_info (tdi
)->pstate
)
1380 dumps
->get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1381 ->pstate
= dumps
->get_dump_file_info (tdi
)->pstate
;
1382 XDELETE (added_pass_nodes
);
1383 added_pass_nodes
= next_node
;
1387 /* Construct the pass tree. The sequencing of passes is driven by
1388 the cgraph routines:
1390 finalize_compilation_unit ()
1391 for each node N in the cgraph
1392 cgraph_analyze_function (N)
1393 cgraph_lower_function (N) -> all_lowering_passes
1395 If we are optimizing, compile is then invoked:
1398 ipa_passes () -> all_small_ipa_passes
1399 -> Analysis of all_regular_ipa_passes
1400 * possible LTO streaming at copmilation time *
1401 -> Execution of all_regular_ipa_passes
1402 * possible LTO streaming at link time *
1403 -> all_late_ipa_passes
1404 expand_all_functions ()
1405 for each node N in the cgraph
1406 expand_function (N) -> Transformation of all_regular_ipa_passes
1411 pass_manager::operator new (size_t sz
)
1413 /* Ensure that all fields of the pass manager are zero-initialized. */
1414 return xcalloc (1, sz
);
1417 pass_manager::pass_manager (context
*ctxt
)
1418 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1419 all_regular_ipa_passes (NULL
),
1420 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1425 /* Initialize the pass_lists array. */
1426 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1428 #undef DEF_PASS_LIST
1430 /* Build the tree of passes. */
1432 #define INSERT_PASSES_AFTER(PASS) \
1435 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1437 opt_pass **p = &(PASS ## _1)->sub;
1439 #define POP_INSERT_PASSES() \
1442 #define NEXT_PASS(PASS, NUM) \
1444 gcc_assert (NULL == PASS ## _ ## NUM); \
1446 PASS ## _1 = make_##PASS (m_ctxt); \
1449 gcc_assert (PASS ## _1); \
1450 PASS ## _ ## NUM = PASS ## _1->clone (); \
1452 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1455 #define TERMINATE_PASS_LIST() \
1458 #include "pass-instances.def"
1460 #undef INSERT_PASSES_AFTER
1461 #undef PUSH_INSERT_PASSES_WITHIN
1462 #undef POP_INSERT_PASSES
1464 #undef TERMINATE_PASS_LIST
1466 /* Register the passes with the tree dump code. */
1467 register_dump_files (all_lowering_passes
);
1468 register_dump_files (all_small_ipa_passes
);
1469 register_dump_files (all_regular_ipa_passes
);
1470 register_dump_files (all_late_ipa_passes
);
1471 register_dump_files (all_passes
);
1474 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1475 function CALLBACK for every function in the call graph. Otherwise,
1476 call CALLBACK on the current function. */
1479 do_per_function (void (*callback
) (function
*, void *data
), void *data
)
1481 if (current_function_decl
)
1482 callback (cfun
, data
);
1485 struct cgraph_node
*node
;
1486 FOR_EACH_DEFINED_FUNCTION (node
)
1487 if (node
->analyzed
&& gimple_has_body_p (node
->decl
)
1488 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
1489 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1493 /* Because inlining might remove no-longer reachable nodes, we need to
1494 keep the array visible to garbage collector to avoid reading collected
1497 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1499 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1500 function CALLBACK for every function in the call graph. Otherwise,
1501 call CALLBACK on the current function.
1502 This function is global so that plugins can use it. */
1504 do_per_function_toporder (void (*callback
) (function
*, void *data
), void *data
)
1508 if (current_function_decl
)
1509 callback (cfun
, data
);
1512 gcc_assert (!order
);
1513 order
= ggc_vec_alloc
<cgraph_node_ptr
> (cgraph_n_nodes
);
1514 nnodes
= ipa_reverse_postorder (order
);
1515 for (i
= nnodes
- 1; i
>= 0; i
--)
1516 order
[i
]->process
= 1;
1517 for (i
= nnodes
- 1; i
>= 0; i
--)
1519 struct cgraph_node
*node
= order
[i
];
1521 /* Allow possibly removed nodes to be garbage collected. */
1524 if (cgraph_function_with_gimple_body_p (node
))
1525 callback (DECL_STRUCT_FUNCTION (node
->decl
), data
);
1533 /* Helper function to perform function body dump. */
1536 execute_function_dump (function
*fn
, void *data
)
1538 opt_pass
*pass
= (opt_pass
*)data
;
1544 if (fn
->curr_properties
& PROP_trees
)
1545 dump_function_to_file (fn
->decl
, dump_file
, dump_flags
);
1547 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1549 /* Flush the file. If verification fails, we won't be able to
1550 close the file before aborting. */
1553 if ((fn
->curr_properties
& PROP_cfg
)
1554 && (dump_flags
& TDF_GRAPH
))
1556 if (!pass
->graph_dump_initialized
)
1558 clean_graph_dump_file (dump_file_name
);
1559 pass
->graph_dump_initialized
= true;
1561 print_graph_cfg (dump_file_name
, fn
);
1568 static struct profile_record
*profile_record
;
1570 /* Do profile consistency book-keeping for the pass with static number INDEX.
1571 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1572 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1573 if we are only book-keeping on passes that may have selectively disabled
1574 themselves on a given function. */
1576 check_profile_consistency (int index
, int subpass
, bool run
)
1578 pass_manager
*passes
= g
->get_passes ();
1581 if (!profile_record
)
1582 profile_record
= XCNEWVEC (struct profile_record
,
1583 passes
->passes_by_id_size
);
1584 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1585 gcc_assert (subpass
< 2);
1586 profile_record
[index
].run
|= run
;
1587 account_profile_record (&profile_record
[index
], subpass
);
1590 /* Output profile consistency. */
1593 dump_profile_report (void)
1595 g
->get_passes ()->dump_profile_report ();
1599 pass_manager::dump_profile_report () const
1602 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1603 gcov_type last_time
= 0, last_size
= 0;
1604 double rel_time_change
, rel_size_change
;
1605 int last_reported
= 0;
1607 if (!profile_record
)
1609 fprintf (stderr
, "\nProfile consistency report:\n\n");
1610 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1611 fprintf (stderr
, " |freq count |freq count |size time\n");
1613 for (i
= 0; i
< passes_by_id_size
; i
++)
1614 for (j
= 0 ; j
< 2; j
++)
1615 if (profile_record
[i
].run
)
1618 rel_time_change
= (profile_record
[i
].time
[j
]
1619 - (double)last_time
) * 100 / (double)last_time
;
1621 rel_time_change
= 0;
1623 rel_size_change
= (profile_record
[i
].size
[j
]
1624 - (double)last_size
) * 100 / (double)last_size
;
1626 rel_size_change
= 0;
1628 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1629 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1630 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1631 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1632 || rel_time_change
|| rel_size_change
)
1635 fprintf (stderr
, "%-20s %s",
1636 passes_by_id
[i
]->name
,
1637 j
? "(after TODO)" : " ");
1638 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1639 fprintf (stderr
, "| %+5i",
1640 profile_record
[i
].num_mismatched_freq_in
[j
]
1643 fprintf (stderr
, "| ");
1644 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1645 fprintf (stderr
, " %+5i",
1646 profile_record
[i
].num_mismatched_count_in
[j
]
1649 fprintf (stderr
, " ");
1650 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1651 fprintf (stderr
, "| %+5i",
1652 profile_record
[i
].num_mismatched_freq_out
[j
]
1655 fprintf (stderr
, "| ");
1656 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1657 fprintf (stderr
, " %+5i",
1658 profile_record
[i
].num_mismatched_count_out
[j
]
1661 fprintf (stderr
, " ");
1663 /* Size/time units change across gimple and RTL. */
1664 if (i
== pass_expand_1
->static_pass_number
)
1665 fprintf (stderr
, "|----------");
1668 if (rel_size_change
)
1669 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1671 fprintf (stderr
, "| ");
1672 if (rel_time_change
)
1673 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1675 fprintf (stderr
, "\n");
1676 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1677 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1678 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1679 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1681 else if (j
&& last_reported
!= i
)
1684 fprintf (stderr
, "%-20s ------------| | |\n",
1685 passes_by_id
[i
]->name
);
1687 last_time
= profile_record
[i
].time
[j
];
1688 last_size
= profile_record
[i
].size
[j
];
1692 /* Perform all TODO actions that ought to be done on each function. */
1695 execute_function_todo (function
*fn
, void *data
)
1697 bool from_ipa_pass
= (cfun
== NULL
);
1698 unsigned int flags
= (size_t)data
;
1699 flags
&= ~fn
->last_verified
;
1705 /* Always cleanup the CFG before trying to update SSA. */
1706 if (flags
& TODO_cleanup_cfg
)
1708 cleanup_tree_cfg ();
1710 /* When cleanup_tree_cfg merges consecutive blocks, it may
1711 perform some simplistic propagation when removing single
1712 valued PHI nodes. This propagation may, in turn, cause the
1713 SSA form to become out-of-date (see PR 22037). So, even
1714 if the parent pass had not scheduled an SSA update, we may
1715 still need to do one. */
1716 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1717 flags
|= TODO_update_ssa
;
1720 if (flags
& TODO_update_ssa_any
)
1722 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1723 update_ssa (update_flags
);
1726 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1727 compute_may_aliases ();
1729 if (optimize
&& (flags
& TODO_update_address_taken
))
1730 execute_update_addresses_taken ();
1732 if (flags
& TODO_remove_unused_locals
)
1733 remove_unused_locals ();
1735 if (flags
& TODO_rebuild_frequencies
)
1736 rebuild_frequencies ();
1738 if (flags
& TODO_rebuild_cgraph_edges
)
1739 rebuild_cgraph_edges ();
1741 /* If we've seen errors do not bother running any verifiers. */
1744 #if defined ENABLE_CHECKING
1745 dom_state pre_verify_state
= dom_info_state (fn
, CDI_DOMINATORS
);
1746 dom_state pre_verify_pstate
= dom_info_state (fn
, CDI_POST_DOMINATORS
);
1748 if (flags
& TODO_verify_il
)
1750 if (cfun
->curr_properties
& PROP_trees
)
1752 if (cfun
->curr_properties
& PROP_cfg
)
1753 /* IPA passes leave stmts to be fixed up, so make sure to
1754 not verify stmts really throw. */
1755 verify_gimple_in_cfg (cfun
, !from_ipa_pass
);
1757 verify_gimple_in_seq (gimple_body (cfun
->decl
));
1759 if (cfun
->curr_properties
& PROP_ssa
)
1760 /* IPA passes leave stmts to be fixed up, so make sure to
1761 not verify SSA operands whose verifier will choke on that. */
1762 verify_ssa (true, !from_ipa_pass
);
1763 /* IPA passes leave basic-blocks unsplit, so make sure to
1764 not trip on that. */
1765 if ((cfun
->curr_properties
& PROP_cfg
)
1767 verify_flow_info ();
1769 && loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1770 verify_loop_closed_ssa (false);
1771 if (cfun
->curr_properties
& PROP_rtl
)
1772 verify_rtl_sharing ();
1775 /* Make sure verifiers don't change dominator state. */
1776 gcc_assert (dom_info_state (fn
, CDI_DOMINATORS
) == pre_verify_state
);
1777 gcc_assert (dom_info_state (fn
, CDI_POST_DOMINATORS
) == pre_verify_pstate
);
1781 fn
->last_verified
= flags
& TODO_verify_all
;
1785 /* For IPA passes make sure to release dominator info, it can be
1786 computed by non-verifying TODOs. */
1789 free_dominance_info (fn
, CDI_DOMINATORS
);
1790 free_dominance_info (fn
, CDI_POST_DOMINATORS
);
1794 /* Perform all TODO actions. */
1796 execute_todo (unsigned int flags
)
1798 #if defined ENABLE_CHECKING
1800 && need_ssa_update_p (cfun
))
1801 gcc_assert (flags
& TODO_update_ssa_any
);
1804 timevar_push (TV_TODO
);
1806 /* Inform the pass whether it is the first time it is run. */
1807 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1809 statistics_fini_pass ();
1812 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1814 /* Always remove functions just as before inlining: IPA passes might be
1815 interested to see bodies of extern inline functions that are not inlined
1816 to analyze side effects. The full removal is done just at the end
1817 of IPA pass queue. */
1818 if (flags
& TODO_remove_functions
)
1821 symtab_remove_unreachable_nodes (true, dump_file
);
1824 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1827 dump_symtab (dump_file
);
1828 /* Flush the file. If verification fails, we won't be able to
1829 close the file before aborting. */
1833 /* Now that the dumping has been done, we can get rid of the optional
1835 if (flags
& TODO_df_finish
)
1836 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1838 timevar_pop (TV_TODO
);
1841 /* Verify invariants that should hold between passes. This is a place
1842 to put simple sanity checks. */
1845 verify_interpass_invariants (void)
1847 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1850 /* Clear the last verified flag. */
1853 clear_last_verified (function
*fn
, void *data ATTRIBUTE_UNUSED
)
1855 fn
->last_verified
= 0;
1858 /* Helper function. Verify that the properties has been turn into the
1859 properties expected by the pass. */
1861 #ifdef ENABLE_CHECKING
1863 verify_curr_properties (function
*fn
, void *data
)
1865 unsigned int props
= (size_t)data
;
1866 gcc_assert ((fn
->curr_properties
& props
) == props
);
1870 /* Initialize pass dump file. */
1871 /* This is non-static so that the plugins can use it. */
1874 pass_init_dump_file (opt_pass
*pass
)
1876 /* If a dump file name is present, open it if enabled. */
1877 if (pass
->static_pass_number
!= -1)
1879 timevar_push (TV_DUMP
);
1880 gcc::dump_manager
*dumps
= g
->get_dumps ();
1881 bool initializing_dump
=
1882 !dumps
->dump_initialized_p (pass
->static_pass_number
);
1883 dump_file_name
= dumps
->get_dump_file_name (pass
->static_pass_number
);
1884 dumps
->dump_start (pass
->static_pass_number
, &dump_flags
);
1885 if (dump_file
&& current_function_decl
)
1886 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1887 if (initializing_dump
1888 && dump_file
&& (dump_flags
& TDF_GRAPH
)
1889 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1891 clean_graph_dump_file (dump_file_name
);
1892 pass
->graph_dump_initialized
= true;
1894 timevar_pop (TV_DUMP
);
1895 return initializing_dump
;
1901 /* Flush PASS dump file. */
1902 /* This is non-static so that plugins can use it. */
1905 pass_fini_dump_file (opt_pass
*pass
)
1907 timevar_push (TV_DUMP
);
1909 /* Flush and close dump file. */
1912 free (CONST_CAST (char *, dump_file_name
));
1913 dump_file_name
= NULL
;
1916 g
->get_dumps ()->dump_finish (pass
->static_pass_number
);
1917 timevar_pop (TV_DUMP
);
1920 /* After executing the pass, apply expected changes to the function
1924 update_properties_after_pass (function
*fn
, void *data
)
1926 opt_pass
*pass
= (opt_pass
*) data
;
1927 fn
->curr_properties
= (fn
->curr_properties
| pass
->properties_provided
)
1928 & ~pass
->properties_destroyed
;
1931 /* Execute summary generation for all of the passes in IPA_PASS. */
1934 execute_ipa_summary_passes (ipa_opt_pass_d
*ipa_pass
)
1938 opt_pass
*pass
= ipa_pass
;
1940 /* Execute all of the IPA_PASSes in the list. */
1941 if (ipa_pass
->type
== IPA_PASS
1942 && pass
->gate (cfun
)
1943 && ipa_pass
->generate_summary
)
1945 pass_init_dump_file (pass
);
1947 /* If a timevar is present, start it. */
1949 timevar_push (pass
->tv_id
);
1951 ipa_pass
->generate_summary ();
1955 timevar_pop (pass
->tv_id
);
1957 pass_fini_dump_file (pass
);
1959 ipa_pass
= (ipa_opt_pass_d
*)ipa_pass
->next
;
1963 /* Execute IPA_PASS function transform on NODE. */
1966 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
1967 ipa_opt_pass_d
*ipa_pass
)
1969 opt_pass
*pass
= ipa_pass
;
1970 unsigned int todo_after
= 0;
1972 current_pass
= pass
;
1973 if (!ipa_pass
->function_transform
)
1976 /* Note that the folders should only create gimple expressions.
1977 This is a hack until the new folder is ready. */
1978 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
1980 pass_init_dump_file (pass
);
1982 /* Run pre-pass verification. */
1983 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
1985 /* If a timevar is present, start it. */
1986 if (pass
->tv_id
!= TV_NONE
)
1987 timevar_push (pass
->tv_id
);
1990 todo_after
= ipa_pass
->function_transform (node
);
1993 if (pass
->tv_id
!= TV_NONE
)
1994 timevar_pop (pass
->tv_id
);
1996 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1997 check_profile_consistency (pass
->static_pass_number
, 0, true);
1999 /* Run post-pass cleanup and verification. */
2000 execute_todo (todo_after
);
2001 verify_interpass_invariants ();
2002 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2003 check_profile_consistency (pass
->static_pass_number
, 1, true);
2006 do_per_function (execute_function_dump
, NULL
);
2007 pass_fini_dump_file (pass
);
2009 current_pass
= NULL
;
2011 /* Signal this is a suitable GC collection point. */
2012 if (!(todo_after
& TODO_do_not_ggc_collect
))
2016 /* For the current function, execute all ipa transforms. */
2019 execute_all_ipa_transforms (void)
2021 struct cgraph_node
*node
;
2024 node
= cgraph_get_node (current_function_decl
);
2026 if (node
->ipa_transforms_to_apply
.exists ())
2030 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2031 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2032 node
->ipa_transforms_to_apply
.release ();
2036 /* Check if PASS is explicitly disabled or enabled and return
2037 the gate status. FUNC is the function to be processed, and
2038 GATE_STATUS is the gate status determined by pass manager by
2042 override_gate_status (opt_pass
*pass
, tree func
, bool gate_status
)
2044 bool explicitly_enabled
= false;
2045 bool explicitly_disabled
= false;
2048 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2049 enabled_pass_uid_range_tab
);
2051 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2052 disabled_pass_uid_range_tab
);
2054 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2063 execute_one_pass (opt_pass
*pass
)
2065 unsigned int todo_after
= 0;
2069 /* IPA passes are executed on whole program, so cfun should be NULL.
2070 Other passes need function context set. */
2071 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2072 gcc_assert (!cfun
&& !current_function_decl
);
2074 gcc_assert (cfun
&& current_function_decl
);
2076 current_pass
= pass
;
2078 /* Check whether gate check should be avoided.
2079 User controls the value of the gate through the parameter "gate_status". */
2080 gate_status
= pass
->gate (cfun
);
2081 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2083 /* Override gate with plugin. */
2084 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2088 /* Run so passes selectively disabling themselves on a given function
2089 are not miscounted. */
2090 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2092 check_profile_consistency (pass
->static_pass_number
, 0, false);
2093 check_profile_consistency (pass
->static_pass_number
, 1, false);
2095 current_pass
= NULL
;
2099 /* Pass execution event trigger: useful to identify passes being
2101 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2103 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2104 Apply all trnasforms first. */
2105 if (pass
->type
== SIMPLE_IPA_PASS
)
2107 struct cgraph_node
*node
;
2108 bool applied
= false;
2109 FOR_EACH_DEFINED_FUNCTION (node
)
2111 && cgraph_function_with_gimple_body_p (node
)
2112 && (!node
->clone_of
|| node
->decl
!= node
->clone_of
->decl
))
2114 if (!node
->global
.inlined_to
2115 && node
->ipa_transforms_to_apply
.exists ())
2117 cgraph_get_body (node
);
2118 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2119 execute_all_ipa_transforms ();
2120 rebuild_cgraph_edges ();
2121 free_dominance_info (CDI_DOMINATORS
);
2122 free_dominance_info (CDI_POST_DOMINATORS
);
2128 symtab_remove_unreachable_nodes (true, dump_file
);
2129 /* Restore current_pass. */
2130 current_pass
= pass
;
2133 if (!quiet_flag
&& !cfun
)
2134 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2136 /* Note that the folders should only create gimple expressions.
2137 This is a hack until the new folder is ready. */
2138 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2140 pass_init_dump_file (pass
);
2142 /* Run pre-pass verification. */
2143 execute_todo (pass
->todo_flags_start
);
2145 #ifdef ENABLE_CHECKING
2146 do_per_function (verify_curr_properties
,
2147 (void *)(size_t)pass
->properties_required
);
2150 /* If a timevar is present, start it. */
2151 if (pass
->tv_id
!= TV_NONE
)
2152 timevar_push (pass
->tv_id
);
2155 if (pass
->has_execute
)
2157 todo_after
= pass
->execute (cfun
);
2158 do_per_function (clear_last_verified
, NULL
);
2162 if (pass
->tv_id
!= TV_NONE
)
2163 timevar_pop (pass
->tv_id
);
2165 do_per_function (update_properties_after_pass
, pass
);
2167 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2168 check_profile_consistency (pass
->static_pass_number
, 0, true);
2170 /* Run post-pass cleanup and verification. */
2171 execute_todo (todo_after
| pass
->todo_flags_finish
| TODO_verify_il
);
2172 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2173 check_profile_consistency (pass
->static_pass_number
, 1, true);
2175 verify_interpass_invariants ();
2177 do_per_function (execute_function_dump
, pass
);
2178 if (pass
->type
== IPA_PASS
)
2180 struct cgraph_node
*node
;
2181 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2182 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*)pass
);
2185 if (!current_function_decl
)
2186 cgraph_process_new_functions ();
2188 pass_fini_dump_file (pass
);
2190 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2191 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2192 || pass
->type
!= RTL_PASS
);
2194 current_pass
= NULL
;
2196 /* Signal this is a suitable GC collection point. */
2197 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2204 execute_pass_list_1 (opt_pass
*pass
)
2208 gcc_assert (pass
->type
== GIMPLE_PASS
2209 || pass
->type
== RTL_PASS
);
2210 if (execute_one_pass (pass
) && pass
->sub
)
2211 execute_pass_list_1 (pass
->sub
);
2218 execute_pass_list (function
*fn
, opt_pass
*pass
)
2221 execute_pass_list_1 (pass
);
2224 free_dominance_info (CDI_DOMINATORS
);
2225 free_dominance_info (CDI_POST_DOMINATORS
);
2230 /* Write out all LTO data. */
2234 timevar_push (TV_IPA_LTO_GIMPLE_OUT
);
2236 timevar_pop (TV_IPA_LTO_GIMPLE_OUT
);
2237 timevar_push (TV_IPA_LTO_DECL_OUT
);
2238 produce_asm_for_decls ();
2239 timevar_pop (TV_IPA_LTO_DECL_OUT
);
2242 /* Same as execute_pass_list but assume that subpasses of IPA passes
2243 are local passes. If SET is not NULL, write out summaries of only
2244 those node in SET. */
2247 ipa_write_summaries_2 (opt_pass
*pass
, struct lto_out_decl_state
*state
)
2251 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2252 gcc_assert (!current_function_decl
);
2254 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2255 if (pass
->type
== IPA_PASS
2256 && ipa_pass
->write_summary
2257 && pass
->gate (cfun
))
2259 /* If a timevar is present, start it. */
2261 timevar_push (pass
->tv_id
);
2263 pass_init_dump_file (pass
);
2265 ipa_pass
->write_summary ();
2267 pass_fini_dump_file (pass
);
2269 /* If a timevar is present, start it. */
2271 timevar_pop (pass
->tv_id
);
2274 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2275 ipa_write_summaries_2 (pass
->sub
, state
);
2281 /* Helper function of ipa_write_summaries. Creates and destroys the
2282 decl state and calls ipa_write_summaries_2 for all passes that have
2283 summaries. SET is the set of nodes to be written. */
2286 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2288 pass_manager
*passes
= g
->get_passes ();
2289 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2290 state
->symtab_node_encoder
= encoder
;
2292 lto_push_out_decl_state (state
);
2294 gcc_assert (!flag_wpa
);
2295 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2299 gcc_assert (lto_get_out_decl_state () == state
);
2300 lto_pop_out_decl_state ();
2301 lto_delete_out_decl_state (state
);
2304 /* Write out summaries for all the nodes in the callgraph. */
2307 ipa_write_summaries (void)
2309 lto_symtab_encoder_t encoder
;
2311 varpool_node
*vnode
;
2312 struct cgraph_node
*node
;
2313 struct cgraph_node
**order
;
2315 if (!flag_generate_lto
|| seen_error ())
2318 encoder
= lto_symtab_encoder_new (false);
2320 /* Create the callgraph set in the same order used in
2321 cgraph_expand_all_functions. This mostly facilitates debugging,
2322 since it causes the gimple file to be processed in the same order
2323 as the source code. */
2324 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2325 order_pos
= ipa_reverse_postorder (order
);
2326 gcc_assert (order_pos
== cgraph_n_nodes
);
2328 for (i
= order_pos
- 1; i
>= 0; i
--)
2330 struct cgraph_node
*node
= order
[i
];
2332 if (cgraph_function_with_gimple_body_p (node
))
2334 /* When streaming out references to statements as part of some IPA
2335 pass summary, the statements need to have uids assigned and the
2336 following does that for all the IPA passes here. Naturally, this
2337 ordering then matches the one IPA-passes get in their stmt_fixup
2340 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2341 renumber_gimple_stmt_uids ();
2344 if (node
->definition
)
2345 lto_set_symtab_encoder_in_partition (encoder
, node
);
2348 FOR_EACH_DEFINED_FUNCTION (node
)
2350 lto_set_symtab_encoder_in_partition (encoder
, node
);
2351 FOR_EACH_DEFINED_VARIABLE (vnode
)
2352 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
2354 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2359 /* Same as execute_pass_list but assume that subpasses of IPA passes
2360 are local passes. If SET is not NULL, write out optimization summaries of
2361 only those node in SET. */
2364 ipa_write_optimization_summaries_1 (opt_pass
*pass
,
2365 struct lto_out_decl_state
*state
)
2369 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*)pass
;
2370 gcc_assert (!current_function_decl
);
2372 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2373 if (pass
->type
== IPA_PASS
2374 && ipa_pass
->write_optimization_summary
2375 && pass
->gate (cfun
))
2377 /* If a timevar is present, start it. */
2379 timevar_push (pass
->tv_id
);
2381 pass_init_dump_file (pass
);
2383 ipa_pass
->write_optimization_summary ();
2385 pass_fini_dump_file (pass
);
2387 /* If a timevar is present, start it. */
2389 timevar_pop (pass
->tv_id
);
2392 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2393 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2399 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2400 NULL, write out all summaries of all nodes. */
2403 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2405 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2406 lto_symtab_encoder_iterator lsei
;
2407 state
->symtab_node_encoder
= encoder
;
2409 lto_push_out_decl_state (state
);
2410 for (lsei
= lsei_start_function_in_partition (encoder
);
2411 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2413 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2414 /* When streaming out references to statements as part of some IPA
2415 pass summary, the statements need to have uids assigned.
2417 For functions newly born at WPA stage we need to initialize
2419 if (node
->definition
2420 && gimple_has_body_p (node
->decl
))
2422 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2423 renumber_gimple_stmt_uids ();
2428 gcc_assert (flag_wpa
);
2429 pass_manager
*passes
= g
->get_passes ();
2430 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2434 gcc_assert (lto_get_out_decl_state () == state
);
2435 lto_pop_out_decl_state ();
2436 lto_delete_out_decl_state (state
);
2439 /* Same as execute_pass_list but assume that subpasses of IPA passes
2440 are local passes. */
2443 ipa_read_summaries_1 (opt_pass
*pass
)
2447 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2449 gcc_assert (!current_function_decl
);
2451 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2453 if (pass
->gate (cfun
))
2455 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2457 /* If a timevar is present, start it. */
2459 timevar_push (pass
->tv_id
);
2461 pass_init_dump_file (pass
);
2463 ipa_pass
->read_summary ();
2465 pass_fini_dump_file (pass
);
2469 timevar_pop (pass
->tv_id
);
2472 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2473 ipa_read_summaries_1 (pass
->sub
);
2480 /* Read all the summaries for all_regular_ipa_passes. */
2483 ipa_read_summaries (void)
2485 pass_manager
*passes
= g
->get_passes ();
2486 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2489 /* Same as execute_pass_list but assume that subpasses of IPA passes
2490 are local passes. */
2493 ipa_read_optimization_summaries_1 (opt_pass
*pass
)
2497 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2499 gcc_assert (!current_function_decl
);
2501 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2503 if (pass
->gate (cfun
))
2505 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2507 /* If a timevar is present, start it. */
2509 timevar_push (pass
->tv_id
);
2511 pass_init_dump_file (pass
);
2513 ipa_pass
->read_optimization_summary ();
2515 pass_fini_dump_file (pass
);
2519 timevar_pop (pass
->tv_id
);
2522 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2523 ipa_read_optimization_summaries_1 (pass
->sub
);
2529 /* Read all the summaries for all_regular_ipa_passes. */
2532 ipa_read_optimization_summaries (void)
2534 pass_manager
*passes
= g
->get_passes ();
2535 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2538 /* Same as execute_pass_list but assume that subpasses of IPA passes
2539 are local passes. */
2541 execute_ipa_pass_list (opt_pass
*pass
)
2545 gcc_assert (!current_function_decl
);
2547 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2548 if (execute_one_pass (pass
) && pass
->sub
)
2550 if (pass
->sub
->type
== GIMPLE_PASS
)
2552 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2553 do_per_function_toporder ((void (*)(function
*, void *))
2556 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2558 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2559 || pass
->sub
->type
== IPA_PASS
)
2560 execute_ipa_pass_list (pass
->sub
);
2564 gcc_assert (!current_function_decl
);
2565 cgraph_process_new_functions ();
2571 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2574 execute_ipa_stmt_fixups (opt_pass
*pass
,
2575 struct cgraph_node
*node
, gimple
*stmts
)
2579 /* Execute all of the IPA_PASSes in the list. */
2580 if (pass
->type
== IPA_PASS
2581 && pass
->gate (cfun
))
2583 ipa_opt_pass_d
*ipa_pass
= (ipa_opt_pass_d
*) pass
;
2585 if (ipa_pass
->stmt_fixup
)
2587 pass_init_dump_file (pass
);
2588 /* If a timevar is present, start it. */
2590 timevar_push (pass
->tv_id
);
2592 ipa_pass
->stmt_fixup (node
, stmts
);
2596 timevar_pop (pass
->tv_id
);
2597 pass_fini_dump_file (pass
);
2600 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2606 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2609 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2611 pass_manager
*passes
= g
->get_passes ();
2612 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2616 extern void debug_properties (unsigned int);
2617 extern void dump_properties (FILE *, unsigned int);
2620 dump_properties (FILE *dump
, unsigned int props
)
2622 fprintf (dump
, "Properties:\n");
2623 if (props
& PROP_gimple_any
)
2624 fprintf (dump
, "PROP_gimple_any\n");
2625 if (props
& PROP_gimple_lcf
)
2626 fprintf (dump
, "PROP_gimple_lcf\n");
2627 if (props
& PROP_gimple_leh
)
2628 fprintf (dump
, "PROP_gimple_leh\n");
2629 if (props
& PROP_cfg
)
2630 fprintf (dump
, "PROP_cfg\n");
2631 if (props
& PROP_ssa
)
2632 fprintf (dump
, "PROP_ssa\n");
2633 if (props
& PROP_no_crit_edges
)
2634 fprintf (dump
, "PROP_no_crit_edges\n");
2635 if (props
& PROP_rtl
)
2636 fprintf (dump
, "PROP_rtl\n");
2637 if (props
& PROP_gimple_lomp
)
2638 fprintf (dump
, "PROP_gimple_lomp\n");
2639 if (props
& PROP_gimple_lcx
)
2640 fprintf (dump
, "PROP_gimple_lcx\n");
2641 if (props
& PROP_gimple_lvec
)
2642 fprintf (dump
, "PROP_gimple_lvec\n");
2643 if (props
& PROP_cfglayout
)
2644 fprintf (dump
, "PROP_cfglayout\n");
2648 debug_properties (unsigned int props
)
2650 dump_properties (stderr
, props
);
2653 /* Called by local passes to see if function is called by already processed nodes.
2654 Because we process nodes in topological order, this means that function is
2655 in recursive cycle or we introduced new direct calls. */
2657 function_called_by_processed_nodes_p (void)
2659 struct cgraph_edge
*e
;
2660 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2664 if (e
->caller
->decl
== current_function_decl
)
2666 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2668 if (TREE_ASM_WRITTEN (e
->caller
->decl
))
2670 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2675 fprintf (dump_file
, "Already processed call to:\n");
2676 dump_cgraph_node (dump_file
, e
->caller
);
2681 #include "gt-passes.h"