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. */
79 /* This is used for debugging. It allows the current pass to printed
80 from anywhere in compilation.
81 The variable current_pass is also used for statistics and plugins. */
82 struct opt_pass
*current_pass
;
84 static void register_pass_name (struct opt_pass
*, const char *);
86 /* Most passes are single-instance (within their context) and thus don't
87 need to implement cloning, but passes that support multiple instances
88 *must* provide their own implementation of the clone method.
90 Handle this by providing a default implemenation, but make it a fatal
96 internal_error ("pass %s does not support cloning", name
);
111 opt_pass::opt_pass (const pass_data
&data
, context
*ctxt
)
115 static_pass_number (0),
122 pass_manager::execute_early_local_passes ()
124 execute_pass_list (pass_early_local_passes_1
->sub
);
128 pass_manager::execute_pass_mode_switching ()
130 return pass_mode_switching_1
->execute ();
134 /* Call from anywhere to find out what pass this is. Useful for
135 printing out debugging information deep inside an service
138 print_current_pass (FILE *file
)
141 fprintf (file
, "current pass = %s (%d)\n",
142 current_pass
->name
, current_pass
->static_pass_number
);
144 fprintf (file
, "no current pass.\n");
148 /* Call from the debugger to get the current pass name. */
152 print_current_pass (stderr
);
157 /* Global variables used to communicate with passes. */
159 bool first_pass_instance
;
162 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
165 This does nothing for local (non-static) variables, unless the
166 variable is a register variable with DECL_ASSEMBLER_NAME set. In
167 that case, or if the variable is not an automatic, it sets up the
168 RTL and outputs any assembler code (label definition, storage
169 allocation and initialization).
171 DECL is the declaration. TOP_LEVEL is nonzero
172 if this declaration is not within a function. */
175 rest_of_decl_compilation (tree decl
,
179 /* We deferred calling assemble_alias so that we could collect
180 other attributes such as visibility. Emit the alias now. */
184 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
187 alias
= TREE_VALUE (TREE_VALUE (alias
));
188 alias
= get_identifier (TREE_STRING_POINTER (alias
));
189 /* A quirk of the initial implementation of aliases required that the
190 user add "extern" to all of them. Which is silly, but now
191 historical. Do note that the symbol is in fact locally defined. */
192 DECL_EXTERNAL (decl
) = 0;
193 TREE_STATIC (decl
) = 1;
194 assemble_alias (decl
, alias
);
198 /* Can't defer this, because it needs to happen before any
199 later function definitions are processed. */
200 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
201 make_decl_rtl (decl
);
203 /* Forward declarations for nested functions are not "external",
204 but we need to treat them as if they were. */
205 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
206 || TREE_CODE (decl
) == FUNCTION_DECL
)
208 timevar_push (TV_VARCONST
);
210 /* Don't output anything when a tentative file-scope definition
211 is seen. But at end of compilation, do output code for them.
213 We do output all variables and rely on
214 callgraph code to defer them except for forward declarations
215 (see gcc.c-torture/compile/920624-1.c) */
217 || !DECL_DEFER_OUTPUT (decl
)
218 || DECL_INITIAL (decl
))
219 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
220 && !DECL_EXTERNAL (decl
))
222 /* When reading LTO unit, we also read varpool, so do not
224 if (in_lto_p
&& !at_end
)
226 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
227 varpool_finalize_decl (decl
);
230 #ifdef ASM_FINISH_DECLARE_OBJECT
231 if (decl
== last_assemble_variable_decl
)
233 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
238 timevar_pop (TV_VARCONST
);
240 else if (TREE_CODE (decl
) == TYPE_DECL
241 /* Like in rest_of_type_compilation, avoid confusing the debug
242 information machinery when there are errors. */
245 timevar_push (TV_SYMOUT
);
246 debug_hooks
->type_decl (decl
, !top_level
);
247 timevar_pop (TV_SYMOUT
);
250 /* Let cgraph know about the existence of variables. */
251 if (in_lto_p
&& !at_end
)
253 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
254 && TREE_STATIC (decl
))
255 varpool_node_for_decl (decl
);
258 /* Called after finishing a record, union or enumeral type. */
261 rest_of_type_compilation (tree type
, int toplev
)
263 /* Avoid confusing the debug information machinery when there are
268 timevar_push (TV_SYMOUT
);
269 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
270 timevar_pop (TV_SYMOUT
);
277 finish_optimization_passes (void)
280 struct dump_file_info
*dfi
;
283 timevar_push (TV_DUMP
);
284 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
286 dump_start (pass_profile_1
->static_pass_number
, NULL
);
288 dump_finish (pass_profile_1
->static_pass_number
);
293 dump_start (pass_profile_1
->static_pass_number
, NULL
);
294 print_combine_total_stats ();
295 dump_finish (pass_profile_1
->static_pass_number
);
298 /* Do whatever is necessary to finish printing the graphs. */
299 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
300 if (dump_initialized_p (i
)
301 && (dfi
->pflags
& TDF_GRAPH
) != 0
302 && (name
= get_dump_file_name (i
)) != NULL
)
304 finish_graph_dump_file (name
);
308 timevar_pop (TV_DUMP
);
312 execute_all_early_local_passes (void)
314 /* Once this pass (and its sub-passes) are complete, all functions
315 will be in SSA form. Technically this state change is happening
316 a tad early, since the sub-passes have not yet run, but since
317 none of the sub-passes are IPA passes and do not create new
318 functions, this is ok. We're setting this value for the benefit
319 of IPA passes that follow. */
320 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
321 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
325 /* Gate: execute, or not, all of the non-trivial optimizations. */
328 gate_all_early_local_passes (void)
330 /* Don't bother doing anything if the program has errors. */
331 return (!seen_error () && !in_lto_p
);
336 const pass_data pass_data_early_local_passes
=
338 SIMPLE_IPA_PASS
, /* type */
339 "early_local_cleanups", /* name */
340 OPTGROUP_NONE
, /* optinfo_flags */
342 true, /* has_execute */
343 TV_EARLY_LOCAL
, /* tv_id */
344 0, /* properties_required */
345 0, /* properties_provided */
346 0, /* properties_destroyed */
347 0, /* todo_flags_start */
348 TODO_remove_functions
, /* todo_flags_finish */
351 class pass_early_local_passes
: public simple_ipa_opt_pass
354 pass_early_local_passes (gcc::context
*ctxt
)
355 : simple_ipa_opt_pass (pass_data_early_local_passes
, ctxt
)
358 /* opt_pass methods: */
359 bool gate () { return gate_all_early_local_passes (); }
360 unsigned int execute () { return execute_all_early_local_passes (); }
362 }; // class pass_early_local_passes
366 simple_ipa_opt_pass
*
367 make_pass_early_local_passes (gcc::context
*ctxt
)
369 return new pass_early_local_passes (ctxt
);
372 /* Gate: execute, or not, all of the non-trivial optimizations. */
375 gate_all_early_optimizations (void)
377 return (optimize
>= 1
378 /* Don't bother doing anything if the program has errors. */
384 const pass_data pass_data_all_early_optimizations
=
386 GIMPLE_PASS
, /* type */
387 "early_optimizations", /* name */
388 OPTGROUP_NONE
, /* optinfo_flags */
390 false, /* has_execute */
392 0, /* properties_required */
393 0, /* properties_provided */
394 0, /* properties_destroyed */
395 0, /* todo_flags_start */
396 0, /* todo_flags_finish */
399 class pass_all_early_optimizations
: public gimple_opt_pass
402 pass_all_early_optimizations (gcc::context
*ctxt
)
403 : gimple_opt_pass (pass_data_all_early_optimizations
, ctxt
)
406 /* opt_pass methods: */
407 bool gate () { return gate_all_early_optimizations (); }
409 }; // class pass_all_early_optimizations
413 static gimple_opt_pass
*
414 make_pass_all_early_optimizations (gcc::context
*ctxt
)
416 return new pass_all_early_optimizations (ctxt
);
419 /* Gate: execute, or not, all of the non-trivial optimizations. */
422 gate_all_optimizations (void)
424 return optimize
>= 1 && !optimize_debug
;
429 const pass_data pass_data_all_optimizations
=
431 GIMPLE_PASS
, /* type */
432 "*all_optimizations", /* name */
433 OPTGROUP_NONE
, /* optinfo_flags */
435 false, /* has_execute */
436 TV_OPTIMIZE
, /* tv_id */
437 0, /* properties_required */
438 0, /* properties_provided */
439 0, /* properties_destroyed */
440 0, /* todo_flags_start */
441 0, /* todo_flags_finish */
444 class pass_all_optimizations
: public gimple_opt_pass
447 pass_all_optimizations (gcc::context
*ctxt
)
448 : gimple_opt_pass (pass_data_all_optimizations
, ctxt
)
451 /* opt_pass methods: */
452 bool gate () { return gate_all_optimizations (); }
454 }; // class pass_all_optimizations
458 static gimple_opt_pass
*
459 make_pass_all_optimizations (gcc::context
*ctxt
)
461 return new pass_all_optimizations (ctxt
);
464 /* Gate: execute, or not, all of the non-trivial optimizations. */
467 gate_all_optimizations_g (void)
469 return optimize
>= 1 && optimize_debug
;
474 const pass_data pass_data_all_optimizations_g
=
476 GIMPLE_PASS
, /* type */
477 "*all_optimizations_g", /* name */
478 OPTGROUP_NONE
, /* optinfo_flags */
480 false, /* has_execute */
481 TV_OPTIMIZE
, /* tv_id */
482 0, /* properties_required */
483 0, /* properties_provided */
484 0, /* properties_destroyed */
485 0, /* todo_flags_start */
486 0, /* todo_flags_finish */
489 class pass_all_optimizations_g
: public gimple_opt_pass
492 pass_all_optimizations_g (gcc::context
*ctxt
)
493 : gimple_opt_pass (pass_data_all_optimizations_g
, ctxt
)
496 /* opt_pass methods: */
497 bool gate () { return gate_all_optimizations_g (); }
499 }; // class pass_all_optimizations_g
503 static gimple_opt_pass
*
504 make_pass_all_optimizations_g (gcc::context
*ctxt
)
506 return new pass_all_optimizations_g (ctxt
);
510 gate_rest_of_compilation (void)
512 /* Early return if there were errors. We can run afoul of our
513 consistency checks, and there's not really much point in fixing them. */
514 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
519 const pass_data pass_data_rest_of_compilation
=
522 "*rest_of_compilation", /* name */
523 OPTGROUP_NONE
, /* optinfo_flags */
525 false, /* has_execute */
526 TV_REST_OF_COMPILATION
, /* tv_id */
527 PROP_rtl
, /* properties_required */
528 0, /* properties_provided */
529 0, /* properties_destroyed */
530 0, /* todo_flags_start */
531 0, /* todo_flags_finish */
534 class pass_rest_of_compilation
: public rtl_opt_pass
537 pass_rest_of_compilation (gcc::context
*ctxt
)
538 : rtl_opt_pass (pass_data_rest_of_compilation
, ctxt
)
541 /* opt_pass methods: */
542 bool gate () { return gate_rest_of_compilation (); }
544 }; // class pass_rest_of_compilation
548 static rtl_opt_pass
*
549 make_pass_rest_of_compilation (gcc::context
*ctxt
)
551 return new pass_rest_of_compilation (ctxt
);
555 gate_postreload (void)
557 return reload_completed
;
562 const pass_data pass_data_postreload
=
565 "*all-postreload", /* name */
566 OPTGROUP_NONE
, /* optinfo_flags */
568 false, /* has_execute */
569 TV_POSTRELOAD
, /* tv_id */
570 PROP_rtl
, /* properties_required */
571 0, /* properties_provided */
572 0, /* properties_destroyed */
573 0, /* todo_flags_start */
574 TODO_verify_rtl_sharing
, /* todo_flags_finish */
577 class pass_postreload
: public rtl_opt_pass
580 pass_postreload (gcc::context
*ctxt
)
581 : rtl_opt_pass (pass_data_postreload
, ctxt
)
584 /* opt_pass methods: */
585 bool gate () { return gate_postreload (); }
587 }; // class pass_postreload
591 static rtl_opt_pass
*
592 make_pass_postreload (gcc::context
*ctxt
)
594 return new pass_postreload (ctxt
);
599 /* Set the static pass number of pass PASS to ID and record that
600 in the mapping from static pass number to pass. */
604 set_pass_for_id (int id
, struct opt_pass
*pass
)
606 pass
->static_pass_number
= id
;
607 if (passes_by_id_size
<= id
)
609 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
610 memset (passes_by_id
+ passes_by_id_size
, 0,
611 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
612 passes_by_id_size
= id
+ 1;
614 passes_by_id
[id
] = pass
;
617 /* Return the pass with the static pass number ID. */
620 pass_manager::get_pass_for_id (int id
) const
622 if (id
>= passes_by_id_size
)
624 return passes_by_id
[id
];
627 /* Iterate over the pass tree allocating dump file numbers. We want
628 to do this depth first, and independent of whether the pass is
632 register_one_dump_file (struct opt_pass
*pass
)
634 g
->get_passes ()->register_one_dump_file (pass
);
638 pass_manager::register_one_dump_file (struct opt_pass
*pass
)
640 char *dot_name
, *flag_name
, *glob_name
;
641 const char *name
, *full_name
, *prefix
;
644 int optgroup_flags
= OPTGROUP_NONE
;
646 /* See below in next_pass_1. */
648 if (pass
->static_pass_number
!= -1)
649 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
650 ? 1 : pass
->static_pass_number
));
652 /* The name is both used to identify the pass for the purposes of plugins,
653 and to specify dump file name and option.
654 The latter two might want something short which is not quite unique; for
655 that reason, we may have a disambiguating prefix, followed by a space
656 to mark the start of the following dump file name / option string. */
657 name
= strchr (pass
->name
, ' ');
658 name
= name
? name
+ 1 : pass
->name
;
659 dot_name
= concat (".", name
, num
, NULL
);
660 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
664 optgroup_flags
|= OPTGROUP_IPA
;
666 else if (pass
->type
== GIMPLE_PASS
)
677 flag_name
= concat (prefix
, name
, num
, NULL
);
678 glob_name
= concat (prefix
, name
, NULL
);
679 optgroup_flags
|= pass
->optinfo_flags
;
680 /* For any passes that do not have an optgroup set, and which are not
681 IPA passes setup above, set the optgroup to OPTGROUP_OTHER so that
682 any dump messages are emitted properly under -fopt-info(-optall). */
683 if (optgroup_flags
== OPTGROUP_NONE
)
684 optgroup_flags
= OPTGROUP_OTHER
;
685 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
, optgroup_flags
);
686 set_pass_for_id (id
, pass
);
687 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
688 register_pass_name (pass
, full_name
);
689 free (CONST_CAST (char *, full_name
));
692 /* Recursive worker function for register_dump_files. */
696 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
700 int new_properties
= (properties
| pass
->properties_provided
)
701 & ~pass
->properties_destroyed
;
703 if (pass
->name
&& pass
->name
[0] != '*')
704 register_one_dump_file (pass
);
707 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
709 /* If we have a gate, combine the properties that we could have with
710 and without the pass being examined. */
712 properties
&= new_properties
;
714 properties
= new_properties
;
723 /* Register the dump files for the pass_manager starting at PASS.
724 PROPERTIES reflects the properties that are guaranteed to be available at
725 the beginning of the pipeline. */
729 register_dump_files (struct opt_pass
*pass
,int properties
)
731 pass
->properties_required
|= properties
;
732 register_dump_files_1 (pass
, properties
);
737 const char* unique_name
;
738 struct opt_pass
*pass
;
741 /* Helper for pass_registry hash table. */
743 struct pass_registry_hasher
: typed_noop_remove
<pass_registry
>
745 typedef pass_registry value_type
;
746 typedef pass_registry compare_type
;
747 static inline hashval_t
hash (const value_type
*);
748 static inline bool equal (const value_type
*, const compare_type
*);
751 /* Pass registry hash function. */
754 pass_registry_hasher::hash (const value_type
*s
)
756 return htab_hash_string (s
->unique_name
);
759 /* Hash equal function */
762 pass_registry_hasher::equal (const value_type
*s1
, const compare_type
*s2
)
764 return !strcmp (s1
->unique_name
, s2
->unique_name
);
767 static hash_table
<pass_registry_hasher
> name_to_pass_map
;
769 /* Register PASS with NAME. */
772 register_pass_name (struct opt_pass
*pass
, const char *name
)
774 struct pass_registry
**slot
;
775 struct pass_registry pr
;
777 if (!name_to_pass_map
.is_created ())
778 name_to_pass_map
.create (256);
780 pr
.unique_name
= name
;
781 slot
= name_to_pass_map
.find_slot (&pr
, INSERT
);
784 struct pass_registry
*new_pr
;
786 new_pr
= XCNEW (struct pass_registry
);
787 new_pr
->unique_name
= xstrdup (name
);
792 return; /* Ignore plugin passes. */
795 /* Map from pass id to canonicalized pass name. */
797 typedef const char *char_ptr
;
798 static vec
<char_ptr
> pass_tab
= vNULL
;
800 /* Callback function for traversing NAME_TO_PASS_MAP. */
803 passes_pass_traverse (pass_registry
**p
, void *data ATTRIBUTE_UNUSED
)
805 struct opt_pass
*pass
= (*p
)->pass
;
807 gcc_assert (pass
->static_pass_number
> 0);
808 gcc_assert (pass_tab
.exists ());
810 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
815 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
816 table for dumping purpose. */
819 create_pass_tab (void)
821 if (!flag_dump_passes
)
824 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
825 name_to_pass_map
.traverse
<void *, passes_pass_traverse
> (NULL
);
828 static bool override_gate_status (struct opt_pass
*, tree
, bool);
830 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
831 is turned on or not. */
834 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
836 int indent
= 3 * pass_indent
;
838 bool is_on
, is_really_on
;
840 is_on
= pass
->has_gate
? pass
->gate () : true;
841 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
843 if (pass
->static_pass_number
<= 0)
846 pn
= pass_tab
[pass
->static_pass_number
];
848 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
849 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
850 is_on
? " ON" : " OFF",
851 ((!is_on
) == (!is_really_on
) ? ""
852 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
855 /* Dump pass list PASS with indentation INDENT. */
858 dump_pass_list (struct opt_pass
*pass
, int indent
)
862 dump_one_pass (pass
, indent
);
864 dump_pass_list (pass
->sub
, indent
+ 1);
870 /* Dump all optimization passes. */
875 g
->get_passes ()->dump_passes ();
879 pass_manager::dump_passes () const
881 struct cgraph_node
*n
, *node
= NULL
;
885 FOR_EACH_FUNCTION (n
)
886 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
895 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
897 dump_pass_list (all_lowering_passes
, 1);
898 dump_pass_list (all_small_ipa_passes
, 1);
899 dump_pass_list (all_regular_ipa_passes
, 1);
900 dump_pass_list (all_lto_gen_passes
, 1);
901 dump_pass_list (all_late_ipa_passes
, 1);
902 dump_pass_list (all_passes
, 1);
908 /* Returns the pass with NAME. */
910 static struct opt_pass
*
911 get_pass_by_name (const char *name
)
913 struct pass_registry
**slot
, pr
;
915 pr
.unique_name
= name
;
916 slot
= name_to_pass_map
.find_slot (&pr
, NO_INSERT
);
921 return (*slot
)->pass
;
925 /* Range [start, last]. */
931 const char *assem_name
;
932 struct uid_range
*next
;
935 typedef struct uid_range
*uid_range_p
;
938 static vec
<uid_range_p
>
939 enabled_pass_uid_range_tab
= vNULL
;
940 static vec
<uid_range_p
>
941 disabled_pass_uid_range_tab
= vNULL
;
944 /* Parse option string for -fdisable- and -fenable-
945 The syntax of the options:
948 -fdisable-<pass_name>
950 -fenable-<pass_name>=s1:e1,s2:e2,...
951 -fdisable-<pass_name>=s1:e1,s2:e2,...
955 enable_disable_pass (const char *arg
, bool is_enable
)
957 struct opt_pass
*pass
;
958 char *range_str
, *phase_name
;
959 char *argstr
= xstrdup (arg
);
960 vec
<uid_range_p
> *tab
= 0;
962 range_str
= strchr (argstr
,'=');
973 error ("unrecognized option -fenable");
975 error ("unrecognized option -fdisable");
979 pass
= get_pass_by_name (phase_name
);
980 if (!pass
|| pass
->static_pass_number
== -1)
983 error ("unknown pass %s specified in -fenable", phase_name
);
985 error ("unknown pass %s specified in -fdisable", phase_name
);
991 tab
= &enabled_pass_uid_range_tab
;
993 tab
= &disabled_pass_uid_range_tab
;
995 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
996 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1001 uid_range_p new_range
= XCNEW (struct uid_range
);
1003 new_range
->start
= 0;
1004 new_range
->last
= (unsigned)-1;
1006 slot
= (*tab
)[pass
->static_pass_number
];
1007 new_range
->next
= slot
;
1008 (*tab
)[pass
->static_pass_number
] = new_range
;
1010 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1011 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1013 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1014 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1018 char *next_range
= NULL
;
1019 char *one_range
= range_str
;
1020 char *end_val
= NULL
;
1025 uid_range_p new_range
;
1026 char *invalid
= NULL
;
1028 char *func_name
= NULL
;
1030 next_range
= strchr (one_range
, ',');
1037 end_val
= strchr (one_range
, ':');
1043 start
= strtol (one_range
, &invalid
, 10);
1044 if (*invalid
|| start
< 0)
1046 if (end_val
|| (one_range
[0] >= '0'
1047 && one_range
[0] <= '9'))
1049 error ("Invalid range %s in option %s",
1051 is_enable
? "-fenable" : "-fdisable");
1055 func_name
= one_range
;
1059 new_range
= XCNEW (struct uid_range
);
1062 new_range
->start
= (unsigned) start
;
1063 new_range
->last
= (unsigned) start
;
1067 new_range
->start
= (unsigned) -1;
1068 new_range
->last
= (unsigned) -1;
1069 new_range
->assem_name
= xstrdup (func_name
);
1074 long last
= strtol (end_val
, &invalid
, 10);
1075 if (*invalid
|| last
< start
)
1077 error ("Invalid range %s in option %s",
1079 is_enable
? "-fenable" : "-fdisable");
1083 new_range
= XCNEW (struct uid_range
);
1084 new_range
->start
= (unsigned) start
;
1085 new_range
->last
= (unsigned) last
;
1088 slot
= (*tab
)[pass
->static_pass_number
];
1089 new_range
->next
= slot
;
1090 (*tab
)[pass
->static_pass_number
] = new_range
;
1093 if (new_range
->assem_name
)
1094 inform (UNKNOWN_LOCATION
,
1095 "enable pass %s for function %s",
1096 phase_name
, new_range
->assem_name
);
1098 inform (UNKNOWN_LOCATION
,
1099 "enable pass %s for functions in the range of [%u, %u]",
1100 phase_name
, new_range
->start
, new_range
->last
);
1104 if (new_range
->assem_name
)
1105 inform (UNKNOWN_LOCATION
,
1106 "disable pass %s for function %s",
1107 phase_name
, new_range
->assem_name
);
1109 inform (UNKNOWN_LOCATION
,
1110 "disable pass %s for functions in the range of [%u, %u]",
1111 phase_name
, new_range
->start
, new_range
->last
);
1114 one_range
= next_range
;
1115 } while (next_range
);
1121 /* Enable pass specified by ARG. */
1124 enable_pass (const char *arg
)
1126 enable_disable_pass (arg
, true);
1129 /* Disable pass specified by ARG. */
1132 disable_pass (const char *arg
)
1134 enable_disable_pass (arg
, false);
1137 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1140 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
1142 vec
<uid_range_p
> tab
)
1144 uid_range_p slot
, range
;
1146 const char *aname
= NULL
;
1149 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1150 || pass
->static_pass_number
== -1)
1153 slot
= tab
[pass
->static_pass_number
];
1157 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
1158 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1159 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1164 if ((unsigned) cgraph_uid
>= range
->start
1165 && (unsigned) cgraph_uid
<= range
->last
)
1167 if (range
->assem_name
&& aname
1168 && !strcmp (range
->assem_name
, aname
))
1170 range
= range
->next
;
1177 /* Update static_pass_number for passes (and the flag
1178 TODO_mark_first_instance).
1180 Passes are constructed with static_pass_number preinitialized to 0
1182 This field is used in two different ways: initially as instance numbers
1183 of their kind, and then as ids within the entire pass manager.
1185 Within pass_manager::pass_manager:
1187 * In add_pass_instance(), as called by next_pass_1 in
1188 NEXT_PASS in init_optimization_passes
1190 * When the initial instance of a pass within a pass manager is seen,
1191 it is flagged, and its static_pass_number is set to -1
1193 * On subsequent times that it is seen, the static pass number
1194 is decremented each time, so that if there are e.g. 4 dups,
1195 they have static_pass_number -4, 2, 3, 4 respectively (note
1196 how the initial one is negative and gives the count); these
1197 can be thought of as instance numbers of the specific pass
1199 * Within the register_dump_files () traversal, set_pass_for_id()
1200 is called on each pass, using these instance numbers to create
1201 dumpfile switches, and then overwriting them with a pass id,
1202 which are global to the whole pass manager (based on
1203 (TDI_end + current value of extra_dump_files_in_use) ) */
1206 add_pass_instance (struct opt_pass
*new_pass
, bool track_duplicates
,
1207 opt_pass
*initial_pass
)
1209 /* Are we dealing with the first pass of its kind, or a clone? */
1210 if (new_pass
!= initial_pass
)
1212 /* We're dealing with a clone. */
1213 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1215 /* Indicate to register_dump_files that this pass has duplicates,
1216 and so it should rename the dump file. The first instance will
1217 be -1, and be number of duplicates = -static_pass_number - 1.
1218 Subsequent instances will be > 0 and just the duplicate number. */
1219 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1221 initial_pass
->static_pass_number
-= 1;
1222 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1227 /* We're dealing with the first pass of its kind. */
1228 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1229 new_pass
->static_pass_number
= -1;
1231 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1235 /* Add a pass to the pass list. Duplicate the pass if it's already
1238 static struct opt_pass
**
1239 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
,
1240 struct opt_pass
*initial_pass
)
1242 /* Every pass should have a name so that plugins can refer to them. */
1243 gcc_assert (pass
->name
!= NULL
);
1245 add_pass_instance (pass
, false, initial_pass
);
1248 return &(*list
)->next
;
1251 /* List node for an inserted pass instance. We need to keep track of all
1252 the newly-added pass instances (with 'added_pass_nodes' defined below)
1253 so that we can register their dump files after pass-positioning is finished.
1254 Registering dumping files needs to be post-processed or the
1255 static_pass_number of the opt_pass object would be modified and mess up
1256 the dump file names of future pass instances to be added. */
1258 struct pass_list_node
1260 struct opt_pass
*pass
;
1261 struct pass_list_node
*next
;
1264 static struct pass_list_node
*added_pass_nodes
= NULL
;
1265 static struct pass_list_node
*prev_added_pass_node
;
1267 /* Insert the pass at the proper position. Return true if the pass
1268 is successfully added.
1270 NEW_PASS_INFO - new pass to be inserted
1271 PASS_LIST - root of the pass list to insert the new pass to */
1274 position_pass (struct register_pass_info
*new_pass_info
,
1275 struct opt_pass
**pass_list
)
1277 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1278 bool success
= false;
1280 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1282 /* Check if the current pass is of the same type as the new pass and
1283 matches the name and the instance number of the reference pass. */
1284 if (pass
->type
== new_pass_info
->pass
->type
1286 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1287 && ((new_pass_info
->ref_pass_instance_number
== 0)
1288 || (new_pass_info
->ref_pass_instance_number
==
1289 pass
->static_pass_number
)
1290 || (new_pass_info
->ref_pass_instance_number
== 1
1291 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1293 struct opt_pass
*new_pass
;
1294 struct pass_list_node
*new_pass_node
;
1296 if (new_pass_info
->ref_pass_instance_number
== 0)
1298 new_pass
= new_pass_info
->pass
->clone ();
1299 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1303 new_pass
= new_pass_info
->pass
;
1304 add_pass_instance (new_pass
, true, new_pass
);
1307 /* Insert the new pass instance based on the positioning op. */
1308 switch (new_pass_info
->pos_op
)
1310 case PASS_POS_INSERT_AFTER
:
1311 new_pass
->next
= pass
->next
;
1312 pass
->next
= new_pass
;
1314 /* Skip newly inserted pass to avoid repeated
1315 insertions in the case where the new pass and the
1316 existing one have the same name. */
1319 case PASS_POS_INSERT_BEFORE
:
1320 new_pass
->next
= pass
;
1322 prev_pass
->next
= new_pass
;
1324 *pass_list
= new_pass
;
1326 case PASS_POS_REPLACE
:
1327 new_pass
->next
= pass
->next
;
1329 prev_pass
->next
= new_pass
;
1331 *pass_list
= new_pass
;
1332 new_pass
->sub
= pass
->sub
;
1333 new_pass
->tv_id
= pass
->tv_id
;
1337 error ("invalid pass positioning operation");
1341 /* Save the newly added pass (instance) in the added_pass_nodes
1342 list so that we can register its dump file later. Note that
1343 we cannot register the dump file now because doing so will modify
1344 the static_pass_number of the opt_pass object and therefore
1345 mess up the dump file name of future instances. */
1346 new_pass_node
= XCNEW (struct pass_list_node
);
1347 new_pass_node
->pass
= new_pass
;
1348 if (!added_pass_nodes
)
1349 added_pass_nodes
= new_pass_node
;
1351 prev_added_pass_node
->next
= new_pass_node
;
1352 prev_added_pass_node
= new_pass_node
;
1357 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1364 /* Hooks a new pass into the pass lists.
1366 PASS_INFO - pass information that specifies the opt_pass object,
1367 reference pass, instance number, and how to position
1371 register_pass (struct register_pass_info
*pass_info
)
1373 g
->get_passes ()->register_pass (pass_info
);
1377 register_pass (opt_pass
* pass
, pass_positioning_ops pos
,
1378 const char* ref_pass_name
, int ref_pass_inst_number
)
1380 register_pass_info i
;
1382 i
.reference_pass_name
= ref_pass_name
;
1383 i
.ref_pass_instance_number
= ref_pass_inst_number
;
1386 g
->get_passes ()->register_pass (&i
);
1390 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1392 bool all_instances
, success
;
1394 /* The checks below could fail in buggy plugins. Existing GCC
1395 passes should never fail these checks, so we mention plugin in
1397 if (!pass_info
->pass
)
1398 fatal_error ("plugin cannot register a missing pass");
1400 if (!pass_info
->pass
->name
)
1401 fatal_error ("plugin cannot register an unnamed pass");
1403 if (!pass_info
->reference_pass_name
)
1405 ("plugin cannot register pass %qs without reference pass name",
1406 pass_info
->pass
->name
);
1408 /* Try to insert the new pass to the pass lists. We need to check
1409 all five lists as the reference pass could be in one (or all) of
1411 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1412 success
= position_pass (pass_info
, &all_lowering_passes
);
1413 if (!success
|| all_instances
)
1414 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1415 if (!success
|| all_instances
)
1416 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1417 if (!success
|| all_instances
)
1418 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1419 if (!success
|| all_instances
)
1420 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1421 if (!success
|| all_instances
)
1422 success
|= position_pass (pass_info
, &all_passes
);
1425 ("pass %qs not found but is referenced by new pass %qs",
1426 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1428 /* OK, we have successfully inserted the new pass. We need to register
1429 the dump files for the newly added pass and its duplicates (if any).
1430 Because the registration of plugin/backend passes happens after the
1431 command-line options are parsed, the options that specify single
1432 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1433 passes. Therefore we currently can only enable dumping of
1434 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1435 are specified. While doing so, we also delete the pass_list_node
1436 objects created during pass positioning. */
1437 while (added_pass_nodes
)
1439 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1440 enum tree_dump_index tdi
;
1441 register_one_dump_file (added_pass_nodes
->pass
);
1442 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1443 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1445 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1449 /* Check if dump-all flag is specified. */
1450 if (get_dump_file_info (tdi
)->pstate
)
1451 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1452 ->pstate
= get_dump_file_info (tdi
)->pstate
;
1453 XDELETE (added_pass_nodes
);
1454 added_pass_nodes
= next_node
;
1458 /* Construct the pass tree. The sequencing of passes is driven by
1459 the cgraph routines:
1461 finalize_compilation_unit ()
1462 for each node N in the cgraph
1463 cgraph_analyze_function (N)
1464 cgraph_lower_function (N) -> all_lowering_passes
1466 If we are optimizing, compile is then invoked:
1469 ipa_passes () -> all_small_ipa_passes
1470 -> Analysis of all_regular_ipa_passes
1471 * possible LTO streaming at copmilation time *
1472 -> Execution of all_regular_ipa_passes
1473 * possible LTO streaming at link time *
1474 -> all_late_ipa_passes
1475 expand_all_functions ()
1476 for each node N in the cgraph
1477 expand_function (N) -> Transformation of all_regular_ipa_passes
1482 pass_manager::operator new (size_t sz
)
1484 /* Ensure that all fields of the pass manager are zero-initialized. */
1485 return xcalloc (1, sz
);
1488 pass_manager::pass_manager (context
*ctxt
)
1489 : all_passes (NULL
), all_small_ipa_passes (NULL
), all_lowering_passes (NULL
),
1490 all_regular_ipa_passes (NULL
), all_lto_gen_passes (NULL
),
1491 all_late_ipa_passes (NULL
), passes_by_id (NULL
), passes_by_id_size (0),
1494 struct opt_pass
**p
;
1496 /* Initialize the pass_lists array. */
1497 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1499 #undef DEF_PASS_LIST
1501 /* Build the tree of passes. */
1503 #define INSERT_PASSES_AFTER(PASS) \
1506 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1508 struct opt_pass **p = &(PASS ## _1)->sub;
1510 #define POP_INSERT_PASSES() \
1513 #define NEXT_PASS(PASS, NUM) \
1515 gcc_assert (NULL == PASS ## _ ## NUM); \
1517 PASS ## _1 = make_##PASS (m_ctxt); \
1520 gcc_assert (PASS ## _1); \
1521 PASS ## _ ## NUM = PASS ## _1->clone (); \
1523 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1526 #define TERMINATE_PASS_LIST() \
1529 #include "pass-instances.def"
1531 #undef INSERT_PASSES_AFTER
1532 #undef PUSH_INSERT_PASSES_WITHIN
1533 #undef POP_INSERT_PASSES
1535 #undef TERMINATE_PASS_LIST
1537 /* Register the passes with the tree dump code. */
1538 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1539 register_dump_files (all_small_ipa_passes
,
1540 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1542 register_dump_files (all_regular_ipa_passes
,
1543 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1545 register_dump_files (all_lto_gen_passes
,
1546 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1548 register_dump_files (all_late_ipa_passes
,
1549 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1551 register_dump_files (all_passes
,
1552 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1556 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1557 function CALLBACK for every function in the call graph. Otherwise,
1558 call CALLBACK on the current function. */
1561 do_per_function (void (*callback
) (void *data
), void *data
)
1563 if (current_function_decl
)
1567 struct cgraph_node
*node
;
1568 FOR_EACH_DEFINED_FUNCTION (node
)
1569 if (node
->symbol
.analyzed
&& gimple_has_body_p (node
->symbol
.decl
)
1570 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1572 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1576 free_dominance_info (CDI_DOMINATORS
);
1577 free_dominance_info (CDI_POST_DOMINATORS
);
1585 /* Because inlining might remove no-longer reachable nodes, we need to
1586 keep the array visible to garbage collector to avoid reading collected
1589 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1591 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1592 function CALLBACK for every function in the call graph. Otherwise,
1593 call CALLBACK on the current function.
1594 This function is global so that plugins can use it. */
1596 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1600 if (current_function_decl
)
1604 gcc_assert (!order
);
1605 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1606 nnodes
= ipa_reverse_postorder (order
);
1607 for (i
= nnodes
- 1; i
>= 0; i
--)
1608 order
[i
]->process
= 1;
1609 for (i
= nnodes
- 1; i
>= 0; i
--)
1611 struct cgraph_node
*node
= order
[i
];
1613 /* Allow possibly removed nodes to be garbage collected. */
1616 if (cgraph_function_with_gimple_body_p (node
))
1618 cgraph_get_body (node
);
1619 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1621 free_dominance_info (CDI_DOMINATORS
);
1622 free_dominance_info (CDI_POST_DOMINATORS
);
1633 /* Helper function to perform function body dump. */
1636 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1638 if (dump_file
&& current_function_decl
)
1640 if (cfun
->curr_properties
& PROP_trees
)
1641 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1643 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1645 /* Flush the file. If verification fails, we won't be able to
1646 close the file before aborting. */
1649 if ((cfun
->curr_properties
& PROP_cfg
)
1650 && (dump_flags
& TDF_GRAPH
))
1651 print_graph_cfg (dump_file_name
, cfun
);
1655 static struct profile_record
*profile_record
;
1657 /* Do profile consistency book-keeping for the pass with static number INDEX.
1658 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1659 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1660 if we are only book-keeping on passes that may have selectively disabled
1661 themselves on a given function. */
1663 check_profile_consistency (int index
, int subpass
, bool run
)
1665 pass_manager
*passes
= g
->get_passes ();
1668 if (!profile_record
)
1669 profile_record
= XCNEWVEC (struct profile_record
,
1670 passes
->passes_by_id_size
);
1671 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1672 gcc_assert (subpass
< 2);
1673 profile_record
[index
].run
|= run
;
1674 account_profile_record (&profile_record
[index
], subpass
);
1677 /* Output profile consistency. */
1680 dump_profile_report (void)
1682 g
->get_passes ()->dump_profile_report ();
1686 pass_manager::dump_profile_report () const
1689 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1690 gcov_type last_time
= 0, last_size
= 0;
1691 double rel_time_change
, rel_size_change
;
1692 int last_reported
= 0;
1694 if (!profile_record
)
1696 fprintf (stderr
, "\nProfile consistency report:\n\n");
1697 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1698 fprintf (stderr
, " |freq count |freq count |size time\n");
1700 for (i
= 0; i
< passes_by_id_size
; i
++)
1701 for (j
= 0 ; j
< 2; j
++)
1702 if (profile_record
[i
].run
)
1705 rel_time_change
= (profile_record
[i
].time
[j
]
1706 - (double)last_time
) * 100 / (double)last_time
;
1708 rel_time_change
= 0;
1710 rel_size_change
= (profile_record
[i
].size
[j
]
1711 - (double)last_size
) * 100 / (double)last_size
;
1713 rel_size_change
= 0;
1715 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1716 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1717 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1718 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1719 || rel_time_change
|| rel_size_change
)
1722 fprintf (stderr
, "%-20s %s",
1723 passes_by_id
[i
]->name
,
1724 j
? "(after TODO)" : " ");
1725 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1726 fprintf (stderr
, "| %+5i",
1727 profile_record
[i
].num_mismatched_freq_in
[j
]
1730 fprintf (stderr
, "| ");
1731 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1732 fprintf (stderr
, " %+5i",
1733 profile_record
[i
].num_mismatched_count_in
[j
]
1736 fprintf (stderr
, " ");
1737 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1738 fprintf (stderr
, "| %+5i",
1739 profile_record
[i
].num_mismatched_freq_out
[j
]
1742 fprintf (stderr
, "| ");
1743 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1744 fprintf (stderr
, " %+5i",
1745 profile_record
[i
].num_mismatched_count_out
[j
]
1748 fprintf (stderr
, " ");
1750 /* Size/time units change across gimple and RTL. */
1751 if (i
== pass_expand_1
->static_pass_number
)
1752 fprintf (stderr
, "|----------");
1755 if (rel_size_change
)
1756 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1758 fprintf (stderr
, "| ");
1759 if (rel_time_change
)
1760 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1762 fprintf (stderr
, "\n");
1763 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1764 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1765 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1766 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1768 else if (j
&& last_reported
!= i
)
1771 fprintf (stderr
, "%-20s ------------| | |\n",
1772 passes_by_id
[i
]->name
);
1774 last_time
= profile_record
[i
].time
[j
];
1775 last_size
= profile_record
[i
].size
[j
];
1779 /* Perform all TODO actions that ought to be done on each function. */
1782 execute_function_todo (void *data
)
1784 unsigned int flags
= (size_t)data
;
1785 flags
&= ~cfun
->last_verified
;
1789 /* Always cleanup the CFG before trying to update SSA. */
1790 if (flags
& TODO_cleanup_cfg
)
1792 cleanup_tree_cfg ();
1794 /* When cleanup_tree_cfg merges consecutive blocks, it may
1795 perform some simplistic propagation when removing single
1796 valued PHI nodes. This propagation may, in turn, cause the
1797 SSA form to become out-of-date (see PR 22037). So, even
1798 if the parent pass had not scheduled an SSA update, we may
1799 still need to do one. */
1800 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1801 flags
|= TODO_update_ssa
;
1804 if (flags
& TODO_update_ssa_any
)
1806 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1807 update_ssa (update_flags
);
1808 cfun
->last_verified
&= ~TODO_verify_ssa
;
1811 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1812 compute_may_aliases ();
1814 if (optimize
&& (flags
& TODO_update_address_taken
))
1815 execute_update_addresses_taken ();
1817 if (flags
& TODO_remove_unused_locals
)
1818 remove_unused_locals ();
1820 if (flags
& TODO_rebuild_frequencies
)
1821 rebuild_frequencies ();
1823 if (flags
& TODO_rebuild_cgraph_edges
)
1824 rebuild_cgraph_edges ();
1826 /* If we've seen errors do not bother running any verifiers. */
1830 #if defined ENABLE_CHECKING
1831 if (flags
& TODO_verify_ssa
1832 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1834 verify_gimple_in_cfg (cfun
);
1837 else if (flags
& TODO_verify_stmts
)
1838 verify_gimple_in_cfg (cfun
);
1839 if (flags
& TODO_verify_flow
)
1840 verify_flow_info ();
1841 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1842 verify_loop_closed_ssa (false);
1843 if (flags
& TODO_verify_rtl_sharing
)
1844 verify_rtl_sharing ();
1847 cfun
->last_verified
= flags
& TODO_verify_all
;
1850 /* Perform all TODO actions. */
1852 execute_todo (unsigned int flags
)
1854 #if defined ENABLE_CHECKING
1856 && need_ssa_update_p (cfun
))
1857 gcc_assert (flags
& TODO_update_ssa_any
);
1860 timevar_push (TV_TODO
);
1862 /* Inform the pass whether it is the first time it is run. */
1863 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1865 statistics_fini_pass ();
1867 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1869 /* Always remove functions just as before inlining: IPA passes might be
1870 interested to see bodies of extern inline functions that are not inlined
1871 to analyze side effects. The full removal is done just at the end
1872 of IPA pass queue. */
1873 if (flags
& TODO_remove_functions
)
1876 symtab_remove_unreachable_nodes (true, dump_file
);
1879 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1882 dump_symtab (dump_file
);
1883 /* Flush the file. If verification fails, we won't be able to
1884 close the file before aborting. */
1888 /* Now that the dumping has been done, we can get rid of the optional
1890 if (flags
& TODO_df_finish
)
1891 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1893 timevar_pop (TV_TODO
);
1896 /* Verify invariants that should hold between passes. This is a place
1897 to put simple sanity checks. */
1900 verify_interpass_invariants (void)
1902 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1905 /* Clear the last verified flag. */
1908 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
1910 cfun
->last_verified
= 0;
1913 /* Helper function. Verify that the properties has been turn into the
1914 properties expected by the pass. */
1916 #ifdef ENABLE_CHECKING
1918 verify_curr_properties (void *data
)
1920 unsigned int props
= (size_t)data
;
1921 gcc_assert ((cfun
->curr_properties
& props
) == props
);
1925 /* Initialize pass dump file. */
1926 /* This is non-static so that the plugins can use it. */
1929 pass_init_dump_file (struct opt_pass
*pass
)
1931 /* If a dump file name is present, open it if enabled. */
1932 if (pass
->static_pass_number
!= -1)
1934 timevar_push (TV_DUMP
);
1935 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
1936 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
1937 dump_start (pass
->static_pass_number
, &dump_flags
);
1938 if (dump_file
&& current_function_decl
)
1939 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1940 if (initializing_dump
1941 && dump_file
&& (dump_flags
& TDF_GRAPH
)
1942 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
1943 clean_graph_dump_file (dump_file_name
);
1944 timevar_pop (TV_DUMP
);
1945 return initializing_dump
;
1951 /* Flush PASS dump file. */
1952 /* This is non-static so that plugins can use it. */
1955 pass_fini_dump_file (struct opt_pass
*pass
)
1957 timevar_push (TV_DUMP
);
1959 /* Flush and close dump file. */
1962 free (CONST_CAST (char *, dump_file_name
));
1963 dump_file_name
= NULL
;
1966 dump_finish (pass
->static_pass_number
);
1967 timevar_pop (TV_DUMP
);
1970 /* After executing the pass, apply expected changes to the function
1974 update_properties_after_pass (void *data
)
1976 struct opt_pass
*pass
= (struct opt_pass
*) data
;
1977 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
1978 & ~pass
->properties_destroyed
;
1981 /* Execute summary generation for all of the passes in IPA_PASS. */
1984 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
1988 struct opt_pass
*pass
= ipa_pass
;
1990 /* Execute all of the IPA_PASSes in the list. */
1991 if (ipa_pass
->type
== IPA_PASS
1992 && ((!pass
->has_gate
) || pass
->gate ())
1993 && ipa_pass
->generate_summary
)
1995 pass_init_dump_file (pass
);
1997 /* If a timevar is present, start it. */
1999 timevar_push (pass
->tv_id
);
2001 ipa_pass
->generate_summary ();
2005 timevar_pop (pass
->tv_id
);
2007 pass_fini_dump_file (pass
);
2009 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->next
;
2013 /* Execute IPA_PASS function transform on NODE. */
2016 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2017 struct ipa_opt_pass_d
*ipa_pass
)
2019 struct opt_pass
*pass
= ipa_pass
;
2020 unsigned int todo_after
= 0;
2022 current_pass
= pass
;
2023 if (!ipa_pass
->function_transform
)
2026 /* Note that the folders should only create gimple expressions.
2027 This is a hack until the new folder is ready. */
2028 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2030 pass_init_dump_file (pass
);
2032 /* Run pre-pass verification. */
2033 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2035 /* If a timevar is present, start it. */
2036 if (pass
->tv_id
!= TV_NONE
)
2037 timevar_push (pass
->tv_id
);
2040 todo_after
= ipa_pass
->function_transform (node
);
2043 if (pass
->tv_id
!= TV_NONE
)
2044 timevar_pop (pass
->tv_id
);
2046 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2047 check_profile_consistency (pass
->static_pass_number
, 0, true);
2049 /* Run post-pass cleanup and verification. */
2050 execute_todo (todo_after
);
2051 verify_interpass_invariants ();
2052 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2053 check_profile_consistency (pass
->static_pass_number
, 1, true);
2055 do_per_function (execute_function_dump
, NULL
);
2056 pass_fini_dump_file (pass
);
2058 current_pass
= NULL
;
2060 /* Signal this is a suitable GC collection point. */
2061 if (!(todo_after
& TODO_do_not_ggc_collect
))
2065 /* For the current function, execute all ipa transforms. */
2068 execute_all_ipa_transforms (void)
2070 struct cgraph_node
*node
;
2073 node
= cgraph_get_node (current_function_decl
);
2075 if (node
->ipa_transforms_to_apply
.exists ())
2079 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2080 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2081 node
->ipa_transforms_to_apply
.release ();
2085 /* Callback for do_per_function to apply all IPA transforms. */
2088 apply_ipa_transforms (void *data
)
2090 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2091 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2093 *(bool *)data
= true;
2094 execute_all_ipa_transforms ();
2095 rebuild_cgraph_edges ();
2099 /* Check if PASS is explicitly disabled or enabled and return
2100 the gate status. FUNC is the function to be processed, and
2101 GATE_STATUS is the gate status determined by pass manager by
2105 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2107 bool explicitly_enabled
= false;
2108 bool explicitly_disabled
= false;
2111 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2112 enabled_pass_uid_range_tab
);
2114 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2115 disabled_pass_uid_range_tab
);
2117 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2126 execute_one_pass (struct opt_pass
*pass
)
2128 unsigned int todo_after
= 0;
2132 /* IPA passes are executed on whole program, so cfun should be NULL.
2133 Other passes need function context set. */
2134 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2135 gcc_assert (!cfun
&& !current_function_decl
);
2137 gcc_assert (cfun
&& current_function_decl
);
2139 current_pass
= pass
;
2141 /* Check whether gate check should be avoided.
2142 User controls the value of the gate through the parameter "gate_status". */
2143 gate_status
= pass
->has_gate
? pass
->gate () : true;
2144 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2146 /* Override gate with plugin. */
2147 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2151 /* Run so passes selectively disabling themselves on a given function
2152 are not miscounted. */
2153 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2155 check_profile_consistency (pass
->static_pass_number
, 0, false);
2156 check_profile_consistency (pass
->static_pass_number
, 1, false);
2158 current_pass
= NULL
;
2162 /* Pass execution event trigger: useful to identify passes being
2164 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2166 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2167 Apply all trnasforms first. */
2168 if (pass
->type
== SIMPLE_IPA_PASS
)
2170 bool applied
= false;
2171 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2173 symtab_remove_unreachable_nodes (true, dump_file
);
2174 /* Restore current_pass. */
2175 current_pass
= pass
;
2178 if (!quiet_flag
&& !cfun
)
2179 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2181 /* Note that the folders should only create gimple expressions.
2182 This is a hack until the new folder is ready. */
2183 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2185 pass_init_dump_file (pass
);
2187 /* Run pre-pass verification. */
2188 execute_todo (pass
->todo_flags_start
);
2190 #ifdef ENABLE_CHECKING
2191 do_per_function (verify_curr_properties
,
2192 (void *)(size_t)pass
->properties_required
);
2195 /* If a timevar is present, start it. */
2196 if (pass
->tv_id
!= TV_NONE
)
2197 timevar_push (pass
->tv_id
);
2200 if (pass
->has_execute
)
2202 todo_after
= pass
->execute ();
2203 do_per_function (clear_last_verified
, NULL
);
2207 if (pass
->tv_id
!= TV_NONE
)
2208 timevar_pop (pass
->tv_id
);
2210 do_per_function (update_properties_after_pass
, pass
);
2212 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2213 check_profile_consistency (pass
->static_pass_number
, 0, true);
2215 /* Run post-pass cleanup and verification. */
2216 execute_todo (todo_after
| pass
->todo_flags_finish
);
2217 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2218 check_profile_consistency (pass
->static_pass_number
, 1, true);
2220 verify_interpass_invariants ();
2221 do_per_function (execute_function_dump
, NULL
);
2222 if (pass
->type
== IPA_PASS
)
2224 struct cgraph_node
*node
;
2225 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2226 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2229 if (!current_function_decl
)
2230 cgraph_process_new_functions ();
2232 pass_fini_dump_file (pass
);
2234 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2235 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2236 || pass
->type
!= RTL_PASS
);
2238 current_pass
= NULL
;
2240 /* Signal this is a suitable GC collection point. */
2241 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2248 execute_pass_list (struct opt_pass
*pass
)
2252 gcc_assert (pass
->type
== GIMPLE_PASS
2253 || pass
->type
== RTL_PASS
);
2254 if (execute_one_pass (pass
) && pass
->sub
)
2255 execute_pass_list (pass
->sub
);
2261 /* Same as execute_pass_list but assume that subpasses of IPA passes
2262 are local passes. If SET is not NULL, write out summaries of only
2263 those node in SET. */
2266 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2270 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2271 gcc_assert (!current_function_decl
);
2273 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2274 if (pass
->type
== IPA_PASS
2275 && ipa_pass
->write_summary
2276 && ((!pass
->has_gate
) || pass
->gate ()))
2278 /* If a timevar is present, start it. */
2280 timevar_push (pass
->tv_id
);
2282 pass_init_dump_file (pass
);
2284 ipa_pass
->write_summary ();
2286 pass_fini_dump_file (pass
);
2288 /* If a timevar is present, start it. */
2290 timevar_pop (pass
->tv_id
);
2293 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2294 ipa_write_summaries_2 (pass
->sub
, state
);
2300 /* Helper function of ipa_write_summaries. Creates and destroys the
2301 decl state and calls ipa_write_summaries_2 for all passes that have
2302 summaries. SET is the set of nodes to be written. */
2305 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2307 pass_manager
*passes
= g
->get_passes ();
2308 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2309 state
->symtab_node_encoder
= encoder
;
2311 lto_push_out_decl_state (state
);
2313 gcc_assert (!flag_wpa
);
2314 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2315 ipa_write_summaries_2 (passes
->all_lto_gen_passes
, state
);
2317 gcc_assert (lto_get_out_decl_state () == state
);
2318 lto_pop_out_decl_state ();
2319 lto_delete_out_decl_state (state
);
2322 /* Write out summaries for all the nodes in the callgraph. */
2325 ipa_write_summaries (void)
2327 lto_symtab_encoder_t encoder
;
2329 struct varpool_node
*vnode
;
2330 struct cgraph_node
*node
;
2331 struct cgraph_node
**order
;
2333 if (!flag_generate_lto
|| seen_error ())
2336 encoder
= lto_symtab_encoder_new (false);
2338 /* Create the callgraph set in the same order used in
2339 cgraph_expand_all_functions. This mostly facilitates debugging,
2340 since it causes the gimple file to be processed in the same order
2341 as the source code. */
2342 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2343 order_pos
= ipa_reverse_postorder (order
);
2344 gcc_assert (order_pos
== cgraph_n_nodes
);
2346 for (i
= order_pos
- 1; i
>= 0; i
--)
2348 struct cgraph_node
*node
= order
[i
];
2350 if (cgraph_function_with_gimple_body_p (node
))
2352 /* When streaming out references to statements as part of some IPA
2353 pass summary, the statements need to have uids assigned and the
2354 following does that for all the IPA passes here. Naturally, this
2355 ordering then matches the one IPA-passes get in their stmt_fixup
2358 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2359 renumber_gimple_stmt_uids ();
2362 if (node
->symbol
.definition
)
2363 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2366 FOR_EACH_DEFINED_FUNCTION (node
)
2367 if (node
->symbol
.alias
)
2368 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2369 FOR_EACH_DEFINED_VARIABLE (vnode
)
2370 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2372 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2377 /* Same as execute_pass_list but assume that subpasses of IPA passes
2378 are local passes. If SET is not NULL, write out optimization summaries of
2379 only those node in SET. */
2382 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2386 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2387 gcc_assert (!current_function_decl
);
2389 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2390 if (pass
->type
== IPA_PASS
2391 && ipa_pass
->write_optimization_summary
2392 && ((!pass
->has_gate
) || pass
->gate ()))
2394 /* If a timevar is present, start it. */
2396 timevar_push (pass
->tv_id
);
2398 pass_init_dump_file (pass
);
2400 ipa_pass
->write_optimization_summary ();
2402 pass_fini_dump_file (pass
);
2404 /* If a timevar is present, start it. */
2406 timevar_pop (pass
->tv_id
);
2409 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2410 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2416 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2417 NULL, write out all summaries of all nodes. */
2420 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2422 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2423 lto_symtab_encoder_iterator lsei
;
2424 state
->symtab_node_encoder
= encoder
;
2426 lto_push_out_decl_state (state
);
2427 for (lsei
= lsei_start_function_in_partition (encoder
);
2428 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2430 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2431 /* When streaming out references to statements as part of some IPA
2432 pass summary, the statements need to have uids assigned.
2434 For functions newly born at WPA stage we need to initialize
2436 if (node
->symbol
.definition
2437 && gimple_has_body_p (node
->symbol
.decl
))
2439 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2440 renumber_gimple_stmt_uids ();
2445 gcc_assert (flag_wpa
);
2446 pass_manager
*passes
= g
->get_passes ();
2447 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2448 ipa_write_optimization_summaries_1 (passes
->all_lto_gen_passes
, state
);
2450 gcc_assert (lto_get_out_decl_state () == state
);
2451 lto_pop_out_decl_state ();
2452 lto_delete_out_decl_state (state
);
2455 /* Same as execute_pass_list but assume that subpasses of IPA passes
2456 are local passes. */
2459 ipa_read_summaries_1 (struct opt_pass
*pass
)
2463 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2465 gcc_assert (!current_function_decl
);
2467 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2469 if ((!pass
->has_gate
) || pass
->gate ())
2471 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2473 /* If a timevar is present, start it. */
2475 timevar_push (pass
->tv_id
);
2477 pass_init_dump_file (pass
);
2479 ipa_pass
->read_summary ();
2481 pass_fini_dump_file (pass
);
2485 timevar_pop (pass
->tv_id
);
2488 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2489 ipa_read_summaries_1 (pass
->sub
);
2496 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2499 ipa_read_summaries (void)
2501 pass_manager
*passes
= g
->get_passes ();
2502 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2503 ipa_read_summaries_1 (passes
->all_lto_gen_passes
);
2506 /* Same as execute_pass_list but assume that subpasses of IPA passes
2507 are local passes. */
2510 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2514 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2516 gcc_assert (!current_function_decl
);
2518 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2520 if ((!pass
->has_gate
) || pass
->gate ())
2522 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2524 /* If a timevar is present, start it. */
2526 timevar_push (pass
->tv_id
);
2528 pass_init_dump_file (pass
);
2530 ipa_pass
->read_optimization_summary ();
2532 pass_fini_dump_file (pass
);
2536 timevar_pop (pass
->tv_id
);
2539 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2540 ipa_read_optimization_summaries_1 (pass
->sub
);
2546 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2549 ipa_read_optimization_summaries (void)
2551 pass_manager
*passes
= g
->get_passes ();
2552 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2553 ipa_read_optimization_summaries_1 (passes
->all_lto_gen_passes
);
2556 /* Same as execute_pass_list but assume that subpasses of IPA passes
2557 are local passes. */
2559 execute_ipa_pass_list (struct opt_pass
*pass
)
2563 gcc_assert (!current_function_decl
);
2565 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2566 if (execute_one_pass (pass
) && pass
->sub
)
2568 if (pass
->sub
->type
== GIMPLE_PASS
)
2570 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2571 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2573 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2575 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2576 || pass
->sub
->type
== IPA_PASS
)
2577 execute_ipa_pass_list (pass
->sub
);
2581 gcc_assert (!current_function_decl
);
2582 cgraph_process_new_functions ();
2588 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2591 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2592 struct cgraph_node
*node
, gimple
*stmts
)
2596 /* Execute all of the IPA_PASSes in the list. */
2597 if (pass
->type
== IPA_PASS
2598 && ((!pass
->has_gate
) || pass
->gate ()))
2600 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2602 if (ipa_pass
->stmt_fixup
)
2604 pass_init_dump_file (pass
);
2605 /* If a timevar is present, start it. */
2607 timevar_push (pass
->tv_id
);
2609 ipa_pass
->stmt_fixup (node
, stmts
);
2613 timevar_pop (pass
->tv_id
);
2614 pass_fini_dump_file (pass
);
2617 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2623 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2626 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2628 pass_manager
*passes
= g
->get_passes ();
2629 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2633 extern void debug_properties (unsigned int);
2634 extern void dump_properties (FILE *, unsigned int);
2637 dump_properties (FILE *dump
, unsigned int props
)
2639 fprintf (dump
, "Properties:\n");
2640 if (props
& PROP_gimple_any
)
2641 fprintf (dump
, "PROP_gimple_any\n");
2642 if (props
& PROP_gimple_lcf
)
2643 fprintf (dump
, "PROP_gimple_lcf\n");
2644 if (props
& PROP_gimple_leh
)
2645 fprintf (dump
, "PROP_gimple_leh\n");
2646 if (props
& PROP_cfg
)
2647 fprintf (dump
, "PROP_cfg\n");
2648 if (props
& PROP_ssa
)
2649 fprintf (dump
, "PROP_ssa\n");
2650 if (props
& PROP_no_crit_edges
)
2651 fprintf (dump
, "PROP_no_crit_edges\n");
2652 if (props
& PROP_rtl
)
2653 fprintf (dump
, "PROP_rtl\n");
2654 if (props
& PROP_gimple_lomp
)
2655 fprintf (dump
, "PROP_gimple_lomp\n");
2656 if (props
& PROP_gimple_lcx
)
2657 fprintf (dump
, "PROP_gimple_lcx\n");
2658 if (props
& PROP_gimple_lvec
)
2659 fprintf (dump
, "PROP_gimple_lvec\n");
2660 if (props
& PROP_cfglayout
)
2661 fprintf (dump
, "PROP_cfglayout\n");
2665 debug_properties (unsigned int props
)
2667 dump_properties (stderr
, props
);
2670 /* Called by local passes to see if function is called by already processed nodes.
2671 Because we process nodes in topological order, this means that function is
2672 in recursive cycle or we introduced new direct calls. */
2674 function_called_by_processed_nodes_p (void)
2676 struct cgraph_edge
*e
;
2677 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2681 if (e
->caller
->symbol
.decl
== current_function_decl
)
2683 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2685 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2687 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2692 fprintf (dump_file
, "Already processed call to:\n");
2693 dump_cgraph_node (dump_file
, e
->caller
);
2698 #include "gt-passes.h"