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"
64 #include "tree-flow.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"
78 /* This is used for debugging. It allows the current pass to printed
79 from anywhere in compilation.
80 The variable current_pass is also used for statistics and plugins. */
81 struct opt_pass
*current_pass
;
83 static void register_pass_name (struct opt_pass
*, const char *);
86 opt_pass::operator new (size_t sz
)
88 return ggc_internal_cleared_alloc_stat (sz MEM_STAT_INFO
);
91 void opt_pass::gt_ggc_mx ()
96 /* Avoid deep stack usage by iteratively walking the chain of "next"
97 passes, rather than recursing (analogous to the chain_next/chain_prev
100 /* "this" has already been marked.
101 Mark a chain of as-yet-unmarked passes. */
102 opt_pass
*limit
= this->next
;
103 while (ggc_test_and_set_mark (limit
))
106 /* "limit" is the first in the chain that wasn't just marked, either
107 because it is NULL, or because it was already marked.
108 Hence all of the passes in the half-open interval:
110 have just been marked: visit them. */
111 for (opt_pass
*iter
= this->next
; iter
!= limit
; iter
= iter
->next
)
115 void opt_pass::gt_pch_nx ()
120 /* Analogous to opt_pass::gt_ggc_mx. */
121 opt_pass
*limit
= this->next
;
122 while (gt_pch_note_object (limit
, limit
, ::gt_pch_nx_with_op
<opt_pass
>))
125 for (opt_pass
*iter
= this->next
; iter
!= limit
; iter
= iter
->next
)
130 void opt_pass::gt_pch_nx_with_op (gt_pointer_operator op
, void *cookie
)
132 op (&(ctxt_
), cookie
);
134 op (&(next
), cookie
);
137 /* Most passes are single-instance (within their context) and thus don't
138 need to implement cloning, but passes that support multiple instances
139 *must* provide their own implementation of the clone method.
141 Handle this by providing a default implemenation, but make it a fatal
147 internal_error ("pass %s does not support cloning", name
);
162 opt_pass::opt_pass(const pass_data
&data
, context
*ctxt
)
166 static_pass_number(0),
172 pass_manager::gt_ggc_mx ()
174 /* We want to efficiently visit all pass objects without incurring deep
175 call chains that could blow the stack.
177 Although there are multiple fields referencing passes within the
178 pass_manager, *almost* all of the underlying pass instances are
179 referenced by the passes_by_id array.
181 Specifically, passes are in the passes_by_id array if they have
182 register_one_dump_file called on them, which requires them to have
183 a name, and for that name to *not* begin with "*". Currently
184 there are 25 passes with a "*" prefix and thus not in the array.
186 Each pass holds references to its sub and next, so visiting a pass
187 will potentially trigger a recursive traversal through these
188 neighbours - if these passes haven't been visited yet.
190 By walking the passes_by_id array *backwards*, in the common case
191 this leads to us walking the pass tree from the leaf passes first,
192 eventually reaching the trunk passes, and hence none of the calls
193 should recurse, given that at each point in the iteration pass->sub
194 and pass->next will already have been marked.
196 Having walked the array, we then walk the higher-level fields,
197 again in bottom-up order, which will ensure that we visit all
198 remaining passes. Most of the passes will have already been
199 visited, which should minimize further recursion. */
200 for (int i
= passes_by_id_size
; i
> 0; )
201 ::gt_ggc_mx (passes_by_id
[--i
]);
203 ::gt_ggc_mx (all_late_ipa_passes
);
204 ::gt_ggc_mx (all_lto_gen_passes
);
205 ::gt_ggc_mx (all_regular_ipa_passes
);
206 ::gt_ggc_mx (all_lowering_passes
);
207 ::gt_ggc_mx (all_small_ipa_passes
);
208 ::gt_ggc_mx (all_passes
);
212 pass_manager::gt_pch_nx ()
214 /* Analogous to pass_manager::gt_ggc_mx */
215 for (int i
= passes_by_id_size
; i
> 0; )
216 ::gt_pch_nx (passes_by_id
[--i
]);
218 ::gt_pch_nx (all_late_ipa_passes
);
219 ::gt_pch_nx (all_lto_gen_passes
);
220 ::gt_pch_nx (all_regular_ipa_passes
);
221 ::gt_pch_nx (all_lowering_passes
);
222 ::gt_pch_nx (all_small_ipa_passes
);
223 ::gt_pch_nx (all_passes
);
227 pass_manager::gt_pch_nx_with_op (gt_pointer_operator op
, void *cookie
)
229 /* Unlike the _mx and _nx hooks, we must visit *every* field, since
230 they must each be reconstructed when reading the data back from
232 op (&(all_passes
), cookie
);
233 op (&(all_small_ipa_passes
), cookie
);
234 op (&(all_lowering_passes
), cookie
);
235 op (&(all_regular_ipa_passes
), cookie
);
236 op (&(all_lto_gen_passes
), cookie
);
237 op (&(all_late_ipa_passes
), cookie
);
239 for (int i
= 0; i
< passes_by_id_size
; i
++)
240 op (&(passes_by_id
[i
]), cookie
);
242 #define INSERT_PASSES_AFTER(PASS)
243 #define PUSH_INSERT_PASSES_WITHIN(PASS)
244 #define POP_INSERT_PASSES()
245 #define NEXT_PASS(PASS, NUM) op (&(PASS ## _ ## NUM), cookie);
246 #define TERMINATE_PASS_LIST()
248 #include "pass-instances.def"
250 #undef INSERT_PASSES_AFTER
251 #undef PUSH_INSERT_PASSES_WITHIN
252 #undef POP_INSERT_PASSES
254 #undef TERMINATE_PASS_LIST
259 pass_manager::execute_early_local_passes ()
261 execute_pass_list (pass_early_local_passes_1
->sub
);
265 pass_manager::execute_pass_mode_switching ()
267 return pass_mode_switching_1
->execute ();
271 /* Call from anywhere to find out what pass this is. Useful for
272 printing out debugging information deep inside an service
275 print_current_pass (FILE *file
)
278 fprintf (file
, "current pass = %s (%d)\n",
279 current_pass
->name
, current_pass
->static_pass_number
);
281 fprintf (file
, "no current pass.\n");
285 /* Call from the debugger to get the current pass name. */
289 print_current_pass (stderr
);
294 /* Global variables used to communicate with passes. */
296 bool first_pass_instance
;
299 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
302 This does nothing for local (non-static) variables, unless the
303 variable is a register variable with DECL_ASSEMBLER_NAME set. In
304 that case, or if the variable is not an automatic, it sets up the
305 RTL and outputs any assembler code (label definition, storage
306 allocation and initialization).
308 DECL is the declaration. TOP_LEVEL is nonzero
309 if this declaration is not within a function. */
312 rest_of_decl_compilation (tree decl
,
316 /* We deferred calling assemble_alias so that we could collect
317 other attributes such as visibility. Emit the alias now. */
321 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
324 alias
= TREE_VALUE (TREE_VALUE (alias
));
325 alias
= get_identifier (TREE_STRING_POINTER (alias
));
326 /* A quirk of the initial implementation of aliases required that the
327 user add "extern" to all of them. Which is silly, but now
328 historical. Do note that the symbol is in fact locally defined. */
329 DECL_EXTERNAL (decl
) = 0;
330 TREE_STATIC (decl
) = 1;
331 assemble_alias (decl
, alias
);
335 /* Can't defer this, because it needs to happen before any
336 later function definitions are processed. */
337 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
338 make_decl_rtl (decl
);
340 /* Forward declarations for nested functions are not "external",
341 but we need to treat them as if they were. */
342 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
343 || TREE_CODE (decl
) == FUNCTION_DECL
)
345 timevar_push (TV_VARCONST
);
347 /* Don't output anything when a tentative file-scope definition
348 is seen. But at end of compilation, do output code for them.
350 We do output all variables and rely on
351 callgraph code to defer them except for forward declarations
352 (see gcc.c-torture/compile/920624-1.c) */
354 || !DECL_DEFER_OUTPUT (decl
)
355 || DECL_INITIAL (decl
))
356 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
357 && !DECL_EXTERNAL (decl
))
359 /* When reading LTO unit, we also read varpool, so do not
361 if (in_lto_p
&& !at_end
)
363 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
364 varpool_finalize_decl (decl
);
367 #ifdef ASM_FINISH_DECLARE_OBJECT
368 if (decl
== last_assemble_variable_decl
)
370 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
375 timevar_pop (TV_VARCONST
);
377 else if (TREE_CODE (decl
) == TYPE_DECL
378 /* Like in rest_of_type_compilation, avoid confusing the debug
379 information machinery when there are errors. */
382 timevar_push (TV_SYMOUT
);
383 debug_hooks
->type_decl (decl
, !top_level
);
384 timevar_pop (TV_SYMOUT
);
387 /* Let cgraph know about the existence of variables. */
388 if (in_lto_p
&& !at_end
)
390 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
391 && TREE_STATIC (decl
))
392 varpool_node_for_decl (decl
);
395 /* Called after finishing a record, union or enumeral type. */
398 rest_of_type_compilation (tree type
, int toplev
)
400 /* Avoid confusing the debug information machinery when there are
405 timevar_push (TV_SYMOUT
);
406 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
407 timevar_pop (TV_SYMOUT
);
414 finish_optimization_passes (void)
417 struct dump_file_info
*dfi
;
420 timevar_push (TV_DUMP
);
421 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
423 dump_start (pass_profile_1
->static_pass_number
, NULL
);
425 dump_finish (pass_profile_1
->static_pass_number
);
430 dump_start (pass_profile_1
->static_pass_number
, NULL
);
431 print_combine_total_stats ();
432 dump_finish (pass_profile_1
->static_pass_number
);
435 /* Do whatever is necessary to finish printing the graphs. */
436 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
437 if (dump_initialized_p (i
)
438 && (dfi
->pflags
& TDF_GRAPH
) != 0
439 && (name
= get_dump_file_name (i
)) != NULL
)
441 finish_graph_dump_file (name
);
445 timevar_pop (TV_DUMP
);
449 execute_all_early_local_passes (void)
451 /* Once this pass (and its sub-passes) are complete, all functions
452 will be in SSA form. Technically this state change is happening
453 a tad early, since the sub-passes have not yet run, but since
454 none of the sub-passes are IPA passes and do not create new
455 functions, this is ok. We're setting this value for the benefit
456 of IPA passes that follow. */
457 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
458 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
462 /* Gate: execute, or not, all of the non-trivial optimizations. */
465 gate_all_early_local_passes (void)
467 /* Don't bother doing anything if the program has errors. */
468 return (!seen_error () && !in_lto_p
);
473 const pass_data pass_data_early_local_passes
=
475 SIMPLE_IPA_PASS
, /* type */
476 "early_local_cleanups", /* name */
477 OPTGROUP_NONE
, /* optinfo_flags */
479 true, /* has_execute */
480 TV_EARLY_LOCAL
, /* tv_id */
481 0, /* properties_required */
482 0, /* properties_provided */
483 0, /* properties_destroyed */
484 0, /* todo_flags_start */
485 TODO_remove_functions
, /* todo_flags_finish */
488 class pass_early_local_passes
: public simple_ipa_opt_pass
491 pass_early_local_passes(gcc::context
*ctxt
)
492 : simple_ipa_opt_pass(pass_data_early_local_passes
, ctxt
)
495 /* opt_pass methods: */
496 bool gate () { return gate_all_early_local_passes (); }
497 unsigned int execute () { return execute_all_early_local_passes (); }
499 }; // class pass_early_local_passes
503 simple_ipa_opt_pass
*
504 make_pass_early_local_passes (gcc::context
*ctxt
)
506 return new pass_early_local_passes (ctxt
);
509 /* Gate: execute, or not, all of the non-trivial optimizations. */
512 gate_all_early_optimizations (void)
514 return (optimize
>= 1
515 /* Don't bother doing anything if the program has errors. */
521 const pass_data pass_data_all_early_optimizations
=
523 GIMPLE_PASS
, /* type */
524 "early_optimizations", /* name */
525 OPTGROUP_NONE
, /* optinfo_flags */
527 false, /* has_execute */
529 0, /* properties_required */
530 0, /* properties_provided */
531 0, /* properties_destroyed */
532 0, /* todo_flags_start */
533 0, /* todo_flags_finish */
536 class pass_all_early_optimizations
: public gimple_opt_pass
539 pass_all_early_optimizations(gcc::context
*ctxt
)
540 : gimple_opt_pass(pass_data_all_early_optimizations
, ctxt
)
543 /* opt_pass methods: */
544 bool gate () { return gate_all_early_optimizations (); }
546 }; // class pass_all_early_optimizations
550 static gimple_opt_pass
*
551 make_pass_all_early_optimizations (gcc::context
*ctxt
)
553 return new pass_all_early_optimizations (ctxt
);
556 /* Gate: execute, or not, all of the non-trivial optimizations. */
559 gate_all_optimizations (void)
561 return optimize
>= 1 && !optimize_debug
;
566 const pass_data pass_data_all_optimizations
=
568 GIMPLE_PASS
, /* type */
569 "*all_optimizations", /* name */
570 OPTGROUP_NONE
, /* optinfo_flags */
572 false, /* has_execute */
573 TV_OPTIMIZE
, /* tv_id */
574 0, /* properties_required */
575 0, /* properties_provided */
576 0, /* properties_destroyed */
577 0, /* todo_flags_start */
578 0, /* todo_flags_finish */
581 class pass_all_optimizations
: public gimple_opt_pass
584 pass_all_optimizations(gcc::context
*ctxt
)
585 : gimple_opt_pass(pass_data_all_optimizations
, ctxt
)
588 /* opt_pass methods: */
589 bool gate () { return gate_all_optimizations (); }
591 }; // class pass_all_optimizations
595 static gimple_opt_pass
*
596 make_pass_all_optimizations (gcc::context
*ctxt
)
598 return new pass_all_optimizations (ctxt
);
601 /* Gate: execute, or not, all of the non-trivial optimizations. */
604 gate_all_optimizations_g (void)
606 return optimize
>= 1 && optimize_debug
;
611 const pass_data pass_data_all_optimizations_g
=
613 GIMPLE_PASS
, /* type */
614 "*all_optimizations_g", /* name */
615 OPTGROUP_NONE
, /* optinfo_flags */
617 false, /* has_execute */
618 TV_OPTIMIZE
, /* tv_id */
619 0, /* properties_required */
620 0, /* properties_provided */
621 0, /* properties_destroyed */
622 0, /* todo_flags_start */
623 0, /* todo_flags_finish */
626 class pass_all_optimizations_g
: public gimple_opt_pass
629 pass_all_optimizations_g(gcc::context
*ctxt
)
630 : gimple_opt_pass(pass_data_all_optimizations_g
, ctxt
)
633 /* opt_pass methods: */
634 bool gate () { return gate_all_optimizations_g (); }
636 }; // class pass_all_optimizations_g
640 static gimple_opt_pass
*
641 make_pass_all_optimizations_g (gcc::context
*ctxt
)
643 return new pass_all_optimizations_g (ctxt
);
647 gate_rest_of_compilation (void)
649 /* Early return if there were errors. We can run afoul of our
650 consistency checks, and there's not really much point in fixing them. */
651 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
656 const pass_data pass_data_rest_of_compilation
=
659 "*rest_of_compilation", /* name */
660 OPTGROUP_NONE
, /* optinfo_flags */
662 false, /* has_execute */
663 TV_REST_OF_COMPILATION
, /* tv_id */
664 PROP_rtl
, /* properties_required */
665 0, /* properties_provided */
666 0, /* properties_destroyed */
667 0, /* todo_flags_start */
668 0, /* todo_flags_finish */
671 class pass_rest_of_compilation
: public rtl_opt_pass
674 pass_rest_of_compilation(gcc::context
*ctxt
)
675 : rtl_opt_pass(pass_data_rest_of_compilation
, ctxt
)
678 /* opt_pass methods: */
679 bool gate () { return gate_rest_of_compilation (); }
681 }; // class pass_rest_of_compilation
685 static rtl_opt_pass
*
686 make_pass_rest_of_compilation (gcc::context
*ctxt
)
688 return new pass_rest_of_compilation (ctxt
);
692 gate_postreload (void)
694 return reload_completed
;
699 const pass_data pass_data_postreload
=
702 "*all-postreload", /* name */
703 OPTGROUP_NONE
, /* optinfo_flags */
705 false, /* has_execute */
706 TV_POSTRELOAD
, /* tv_id */
707 PROP_rtl
, /* properties_required */
708 0, /* properties_provided */
709 0, /* properties_destroyed */
710 0, /* todo_flags_start */
711 TODO_verify_rtl_sharing
, /* todo_flags_finish */
714 class pass_postreload
: public rtl_opt_pass
717 pass_postreload(gcc::context
*ctxt
)
718 : rtl_opt_pass(pass_data_postreload
, ctxt
)
721 /* opt_pass methods: */
722 bool gate () { return gate_postreload (); }
724 }; // class pass_postreload
728 static rtl_opt_pass
*
729 make_pass_postreload (gcc::context
*ctxt
)
731 return new pass_postreload (ctxt
);
736 /* Set the static pass number of pass PASS to ID and record that
737 in the mapping from static pass number to pass. */
741 set_pass_for_id (int id
, struct opt_pass
*pass
)
743 pass
->static_pass_number
= id
;
744 if (passes_by_id_size
<= id
)
746 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
747 memset (passes_by_id
+ passes_by_id_size
, 0,
748 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
749 passes_by_id_size
= id
+ 1;
751 passes_by_id
[id
] = pass
;
754 /* Return the pass with the static pass number ID. */
757 pass_manager::get_pass_for_id (int id
) const
759 if (id
>= passes_by_id_size
)
761 return passes_by_id
[id
];
764 /* Iterate over the pass tree allocating dump file numbers. We want
765 to do this depth first, and independent of whether the pass is
769 register_one_dump_file (struct opt_pass
*pass
)
771 g
->get_passes ()->register_one_dump_file (pass
);
775 pass_manager::register_one_dump_file (struct opt_pass
*pass
)
777 char *dot_name
, *flag_name
, *glob_name
;
778 const char *name
, *full_name
, *prefix
;
781 int optgroup_flags
= OPTGROUP_NONE
;
783 /* See below in next_pass_1. */
785 if (pass
->static_pass_number
!= -1)
786 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
787 ? 1 : pass
->static_pass_number
));
789 /* The name is both used to identify the pass for the purposes of plugins,
790 and to specify dump file name and option.
791 The latter two might want something short which is not quite unique; for
792 that reason, we may have a disambiguating prefix, followed by a space
793 to mark the start of the following dump file name / option string. */
794 name
= strchr (pass
->name
, ' ');
795 name
= name
? name
+ 1 : pass
->name
;
796 dot_name
= concat (".", name
, num
, NULL
);
797 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
801 optgroup_flags
|= OPTGROUP_IPA
;
803 else if (pass
->type
== GIMPLE_PASS
)
814 flag_name
= concat (prefix
, name
, num
, NULL
);
815 glob_name
= concat (prefix
, name
, NULL
);
816 optgroup_flags
|= pass
->optinfo_flags
;
817 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
, optgroup_flags
);
818 set_pass_for_id (id
, pass
);
819 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
820 register_pass_name (pass
, full_name
);
821 free (CONST_CAST (char *, full_name
));
824 /* Recursive worker function for register_dump_files. */
828 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
832 int new_properties
= (properties
| pass
->properties_provided
)
833 & ~pass
->properties_destroyed
;
835 if (pass
->name
&& pass
->name
[0] != '*')
836 register_one_dump_file (pass
);
839 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
841 /* If we have a gate, combine the properties that we could have with
842 and without the pass being examined. */
844 properties
&= new_properties
;
846 properties
= new_properties
;
855 /* Register the dump files for the pass_manager starting at PASS.
856 PROPERTIES reflects the properties that are guaranteed to be available at
857 the beginning of the pipeline. */
861 register_dump_files (struct opt_pass
*pass
,int properties
)
863 pass
->properties_required
|= properties
;
864 register_dump_files_1 (pass
, properties
);
869 const char* unique_name
;
870 struct opt_pass
*pass
;
873 /* Helper for pass_registry hash table. */
875 struct pass_registry_hasher
: typed_noop_remove
<pass_registry
>
877 typedef pass_registry value_type
;
878 typedef pass_registry compare_type
;
879 static inline hashval_t
hash (const value_type
*);
880 static inline bool equal (const value_type
*, const compare_type
*);
883 /* Pass registry hash function. */
886 pass_registry_hasher::hash (const value_type
*s
)
888 return htab_hash_string (s
->unique_name
);
891 /* Hash equal function */
894 pass_registry_hasher::equal (const value_type
*s1
, const compare_type
*s2
)
896 return !strcmp (s1
->unique_name
, s2
->unique_name
);
899 static hash_table
<pass_registry_hasher
> name_to_pass_map
;
901 /* Register PASS with NAME. */
904 register_pass_name (struct opt_pass
*pass
, const char *name
)
906 struct pass_registry
**slot
;
907 struct pass_registry pr
;
909 if (!name_to_pass_map
.is_created ())
910 name_to_pass_map
.create (256);
912 pr
.unique_name
= name
;
913 slot
= name_to_pass_map
.find_slot (&pr
, INSERT
);
916 struct pass_registry
*new_pr
;
918 new_pr
= XCNEW (struct pass_registry
);
919 new_pr
->unique_name
= xstrdup (name
);
924 return; /* Ignore plugin passes. */
927 /* Map from pass id to canonicalized pass name. */
929 typedef const char *char_ptr
;
930 static vec
<char_ptr
> pass_tab
= vNULL
;
932 /* Callback function for traversing NAME_TO_PASS_MAP. */
935 passes_pass_traverse (pass_registry
**p
, void *data ATTRIBUTE_UNUSED
)
937 struct opt_pass
*pass
= (*p
)->pass
;
939 gcc_assert (pass
->static_pass_number
> 0);
940 gcc_assert (pass_tab
.exists ());
942 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
947 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
948 table for dumping purpose. */
951 create_pass_tab (void)
953 if (!flag_dump_passes
)
956 pass_tab
.safe_grow_cleared (g
->get_passes ()->passes_by_id_size
+ 1);
957 name_to_pass_map
.traverse
<void *, passes_pass_traverse
> (NULL
);
960 static bool override_gate_status (struct opt_pass
*, tree
, bool);
962 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
963 is turned on or not. */
966 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
968 int indent
= 3 * pass_indent
;
970 bool is_on
, is_really_on
;
972 is_on
= pass
->has_gate
? pass
->gate() : true;
973 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
975 if (pass
->static_pass_number
<= 0)
978 pn
= pass_tab
[pass
->static_pass_number
];
980 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
981 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
982 is_on
? " ON" : " OFF",
983 ((!is_on
) == (!is_really_on
) ? ""
984 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
987 /* Dump pass list PASS with indentation INDENT. */
990 dump_pass_list (struct opt_pass
*pass
, int indent
)
994 dump_one_pass (pass
, indent
);
996 dump_pass_list (pass
->sub
, indent
+ 1);
1002 /* Dump all optimization passes. */
1007 g
->get_passes ()->dump_passes ();
1011 pass_manager::dump_passes () const
1013 struct cgraph_node
*n
, *node
= NULL
;
1017 FOR_EACH_FUNCTION (n
)
1018 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
1027 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1029 dump_pass_list (all_lowering_passes
, 1);
1030 dump_pass_list (all_small_ipa_passes
, 1);
1031 dump_pass_list (all_regular_ipa_passes
, 1);
1032 dump_pass_list (all_lto_gen_passes
, 1);
1033 dump_pass_list (all_late_ipa_passes
, 1);
1034 dump_pass_list (all_passes
, 1);
1040 /* Returns the pass with NAME. */
1042 static struct opt_pass
*
1043 get_pass_by_name (const char *name
)
1045 struct pass_registry
**slot
, pr
;
1047 pr
.unique_name
= name
;
1048 slot
= name_to_pass_map
.find_slot (&pr
, NO_INSERT
);
1050 if (!slot
|| !*slot
)
1053 return (*slot
)->pass
;
1057 /* Range [start, last]. */
1063 const char *assem_name
;
1064 struct uid_range
*next
;
1067 typedef struct uid_range
*uid_range_p
;
1070 static vec
<uid_range_p
>
1071 enabled_pass_uid_range_tab
= vNULL
;
1072 static vec
<uid_range_p
>
1073 disabled_pass_uid_range_tab
= vNULL
;
1076 /* Parse option string for -fdisable- and -fenable-
1077 The syntax of the options:
1079 -fenable-<pass_name>
1080 -fdisable-<pass_name>
1082 -fenable-<pass_name>=s1:e1,s2:e2,...
1083 -fdisable-<pass_name>=s1:e1,s2:e2,...
1087 enable_disable_pass (const char *arg
, bool is_enable
)
1089 struct opt_pass
*pass
;
1090 char *range_str
, *phase_name
;
1091 char *argstr
= xstrdup (arg
);
1092 vec
<uid_range_p
> *tab
= 0;
1094 range_str
= strchr (argstr
,'=');
1101 phase_name
= argstr
;
1105 error ("unrecognized option -fenable");
1107 error ("unrecognized option -fdisable");
1111 pass
= get_pass_by_name (phase_name
);
1112 if (!pass
|| pass
->static_pass_number
== -1)
1115 error ("unknown pass %s specified in -fenable", phase_name
);
1117 error ("unknown pass %s specified in -fdisable", phase_name
);
1123 tab
= &enabled_pass_uid_range_tab
;
1125 tab
= &disabled_pass_uid_range_tab
;
1127 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
1128 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
1133 uid_range_p new_range
= XCNEW (struct uid_range
);
1135 new_range
->start
= 0;
1136 new_range
->last
= (unsigned)-1;
1138 slot
= (*tab
)[pass
->static_pass_number
];
1139 new_range
->next
= slot
;
1140 (*tab
)[pass
->static_pass_number
] = new_range
;
1142 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
1143 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1145 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
1146 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
1150 char *next_range
= NULL
;
1151 char *one_range
= range_str
;
1152 char *end_val
= NULL
;
1157 uid_range_p new_range
;
1158 char *invalid
= NULL
;
1160 char *func_name
= NULL
;
1162 next_range
= strchr (one_range
, ',');
1169 end_val
= strchr (one_range
, ':');
1175 start
= strtol (one_range
, &invalid
, 10);
1176 if (*invalid
|| start
< 0)
1178 if (end_val
|| (one_range
[0] >= '0'
1179 && one_range
[0] <= '9'))
1181 error ("Invalid range %s in option %s",
1183 is_enable
? "-fenable" : "-fdisable");
1187 func_name
= one_range
;
1191 new_range
= XCNEW (struct uid_range
);
1194 new_range
->start
= (unsigned) start
;
1195 new_range
->last
= (unsigned) start
;
1199 new_range
->start
= (unsigned) -1;
1200 new_range
->last
= (unsigned) -1;
1201 new_range
->assem_name
= xstrdup (func_name
);
1206 long last
= strtol (end_val
, &invalid
, 10);
1207 if (*invalid
|| last
< start
)
1209 error ("Invalid range %s in option %s",
1211 is_enable
? "-fenable" : "-fdisable");
1215 new_range
= XCNEW (struct uid_range
);
1216 new_range
->start
= (unsigned) start
;
1217 new_range
->last
= (unsigned) last
;
1220 slot
= (*tab
)[pass
->static_pass_number
];
1221 new_range
->next
= slot
;
1222 (*tab
)[pass
->static_pass_number
] = new_range
;
1225 if (new_range
->assem_name
)
1226 inform (UNKNOWN_LOCATION
,
1227 "enable pass %s for function %s",
1228 phase_name
, new_range
->assem_name
);
1230 inform (UNKNOWN_LOCATION
,
1231 "enable pass %s for functions in the range of [%u, %u]",
1232 phase_name
, new_range
->start
, new_range
->last
);
1236 if (new_range
->assem_name
)
1237 inform (UNKNOWN_LOCATION
,
1238 "disable pass %s for function %s",
1239 phase_name
, new_range
->assem_name
);
1241 inform (UNKNOWN_LOCATION
,
1242 "disable pass %s for functions in the range of [%u, %u]",
1243 phase_name
, new_range
->start
, new_range
->last
);
1246 one_range
= next_range
;
1247 } while (next_range
);
1253 /* Enable pass specified by ARG. */
1256 enable_pass (const char *arg
)
1258 enable_disable_pass (arg
, true);
1261 /* Disable pass specified by ARG. */
1264 disable_pass (const char *arg
)
1266 enable_disable_pass (arg
, false);
1269 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
1272 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
1274 vec
<uid_range_p
> tab
)
1276 uid_range_p slot
, range
;
1278 const char *aname
= NULL
;
1281 || (unsigned) pass
->static_pass_number
>= tab
.length ()
1282 || pass
->static_pass_number
== -1)
1285 slot
= tab
[pass
->static_pass_number
];
1289 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
1290 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1291 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1296 if ((unsigned) cgraph_uid
>= range
->start
1297 && (unsigned) cgraph_uid
<= range
->last
)
1299 if (range
->assem_name
&& aname
1300 && !strcmp (range
->assem_name
, aname
))
1302 range
= range
->next
;
1309 /* Update static_pass_number for passes (and the flag
1310 TODO_mark_first_instance).
1312 Passes are constructed with static_pass_number preinitialized to 0
1314 This field is used in two different ways: initially as instance numbers
1315 of their kind, and then as ids within the entire pass manager.
1317 Within pass_manager::pass_manager:
1319 * In add_pass_instance(), as called by next_pass_1 in
1320 NEXT_PASS in init_optimization_passes
1322 * When the initial instance of a pass within a pass manager is seen,
1323 it is flagged, and its static_pass_number is set to -1
1325 * On subsequent times that it is seen, the static pass number
1326 is decremented each time, so that if there are e.g. 4 dups,
1327 they have static_pass_number -4, 2, 3, 4 respectively (note
1328 how the initial one is negative and gives the count); these
1329 can be thought of as instance numbers of the specific pass
1331 * Within the register_dump_files () traversal, set_pass_for_id()
1332 is called on each pass, using these instance numbers to create
1333 dumpfile switches, and then overwriting them with a pass id,
1334 which are global to the whole pass manager (based on
1335 (TDI_end + current value of extra_dump_files_in_use) ) */
1338 add_pass_instance (struct opt_pass
*new_pass
, bool track_duplicates
,
1339 opt_pass
*initial_pass
)
1341 /* Are we dealing with the first pass of its kind, or a clone? */
1342 if (new_pass
!= initial_pass
)
1344 /* We're dealing with a clone. */
1345 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1347 /* Indicate to register_dump_files that this pass has duplicates,
1348 and so it should rename the dump file. The first instance will
1349 be -1, and be number of duplicates = -static_pass_number - 1.
1350 Subsequent instances will be > 0 and just the duplicate number. */
1351 if ((new_pass
->name
&& new_pass
->name
[0] != '*') || track_duplicates
)
1353 initial_pass
->static_pass_number
-= 1;
1354 new_pass
->static_pass_number
= -initial_pass
->static_pass_number
;
1359 /* We're dealing with the first pass of its kind. */
1360 new_pass
->todo_flags_start
|= TODO_mark_first_instance
;
1361 new_pass
->static_pass_number
= -1;
1363 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, new_pass
);
1367 /* Add a pass to the pass list. Duplicate the pass if it's already
1370 static struct opt_pass
**
1371 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
,
1372 struct opt_pass
*initial_pass
)
1374 /* Every pass should have a name so that plugins can refer to them. */
1375 gcc_assert (pass
->name
!= NULL
);
1377 add_pass_instance (pass
, false, initial_pass
);
1380 return &(*list
)->next
;
1383 /* List node for an inserted pass instance. We need to keep track of all
1384 the newly-added pass instances (with 'added_pass_nodes' defined below)
1385 so that we can register their dump files after pass-positioning is finished.
1386 Registering dumping files needs to be post-processed or the
1387 static_pass_number of the opt_pass object would be modified and mess up
1388 the dump file names of future pass instances to be added. */
1390 struct pass_list_node
1392 struct opt_pass
*pass
;
1393 struct pass_list_node
*next
;
1396 static struct pass_list_node
*added_pass_nodes
= NULL
;
1397 static struct pass_list_node
*prev_added_pass_node
;
1399 /* Insert the pass at the proper position. Return true if the pass
1400 is successfully added.
1402 NEW_PASS_INFO - new pass to be inserted
1403 PASS_LIST - root of the pass list to insert the new pass to */
1406 position_pass (struct register_pass_info
*new_pass_info
,
1407 struct opt_pass
**pass_list
)
1409 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1410 bool success
= false;
1412 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1414 /* Check if the current pass is of the same type as the new pass and
1415 matches the name and the instance number of the reference pass. */
1416 if (pass
->type
== new_pass_info
->pass
->type
1418 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1419 && ((new_pass_info
->ref_pass_instance_number
== 0)
1420 || (new_pass_info
->ref_pass_instance_number
==
1421 pass
->static_pass_number
)
1422 || (new_pass_info
->ref_pass_instance_number
== 1
1423 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1425 struct opt_pass
*new_pass
;
1426 struct pass_list_node
*new_pass_node
;
1428 if (new_pass_info
->ref_pass_instance_number
== 0)
1430 new_pass
= new_pass_info
->pass
->clone ();
1431 add_pass_instance (new_pass
, true, new_pass_info
->pass
);
1435 new_pass
= new_pass_info
->pass
;
1436 add_pass_instance (new_pass
, true, new_pass
);
1439 /* Insert the new pass instance based on the positioning op. */
1440 switch (new_pass_info
->pos_op
)
1442 case PASS_POS_INSERT_AFTER
:
1443 new_pass
->next
= pass
->next
;
1444 pass
->next
= new_pass
;
1446 /* Skip newly inserted pass to avoid repeated
1447 insertions in the case where the new pass and the
1448 existing one have the same name. */
1451 case PASS_POS_INSERT_BEFORE
:
1452 new_pass
->next
= pass
;
1454 prev_pass
->next
= new_pass
;
1456 *pass_list
= new_pass
;
1458 case PASS_POS_REPLACE
:
1459 new_pass
->next
= pass
->next
;
1461 prev_pass
->next
= new_pass
;
1463 *pass_list
= new_pass
;
1464 new_pass
->sub
= pass
->sub
;
1465 new_pass
->tv_id
= pass
->tv_id
;
1469 error ("invalid pass positioning operation");
1473 /* Save the newly added pass (instance) in the added_pass_nodes
1474 list so that we can register its dump file later. Note that
1475 we cannot register the dump file now because doing so will modify
1476 the static_pass_number of the opt_pass object and therefore
1477 mess up the dump file name of future instances. */
1478 new_pass_node
= XCNEW (struct pass_list_node
);
1479 new_pass_node
->pass
= new_pass
;
1480 if (!added_pass_nodes
)
1481 added_pass_nodes
= new_pass_node
;
1483 prev_added_pass_node
->next
= new_pass_node
;
1484 prev_added_pass_node
= new_pass_node
;
1489 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1496 /* Hooks a new pass into the pass lists.
1498 PASS_INFO - pass information that specifies the opt_pass object,
1499 reference pass, instance number, and how to position
1503 register_pass (struct register_pass_info
*pass_info
)
1505 g
->get_passes ()->register_pass (pass_info
);
1510 pass_manager::register_pass (struct register_pass_info
*pass_info
)
1512 bool all_instances
, success
;
1514 /* The checks below could fail in buggy plugins. Existing GCC
1515 passes should never fail these checks, so we mention plugin in
1517 if (!pass_info
->pass
)
1518 fatal_error ("plugin cannot register a missing pass");
1520 if (!pass_info
->pass
->name
)
1521 fatal_error ("plugin cannot register an unnamed pass");
1523 if (!pass_info
->reference_pass_name
)
1525 ("plugin cannot register pass %qs without reference pass name",
1526 pass_info
->pass
->name
);
1528 /* Try to insert the new pass to the pass lists. We need to check
1529 all five lists as the reference pass could be in one (or all) of
1531 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1532 success
= position_pass (pass_info
, &all_lowering_passes
);
1533 if (!success
|| all_instances
)
1534 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1535 if (!success
|| all_instances
)
1536 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1537 if (!success
|| all_instances
)
1538 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1539 if (!success
|| all_instances
)
1540 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1541 if (!success
|| all_instances
)
1542 success
|= position_pass (pass_info
, &all_passes
);
1545 ("pass %qs not found but is referenced by new pass %qs",
1546 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1548 /* OK, we have successfully inserted the new pass. We need to register
1549 the dump files for the newly added pass and its duplicates (if any).
1550 Because the registration of plugin/backend passes happens after the
1551 command-line options are parsed, the options that specify single
1552 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1553 passes. Therefore we currently can only enable dumping of
1554 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1555 are specified. While doing so, we also delete the pass_list_node
1556 objects created during pass positioning. */
1557 while (added_pass_nodes
)
1559 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1560 enum tree_dump_index tdi
;
1561 register_one_dump_file (added_pass_nodes
->pass
);
1562 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1563 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1565 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1569 /* Check if dump-all flag is specified. */
1570 if (get_dump_file_info (tdi
)->pstate
)
1571 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1572 ->pstate
= get_dump_file_info (tdi
)->pstate
;
1573 XDELETE (added_pass_nodes
);
1574 added_pass_nodes
= next_node
;
1578 /* Construct the pass tree. The sequencing of passes is driven by
1579 the cgraph routines:
1581 finalize_compilation_unit ()
1582 for each node N in the cgraph
1583 cgraph_analyze_function (N)
1584 cgraph_lower_function (N) -> all_lowering_passes
1586 If we are optimizing, compile is then invoked:
1589 ipa_passes () -> all_small_ipa_passes
1590 -> Analysis of all_regular_ipa_passes
1591 * possible LTO streaming at copmilation time *
1592 -> Execution of all_regular_ipa_passes
1593 * possible LTO streaming at link time *
1594 -> all_late_ipa_passes
1595 expand_all_functions ()
1596 for each node N in the cgraph
1597 expand_function (N) -> Transformation of all_regular_ipa_passes
1602 pass_manager::operator new (size_t sz
)
1604 /* Ensure that all fields of the pass manager are zero-initialized. */
1605 return ggc_internal_cleared_alloc_stat (sz MEM_STAT_INFO
);
1608 pass_manager::pass_manager (context
*ctxt
)
1609 : all_passes(NULL
), all_small_ipa_passes(NULL
), all_lowering_passes(NULL
),
1610 all_regular_ipa_passes(NULL
), all_lto_gen_passes(NULL
),
1611 all_late_ipa_passes(NULL
), passes_by_id(NULL
), passes_by_id_size(0),
1614 struct opt_pass
**p
;
1616 /* Initialize the pass_lists array. */
1617 #define DEF_PASS_LIST(LIST) pass_lists[PASS_LIST_NO_##LIST] = &LIST;
1619 #undef DEF_PASS_LIST
1621 /* Build the tree of passes. */
1623 #define INSERT_PASSES_AFTER(PASS) \
1626 #define PUSH_INSERT_PASSES_WITHIN(PASS) \
1628 struct opt_pass **p = &(PASS ## _1)->sub;
1630 #define POP_INSERT_PASSES() \
1633 #define NEXT_PASS(PASS, NUM) \
1635 gcc_assert (NULL == PASS ## _ ## NUM); \
1637 PASS ## _1 = make_##PASS (ctxt_); \
1640 gcc_assert (PASS ## _1); \
1641 PASS ## _ ## NUM = PASS ## _1->clone (); \
1643 p = next_pass_1 (p, PASS ## _ ## NUM, PASS ## _1); \
1646 #define TERMINATE_PASS_LIST() \
1649 #include "pass-instances.def"
1651 #undef INSERT_PASSES_AFTER
1652 #undef PUSH_INSERT_PASSES_WITHIN
1653 #undef POP_INSERT_PASSES
1655 #undef TERMINATE_PASS_LIST
1657 /* Register the passes with the tree dump code. */
1658 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1659 register_dump_files (all_small_ipa_passes
,
1660 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1662 register_dump_files (all_regular_ipa_passes
,
1663 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1665 register_dump_files (all_lto_gen_passes
,
1666 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1668 register_dump_files (all_late_ipa_passes
,
1669 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1671 register_dump_files (all_passes
,
1672 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1676 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1677 function CALLBACK for every function in the call graph. Otherwise,
1678 call CALLBACK on the current function. */
1681 do_per_function (void (*callback
) (void *data
), void *data
)
1683 if (current_function_decl
)
1687 struct cgraph_node
*node
;
1688 FOR_EACH_DEFINED_FUNCTION (node
)
1689 if (node
->symbol
.analyzed
&& gimple_has_body_p (node
->symbol
.decl
)
1690 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1692 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1696 free_dominance_info (CDI_DOMINATORS
);
1697 free_dominance_info (CDI_POST_DOMINATORS
);
1705 /* Because inlining might remove no-longer reachable nodes, we need to
1706 keep the array visible to garbage collector to avoid reading collected
1709 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1711 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1712 function CALLBACK for every function in the call graph. Otherwise,
1713 call CALLBACK on the current function.
1714 This function is global so that plugins can use it. */
1716 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1720 if (current_function_decl
)
1724 gcc_assert (!order
);
1725 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1726 nnodes
= ipa_reverse_postorder (order
);
1727 for (i
= nnodes
- 1; i
>= 0; i
--)
1728 order
[i
]->process
= 1;
1729 for (i
= nnodes
- 1; i
>= 0; i
--)
1731 struct cgraph_node
*node
= order
[i
];
1733 /* Allow possibly removed nodes to be garbage collected. */
1736 if (cgraph_function_with_gimple_body_p (node
))
1738 cgraph_get_body (node
);
1739 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1741 free_dominance_info (CDI_DOMINATORS
);
1742 free_dominance_info (CDI_POST_DOMINATORS
);
1753 /* Helper function to perform function body dump. */
1756 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1758 if (dump_file
&& current_function_decl
)
1760 if (cfun
->curr_properties
& PROP_trees
)
1761 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1763 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1765 /* Flush the file. If verification fails, we won't be able to
1766 close the file before aborting. */
1769 if ((cfun
->curr_properties
& PROP_cfg
)
1770 && (dump_flags
& TDF_GRAPH
))
1771 print_graph_cfg (dump_file_name
, cfun
);
1775 static struct profile_record
*profile_record
;
1777 /* Do profile consistency book-keeping for the pass with static number INDEX.
1778 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1779 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1780 if we are only book-keeping on passes that may have selectively disabled
1781 themselves on a given function. */
1783 check_profile_consistency (int index
, int subpass
, bool run
)
1785 pass_manager
*passes
= g
->get_passes ();
1788 if (!profile_record
)
1789 profile_record
= XCNEWVEC (struct profile_record
,
1790 passes
->passes_by_id_size
);
1791 gcc_assert (index
< passes
->passes_by_id_size
&& index
>= 0);
1792 gcc_assert (subpass
< 2);
1793 profile_record
[index
].run
|= run
;
1794 account_profile_record (&profile_record
[index
], subpass
);
1797 /* Output profile consistency. */
1800 dump_profile_report (void)
1802 g
->get_passes ()->dump_profile_report ();
1806 pass_manager::dump_profile_report () const
1809 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1810 gcov_type last_time
= 0, last_size
= 0;
1811 double rel_time_change
, rel_size_change
;
1812 int last_reported
= 0;
1814 if (!profile_record
)
1816 fprintf (stderr
, "\nProfile consistency report:\n\n");
1817 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1818 fprintf (stderr
, " |freq count |freq count |size time\n");
1820 for (i
= 0; i
< passes_by_id_size
; i
++)
1821 for (j
= 0 ; j
< 2; j
++)
1822 if (profile_record
[i
].run
)
1825 rel_time_change
= (profile_record
[i
].time
[j
]
1826 - (double)last_time
) * 100 / (double)last_time
;
1828 rel_time_change
= 0;
1830 rel_size_change
= (profile_record
[i
].size
[j
]
1831 - (double)last_size
) * 100 / (double)last_size
;
1833 rel_size_change
= 0;
1835 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1836 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1837 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1838 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1839 || rel_time_change
|| rel_size_change
)
1842 fprintf (stderr
, "%-20s %s",
1843 passes_by_id
[i
]->name
,
1844 j
? "(after TODO)" : " ");
1845 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1846 fprintf (stderr
, "| %+5i",
1847 profile_record
[i
].num_mismatched_freq_in
[j
]
1850 fprintf (stderr
, "| ");
1851 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1852 fprintf (stderr
, " %+5i",
1853 profile_record
[i
].num_mismatched_count_in
[j
]
1856 fprintf (stderr
, " ");
1857 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1858 fprintf (stderr
, "| %+5i",
1859 profile_record
[i
].num_mismatched_freq_out
[j
]
1862 fprintf (stderr
, "| ");
1863 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1864 fprintf (stderr
, " %+5i",
1865 profile_record
[i
].num_mismatched_count_out
[j
]
1868 fprintf (stderr
, " ");
1870 /* Size/time units change across gimple and RTL. */
1871 if (i
== pass_expand_1
->static_pass_number
)
1872 fprintf (stderr
, "|----------");
1875 if (rel_size_change
)
1876 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1878 fprintf (stderr
, "| ");
1879 if (rel_time_change
)
1880 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1882 fprintf (stderr
, "\n");
1883 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1884 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1885 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1886 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1888 else if (j
&& last_reported
!= i
)
1891 fprintf (stderr
, "%-20s ------------| | |\n",
1892 passes_by_id
[i
]->name
);
1894 last_time
= profile_record
[i
].time
[j
];
1895 last_size
= profile_record
[i
].size
[j
];
1899 /* Perform all TODO actions that ought to be done on each function. */
1902 execute_function_todo (void *data
)
1904 unsigned int flags
= (size_t)data
;
1905 flags
&= ~cfun
->last_verified
;
1909 /* Always cleanup the CFG before trying to update SSA. */
1910 if (flags
& TODO_cleanup_cfg
)
1912 cleanup_tree_cfg ();
1914 /* When cleanup_tree_cfg merges consecutive blocks, it may
1915 perform some simplistic propagation when removing single
1916 valued PHI nodes. This propagation may, in turn, cause the
1917 SSA form to become out-of-date (see PR 22037). So, even
1918 if the parent pass had not scheduled an SSA update, we may
1919 still need to do one. */
1920 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1921 flags
|= TODO_update_ssa
;
1924 if (flags
& TODO_update_ssa_any
)
1926 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1927 update_ssa (update_flags
);
1928 cfun
->last_verified
&= ~TODO_verify_ssa
;
1931 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1932 compute_may_aliases ();
1934 if (optimize
&& (flags
& TODO_update_address_taken
))
1935 execute_update_addresses_taken ();
1937 if (flags
& TODO_remove_unused_locals
)
1938 remove_unused_locals ();
1940 if (flags
& TODO_rebuild_frequencies
)
1941 rebuild_frequencies ();
1943 if (flags
& TODO_rebuild_cgraph_edges
)
1944 rebuild_cgraph_edges ();
1946 /* If we've seen errors do not bother running any verifiers. */
1950 #if defined ENABLE_CHECKING
1951 if (flags
& TODO_verify_ssa
1952 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1954 verify_gimple_in_cfg (cfun
);
1957 else if (flags
& TODO_verify_stmts
)
1958 verify_gimple_in_cfg (cfun
);
1959 if (flags
& TODO_verify_flow
)
1960 verify_flow_info ();
1961 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1962 verify_loop_closed_ssa (false);
1963 if (flags
& TODO_verify_rtl_sharing
)
1964 verify_rtl_sharing ();
1967 cfun
->last_verified
= flags
& TODO_verify_all
;
1970 /* Perform all TODO actions. */
1972 execute_todo (unsigned int flags
)
1974 #if defined ENABLE_CHECKING
1976 && need_ssa_update_p (cfun
))
1977 gcc_assert (flags
& TODO_update_ssa_any
);
1980 timevar_push (TV_TODO
);
1982 /* Inform the pass whether it is the first time it is run. */
1983 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1985 statistics_fini_pass ();
1987 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1989 /* Always remove functions just as before inlining: IPA passes might be
1990 interested to see bodies of extern inline functions that are not inlined
1991 to analyze side effects. The full removal is done just at the end
1992 of IPA pass queue. */
1993 if (flags
& TODO_remove_functions
)
1996 symtab_remove_unreachable_nodes (true, dump_file
);
1999 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2002 dump_symtab (dump_file
);
2003 /* Flush the file. If verification fails, we won't be able to
2004 close the file before aborting. */
2008 /* Now that the dumping has been done, we can get rid of the optional
2010 if (flags
& TODO_df_finish
)
2011 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2013 timevar_pop (TV_TODO
);
2016 /* Verify invariants that should hold between passes. This is a place
2017 to put simple sanity checks. */
2020 verify_interpass_invariants (void)
2022 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2025 /* Clear the last verified flag. */
2028 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
2030 cfun
->last_verified
= 0;
2033 /* Helper function. Verify that the properties has been turn into the
2034 properties expected by the pass. */
2036 #ifdef ENABLE_CHECKING
2038 verify_curr_properties (void *data
)
2040 unsigned int props
= (size_t)data
;
2041 gcc_assert ((cfun
->curr_properties
& props
) == props
);
2045 /* Initialize pass dump file. */
2046 /* This is non-static so that the plugins can use it. */
2049 pass_init_dump_file (struct opt_pass
*pass
)
2051 /* If a dump file name is present, open it if enabled. */
2052 if (pass
->static_pass_number
!= -1)
2054 timevar_push (TV_DUMP
);
2055 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
2056 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
2057 dump_start (pass
->static_pass_number
, &dump_flags
);
2058 if (dump_file
&& current_function_decl
)
2059 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2060 if (initializing_dump
2061 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2062 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2063 clean_graph_dump_file (dump_file_name
);
2064 timevar_pop (TV_DUMP
);
2065 return initializing_dump
;
2071 /* Flush PASS dump file. */
2072 /* This is non-static so that plugins can use it. */
2075 pass_fini_dump_file (struct opt_pass
*pass
)
2077 timevar_push (TV_DUMP
);
2079 /* Flush and close dump file. */
2082 free (CONST_CAST (char *, dump_file_name
));
2083 dump_file_name
= NULL
;
2086 dump_finish (pass
->static_pass_number
);
2087 timevar_pop (TV_DUMP
);
2090 /* After executing the pass, apply expected changes to the function
2094 update_properties_after_pass (void *data
)
2096 struct opt_pass
*pass
= (struct opt_pass
*) data
;
2097 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
2098 & ~pass
->properties_destroyed
;
2101 /* Execute summary generation for all of the passes in IPA_PASS. */
2104 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
2108 struct opt_pass
*pass
= ipa_pass
;
2110 /* Execute all of the IPA_PASSes in the list. */
2111 if (ipa_pass
->type
== IPA_PASS
2112 && ((!pass
->has_gate
) || pass
->gate ())
2113 && ipa_pass
->generate_summary
)
2115 pass_init_dump_file (pass
);
2117 /* If a timevar is present, start it. */
2119 timevar_push (pass
->tv_id
);
2121 ipa_pass
->generate_summary ();
2125 timevar_pop (pass
->tv_id
);
2127 pass_fini_dump_file (pass
);
2129 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->next
;
2133 /* Execute IPA_PASS function transform on NODE. */
2136 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2137 struct ipa_opt_pass_d
*ipa_pass
)
2139 struct opt_pass
*pass
= ipa_pass
;
2140 unsigned int todo_after
= 0;
2142 current_pass
= pass
;
2143 if (!ipa_pass
->function_transform
)
2146 /* Note that the folders should only create gimple expressions.
2147 This is a hack until the new folder is ready. */
2148 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2150 pass_init_dump_file (pass
);
2152 /* Run pre-pass verification. */
2153 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2155 /* If a timevar is present, start it. */
2156 if (pass
->tv_id
!= TV_NONE
)
2157 timevar_push (pass
->tv_id
);
2160 todo_after
= ipa_pass
->function_transform (node
);
2163 if (pass
->tv_id
!= TV_NONE
)
2164 timevar_pop (pass
->tv_id
);
2166 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2167 check_profile_consistency (pass
->static_pass_number
, 0, true);
2169 /* Run post-pass cleanup and verification. */
2170 execute_todo (todo_after
);
2171 verify_interpass_invariants ();
2172 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2173 check_profile_consistency (pass
->static_pass_number
, 1, true);
2175 do_per_function (execute_function_dump
, NULL
);
2176 pass_fini_dump_file (pass
);
2178 current_pass
= NULL
;
2180 /* Signal this is a suitable GC collection point. */
2181 if (!(todo_after
& TODO_do_not_ggc_collect
))
2185 /* For the current function, execute all ipa transforms. */
2188 execute_all_ipa_transforms (void)
2190 struct cgraph_node
*node
;
2193 node
= cgraph_get_node (current_function_decl
);
2195 if (node
->ipa_transforms_to_apply
.exists ())
2199 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2200 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2201 node
->ipa_transforms_to_apply
.release ();
2205 /* Callback for do_per_function to apply all IPA transforms. */
2208 apply_ipa_transforms (void *data
)
2210 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2211 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2213 *(bool *)data
= true;
2214 execute_all_ipa_transforms();
2215 rebuild_cgraph_edges ();
2219 /* Check if PASS is explicitly disabled or enabled and return
2220 the gate status. FUNC is the function to be processed, and
2221 GATE_STATUS is the gate status determined by pass manager by
2225 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2227 bool explicitly_enabled
= false;
2228 bool explicitly_disabled
= false;
2231 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2232 enabled_pass_uid_range_tab
);
2234 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2235 disabled_pass_uid_range_tab
);
2237 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2246 execute_one_pass (struct opt_pass
*pass
)
2248 unsigned int todo_after
= 0;
2252 /* IPA passes are executed on whole program, so cfun should be NULL.
2253 Other passes need function context set. */
2254 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2255 gcc_assert (!cfun
&& !current_function_decl
);
2257 gcc_assert (cfun
&& current_function_decl
);
2259 current_pass
= pass
;
2261 /* Check whether gate check should be avoided.
2262 User controls the value of the gate through the parameter "gate_status". */
2263 gate_status
= pass
->has_gate
? pass
->gate() : true;
2264 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2266 /* Override gate with plugin. */
2267 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2271 /* Run so passes selectively disabling themselves on a given function
2272 are not miscounted. */
2273 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2275 check_profile_consistency (pass
->static_pass_number
, 0, false);
2276 check_profile_consistency (pass
->static_pass_number
, 1, false);
2278 current_pass
= NULL
;
2282 /* Pass execution event trigger: useful to identify passes being
2284 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2286 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2287 Apply all trnasforms first. */
2288 if (pass
->type
== SIMPLE_IPA_PASS
)
2290 bool applied
= false;
2291 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2293 symtab_remove_unreachable_nodes (true, dump_file
);
2294 /* Restore current_pass. */
2295 current_pass
= pass
;
2298 if (!quiet_flag
&& !cfun
)
2299 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2301 /* Note that the folders should only create gimple expressions.
2302 This is a hack until the new folder is ready. */
2303 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2305 pass_init_dump_file (pass
);
2307 /* Run pre-pass verification. */
2308 execute_todo (pass
->todo_flags_start
);
2310 #ifdef ENABLE_CHECKING
2311 do_per_function (verify_curr_properties
,
2312 (void *)(size_t)pass
->properties_required
);
2315 /* If a timevar is present, start it. */
2316 if (pass
->tv_id
!= TV_NONE
)
2317 timevar_push (pass
->tv_id
);
2320 if (pass
->has_execute
)
2322 todo_after
= pass
->execute ();
2323 do_per_function (clear_last_verified
, NULL
);
2327 if (pass
->tv_id
!= TV_NONE
)
2328 timevar_pop (pass
->tv_id
);
2330 do_per_function (update_properties_after_pass
, pass
);
2332 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2333 check_profile_consistency (pass
->static_pass_number
, 0, true);
2335 /* Run post-pass cleanup and verification. */
2336 execute_todo (todo_after
| pass
->todo_flags_finish
);
2337 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2338 check_profile_consistency (pass
->static_pass_number
, 1, true);
2340 verify_interpass_invariants ();
2341 do_per_function (execute_function_dump
, NULL
);
2342 if (pass
->type
== IPA_PASS
)
2344 struct cgraph_node
*node
;
2345 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2346 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2349 if (!current_function_decl
)
2350 cgraph_process_new_functions ();
2352 pass_fini_dump_file (pass
);
2354 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2355 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2356 || pass
->type
!= RTL_PASS
);
2358 current_pass
= NULL
;
2360 /* Signal this is a suitable GC collection point. */
2361 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2368 execute_pass_list (struct opt_pass
*pass
)
2372 gcc_assert (pass
->type
== GIMPLE_PASS
2373 || pass
->type
== RTL_PASS
);
2374 if (execute_one_pass (pass
) && pass
->sub
)
2375 execute_pass_list (pass
->sub
);
2381 /* Same as execute_pass_list but assume that subpasses of IPA passes
2382 are local passes. If SET is not NULL, write out summaries of only
2383 those node in SET. */
2386 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2390 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2391 gcc_assert (!current_function_decl
);
2393 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2394 if (pass
->type
== IPA_PASS
2395 && ipa_pass
->write_summary
2396 && ((!pass
->has_gate
) || pass
->gate ()))
2398 /* If a timevar is present, start it. */
2400 timevar_push (pass
->tv_id
);
2402 pass_init_dump_file (pass
);
2404 ipa_pass
->write_summary ();
2406 pass_fini_dump_file (pass
);
2408 /* If a timevar is present, start it. */
2410 timevar_pop (pass
->tv_id
);
2413 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2414 ipa_write_summaries_2 (pass
->sub
, state
);
2420 /* Helper function of ipa_write_summaries. Creates and destroys the
2421 decl state and calls ipa_write_summaries_2 for all passes that have
2422 summaries. SET is the set of nodes to be written. */
2425 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2427 pass_manager
*passes
= g
->get_passes ();
2428 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2429 state
->symtab_node_encoder
= encoder
;
2431 lto_push_out_decl_state (state
);
2433 gcc_assert (!flag_wpa
);
2434 ipa_write_summaries_2 (passes
->all_regular_ipa_passes
, state
);
2435 ipa_write_summaries_2 (passes
->all_lto_gen_passes
, state
);
2437 gcc_assert (lto_get_out_decl_state () == state
);
2438 lto_pop_out_decl_state ();
2439 lto_delete_out_decl_state (state
);
2442 /* Write out summaries for all the nodes in the callgraph. */
2445 ipa_write_summaries (void)
2447 lto_symtab_encoder_t encoder
;
2449 struct varpool_node
*vnode
;
2450 struct cgraph_node
*node
;
2451 struct cgraph_node
**order
;
2453 if (!flag_generate_lto
|| seen_error ())
2456 encoder
= lto_symtab_encoder_new (false);
2458 /* Create the callgraph set in the same order used in
2459 cgraph_expand_all_functions. This mostly facilitates debugging,
2460 since it causes the gimple file to be processed in the same order
2461 as the source code. */
2462 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2463 order_pos
= ipa_reverse_postorder (order
);
2464 gcc_assert (order_pos
== cgraph_n_nodes
);
2466 for (i
= order_pos
- 1; i
>= 0; i
--)
2468 struct cgraph_node
*node
= order
[i
];
2470 if (cgraph_function_with_gimple_body_p (node
))
2472 /* When streaming out references to statements as part of some IPA
2473 pass summary, the statements need to have uids assigned and the
2474 following does that for all the IPA passes here. Naturally, this
2475 ordering then matches the one IPA-passes get in their stmt_fixup
2478 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2479 renumber_gimple_stmt_uids ();
2482 if (node
->symbol
.definition
)
2483 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2486 FOR_EACH_DEFINED_FUNCTION (node
)
2487 if (node
->symbol
.alias
)
2488 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2489 FOR_EACH_DEFINED_VARIABLE (vnode
)
2490 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2492 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2497 /* Same as execute_pass_list but assume that subpasses of IPA passes
2498 are local passes. If SET is not NULL, write out optimization summaries of
2499 only those node in SET. */
2502 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2506 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2507 gcc_assert (!current_function_decl
);
2509 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2510 if (pass
->type
== IPA_PASS
2511 && ipa_pass
->write_optimization_summary
2512 && ((!pass
->has_gate
) || pass
->gate ()))
2514 /* If a timevar is present, start it. */
2516 timevar_push (pass
->tv_id
);
2518 pass_init_dump_file (pass
);
2520 ipa_pass
->write_optimization_summary ();
2522 pass_fini_dump_file (pass
);
2524 /* If a timevar is present, start it. */
2526 timevar_pop (pass
->tv_id
);
2529 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2530 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2536 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2537 NULL, write out all summaries of all nodes. */
2540 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2542 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2543 lto_symtab_encoder_iterator lsei
;
2544 state
->symtab_node_encoder
= encoder
;
2546 lto_push_out_decl_state (state
);
2547 for (lsei
= lsei_start_function_in_partition (encoder
);
2548 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2550 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2551 /* When streaming out references to statements as part of some IPA
2552 pass summary, the statements need to have uids assigned.
2554 For functions newly born at WPA stage we need to initialize
2556 if (node
->symbol
.definition
2557 && gimple_has_body_p (node
->symbol
.decl
))
2559 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2560 renumber_gimple_stmt_uids ();
2565 gcc_assert (flag_wpa
);
2566 pass_manager
*passes
= g
->get_passes ();
2567 ipa_write_optimization_summaries_1 (passes
->all_regular_ipa_passes
, state
);
2568 ipa_write_optimization_summaries_1 (passes
->all_lto_gen_passes
, state
);
2570 gcc_assert (lto_get_out_decl_state () == state
);
2571 lto_pop_out_decl_state ();
2572 lto_delete_out_decl_state (state
);
2575 /* Same as execute_pass_list but assume that subpasses of IPA passes
2576 are local passes. */
2579 ipa_read_summaries_1 (struct opt_pass
*pass
)
2583 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2585 gcc_assert (!current_function_decl
);
2587 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2589 if ((!pass
->has_gate
) || pass
->gate ())
2591 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2593 /* If a timevar is present, start it. */
2595 timevar_push (pass
->tv_id
);
2597 pass_init_dump_file (pass
);
2599 ipa_pass
->read_summary ();
2601 pass_fini_dump_file (pass
);
2605 timevar_pop (pass
->tv_id
);
2608 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2609 ipa_read_summaries_1 (pass
->sub
);
2616 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2619 ipa_read_summaries (void)
2621 pass_manager
*passes
= g
->get_passes ();
2622 ipa_read_summaries_1 (passes
->all_regular_ipa_passes
);
2623 ipa_read_summaries_1 (passes
->all_lto_gen_passes
);
2626 /* Same as execute_pass_list but assume that subpasses of IPA passes
2627 are local passes. */
2630 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2634 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2636 gcc_assert (!current_function_decl
);
2638 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2640 if ((!pass
->has_gate
) || pass
->gate ())
2642 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2644 /* If a timevar is present, start it. */
2646 timevar_push (pass
->tv_id
);
2648 pass_init_dump_file (pass
);
2650 ipa_pass
->read_optimization_summary ();
2652 pass_fini_dump_file (pass
);
2656 timevar_pop (pass
->tv_id
);
2659 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2660 ipa_read_optimization_summaries_1 (pass
->sub
);
2666 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2669 ipa_read_optimization_summaries (void)
2671 pass_manager
*passes
= g
->get_passes ();
2672 ipa_read_optimization_summaries_1 (passes
->all_regular_ipa_passes
);
2673 ipa_read_optimization_summaries_1 (passes
->all_lto_gen_passes
);
2676 /* Same as execute_pass_list but assume that subpasses of IPA passes
2677 are local passes. */
2679 execute_ipa_pass_list (struct opt_pass
*pass
)
2683 gcc_assert (!current_function_decl
);
2685 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2686 if (execute_one_pass (pass
) && pass
->sub
)
2688 if (pass
->sub
->type
== GIMPLE_PASS
)
2690 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2691 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2693 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2695 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2696 || pass
->sub
->type
== IPA_PASS
)
2697 execute_ipa_pass_list (pass
->sub
);
2701 gcc_assert (!current_function_decl
);
2702 cgraph_process_new_functions ();
2708 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2711 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2712 struct cgraph_node
*node
, gimple
*stmts
)
2716 /* Execute all of the IPA_PASSes in the list. */
2717 if (pass
->type
== IPA_PASS
2718 && ((!pass
->has_gate
) || pass
->gate ()))
2720 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2722 if (ipa_pass
->stmt_fixup
)
2724 pass_init_dump_file (pass
);
2725 /* If a timevar is present, start it. */
2727 timevar_push (pass
->tv_id
);
2729 ipa_pass
->stmt_fixup (node
, stmts
);
2733 timevar_pop (pass
->tv_id
);
2734 pass_fini_dump_file (pass
);
2737 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2743 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2746 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2748 pass_manager
*passes
= g
->get_passes ();
2749 execute_ipa_stmt_fixups (passes
->all_regular_ipa_passes
, node
, stmts
);
2753 extern void debug_properties (unsigned int);
2754 extern void dump_properties (FILE *, unsigned int);
2757 dump_properties (FILE *dump
, unsigned int props
)
2759 fprintf (dump
, "Properties:\n");
2760 if (props
& PROP_gimple_any
)
2761 fprintf (dump
, "PROP_gimple_any\n");
2762 if (props
& PROP_gimple_lcf
)
2763 fprintf (dump
, "PROP_gimple_lcf\n");
2764 if (props
& PROP_gimple_leh
)
2765 fprintf (dump
, "PROP_gimple_leh\n");
2766 if (props
& PROP_cfg
)
2767 fprintf (dump
, "PROP_cfg\n");
2768 if (props
& PROP_ssa
)
2769 fprintf (dump
, "PROP_ssa\n");
2770 if (props
& PROP_no_crit_edges
)
2771 fprintf (dump
, "PROP_no_crit_edges\n");
2772 if (props
& PROP_rtl
)
2773 fprintf (dump
, "PROP_rtl\n");
2774 if (props
& PROP_gimple_lomp
)
2775 fprintf (dump
, "PROP_gimple_lomp\n");
2776 if (props
& PROP_gimple_lcx
)
2777 fprintf (dump
, "PROP_gimple_lcx\n");
2778 if (props
& PROP_gimple_lvec
)
2779 fprintf (dump
, "PROP_gimple_lvec\n");
2780 if (props
& PROP_cfglayout
)
2781 fprintf (dump
, "PROP_cfglayout\n");
2785 debug_properties (unsigned int props
)
2787 dump_properties (stderr
, props
);
2790 /* Called by local passes to see if function is called by already processed nodes.
2791 Because we process nodes in topological order, this means that function is
2792 in recursive cycle or we introduced new direct calls. */
2794 function_called_by_processed_nodes_p (void)
2796 struct cgraph_edge
*e
;
2797 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2801 if (e
->caller
->symbol
.decl
== current_function_decl
)
2803 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2805 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2807 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2812 fprintf (dump_file
, "Already processed call to:\n");
2813 dump_cgraph_node (dump_file
, e
->caller
);
2818 #include "gt-passes.h"