1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
29 #include "coretypes.h"
37 #include "insn-attr.h"
38 #include "insn-config.h"
39 #include "insn-flags.h"
40 #include "hard-reg-set.h"
47 #include "basic-block.h"
52 #include "diagnostic-core.h"
57 #include "langhooks.h"
59 #include "hosthooks.h"
63 #include "value-prof.h"
64 #include "tree-inline.h"
65 #include "tree-flow.h"
66 #include "tree-pass.h"
67 #include "tree-dump.h"
70 #include "lto-streamer.h"
72 #include "ipa-utils.h"
73 #include "tree-pretty-print.h" /* for dump_function_header */
75 /* This is used for debugging. It allows the current pass to printed
76 from anywhere in compilation.
77 The variable current_pass is also used for statistics and plugins. */
78 struct opt_pass
*current_pass
;
80 static void register_pass_name (struct opt_pass
*, const char *);
82 /* Call from anywhere to find out what pass this is. Useful for
83 printing out debugging information deep inside an service
86 print_current_pass (FILE *file
)
89 fprintf (file
, "current pass = %s (%d)\n",
90 current_pass
->name
, current_pass
->static_pass_number
);
92 fprintf (file
, "no current pass.\n");
96 /* Call from the debugger to get the current pass name. */
100 print_current_pass (stderr
);
105 /* Global variables used to communicate with passes. */
107 bool first_pass_instance
;
110 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
113 This does nothing for local (non-static) variables, unless the
114 variable is a register variable with DECL_ASSEMBLER_NAME set. In
115 that case, or if the variable is not an automatic, it sets up the
116 RTL and outputs any assembler code (label definition, storage
117 allocation and initialization).
119 DECL is the declaration. TOP_LEVEL is nonzero
120 if this declaration is not within a function. */
123 rest_of_decl_compilation (tree decl
,
127 /* We deferred calling assemble_alias so that we could collect
128 other attributes such as visibility. Emit the alias now. */
132 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
135 alias
= TREE_VALUE (TREE_VALUE (alias
));
136 alias
= get_identifier (TREE_STRING_POINTER (alias
));
137 /* A quirk of the initial implementation of aliases required that the
138 user add "extern" to all of them. Which is silly, but now
139 historical. Do note that the symbol is in fact locally defined. */
140 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
141 DECL_EXTERNAL (decl
) = 0;
142 assemble_alias (decl
, alias
);
146 /* Can't defer this, because it needs to happen before any
147 later function definitions are processed. */
148 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
149 make_decl_rtl (decl
);
151 /* Forward declarations for nested functions are not "external",
152 but we need to treat them as if they were. */
153 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
154 || TREE_CODE (decl
) == FUNCTION_DECL
)
156 timevar_push (TV_VARCONST
);
158 /* Don't output anything when a tentative file-scope definition
159 is seen. But at end of compilation, do output code for them.
161 We do output all variables and rely on
162 callgraph code to defer them except for forward declarations
163 (see gcc.c-torture/compile/920624-1.c) */
165 || !DECL_DEFER_OUTPUT (decl
)
166 || DECL_INITIAL (decl
))
167 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
168 && !DECL_EXTERNAL (decl
))
170 /* When reading LTO unit, we also read varpool, so do not
172 if (in_lto_p
&& !at_end
)
174 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
175 varpool_finalize_decl (decl
);
178 #ifdef ASM_FINISH_DECLARE_OBJECT
179 if (decl
== last_assemble_variable_decl
)
181 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
186 timevar_pop (TV_VARCONST
);
188 else if (TREE_CODE (decl
) == TYPE_DECL
189 /* Like in rest_of_type_compilation, avoid confusing the debug
190 information machinery when there are errors. */
193 timevar_push (TV_SYMOUT
);
194 debug_hooks
->type_decl (decl
, !top_level
);
195 timevar_pop (TV_SYMOUT
);
198 /* Let cgraph know about the existence of variables. */
199 if (in_lto_p
&& !at_end
)
201 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
202 && TREE_STATIC (decl
))
203 varpool_node_for_decl (decl
);
206 /* Called after finishing a record, union or enumeral type. */
209 rest_of_type_compilation (tree type
, int toplev
)
211 /* Avoid confusing the debug information machinery when there are
216 timevar_push (TV_SYMOUT
);
217 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
218 timevar_pop (TV_SYMOUT
);
224 finish_optimization_passes (void)
227 struct dump_file_info
*dfi
;
230 timevar_push (TV_DUMP
);
231 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
233 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
235 dump_finish (pass_profile
.pass
.static_pass_number
);
240 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
241 print_combine_total_stats ();
242 dump_finish (pass_profile
.pass
.static_pass_number
);
245 /* Do whatever is necessary to finish printing the graphs. */
246 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
247 if (dump_initialized_p (i
)
248 && (dfi
->pflags
& TDF_GRAPH
) != 0
249 && (name
= get_dump_file_name (i
)) != NULL
)
251 finish_graph_dump_file (name
);
255 timevar_pop (TV_DUMP
);
259 execute_all_early_local_passes (void)
261 /* Once this pass (and its sub-passes) are complete, all functions
262 will be in SSA form. Technically this state change is happening
263 a tad early, since the sub-passes have not yet run, but since
264 none of the sub-passes are IPA passes and do not create new
265 functions, this is ok. We're setting this value for the benefit
266 of IPA passes that follow. */
267 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
268 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
272 /* Gate: execute, or not, all of the non-trivial optimizations. */
275 gate_all_early_local_passes (void)
277 /* Don't bother doing anything if the program has errors. */
278 return (!seen_error () && !in_lto_p
);
281 struct simple_ipa_opt_pass pass_early_local_passes
=
285 "early_local_cleanups", /* name */
286 OPTGROUP_NONE
, /* optinfo_flags */
287 gate_all_early_local_passes
, /* gate */
288 execute_all_early_local_passes
, /* execute */
291 0, /* static_pass_number */
292 TV_EARLY_LOCAL
, /* tv_id */
293 0, /* properties_required */
294 0, /* properties_provided */
295 0, /* properties_destroyed */
296 0, /* todo_flags_start */
297 TODO_remove_functions
/* todo_flags_finish */
301 /* Gate: execute, or not, all of the non-trivial optimizations. */
304 gate_all_early_optimizations (void)
306 return (optimize
>= 1
307 /* Don't bother doing anything if the program has errors. */
311 static struct gimple_opt_pass pass_all_early_optimizations
=
315 "early_optimizations", /* name */
316 OPTGROUP_NONE
, /* optinfo_flags */
317 gate_all_early_optimizations
, /* gate */
321 0, /* static_pass_number */
323 0, /* properties_required */
324 0, /* properties_provided */
325 0, /* properties_destroyed */
326 0, /* todo_flags_start */
327 0 /* todo_flags_finish */
331 /* Gate: execute, or not, all of the non-trivial optimizations. */
334 gate_all_optimizations (void)
336 return optimize
>= 1 && !optimize_debug
;
339 static struct gimple_opt_pass pass_all_optimizations
=
343 "*all_optimizations", /* name */
344 OPTGROUP_NONE
, /* optinfo_flags */
345 gate_all_optimizations
, /* gate */
349 0, /* static_pass_number */
350 TV_OPTIMIZE
, /* tv_id */
351 0, /* properties_required */
352 0, /* properties_provided */
353 0, /* properties_destroyed */
354 0, /* todo_flags_start */
355 0 /* todo_flags_finish */
359 /* Gate: execute, or not, all of the non-trivial optimizations. */
362 gate_all_optimizations_g (void)
364 return optimize
>= 1 && optimize_debug
;
367 static struct gimple_opt_pass pass_all_optimizations_g
=
371 "*all_optimizations_g", /* name */
372 OPTGROUP_NONE
, /* optinfo_flags */
373 gate_all_optimizations_g
, /* gate */
377 0, /* static_pass_number */
378 TV_OPTIMIZE
, /* tv_id */
379 0, /* properties_required */
380 0, /* properties_provided */
381 0, /* properties_destroyed */
382 0, /* todo_flags_start */
383 0 /* todo_flags_finish */
388 gate_rest_of_compilation (void)
390 /* Early return if there were errors. We can run afoul of our
391 consistency checks, and there's not really much point in fixing them. */
392 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
395 static struct rtl_opt_pass pass_rest_of_compilation
=
399 "*rest_of_compilation", /* name */
400 OPTGROUP_NONE
, /* optinfo_flags */
401 gate_rest_of_compilation
, /* gate */
405 0, /* static_pass_number */
406 TV_REST_OF_COMPILATION
, /* tv_id */
407 PROP_rtl
, /* properties_required */
408 0, /* properties_provided */
409 0, /* properties_destroyed */
410 0, /* todo_flags_start */
411 TODO_ggc_collect
/* todo_flags_finish */
416 gate_postreload (void)
418 return reload_completed
;
421 static struct rtl_opt_pass pass_postreload
=
425 "*all-postreload", /* name */
426 OPTGROUP_NONE
, /* optinfo_flags */
427 gate_postreload
, /* gate */
431 0, /* static_pass_number */
432 TV_POSTRELOAD
, /* tv_id */
433 PROP_rtl
, /* properties_required */
434 0, /* properties_provided */
435 0, /* properties_destroyed */
436 0, /* todo_flags_start */
437 TODO_ggc_collect
| TODO_verify_rtl_sharing
/* todo_flags_finish */
443 /* The root of the compilation pass tree, once constructed. */
444 struct opt_pass
*all_passes
, *all_small_ipa_passes
, *all_lowering_passes
,
445 *all_regular_ipa_passes
, *all_late_ipa_passes
, *all_lto_gen_passes
;
447 /* This is used by plugins, and should also be used in register_pass. */
448 #define DEF_PASS_LIST(LIST) &LIST,
449 struct opt_pass
**gcc_pass_lists
[] = { GCC_PASS_LISTS NULL
};
452 /* A map from static pass id to optimization pass. */
453 struct opt_pass
**passes_by_id
;
454 int passes_by_id_size
;
456 /* Set the static pass number of pass PASS to ID and record that
457 in the mapping from static pass number to pass. */
460 set_pass_for_id (int id
, struct opt_pass
*pass
)
462 pass
->static_pass_number
= id
;
463 if (passes_by_id_size
<= id
)
465 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
466 memset (passes_by_id
+ passes_by_id_size
, 0,
467 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
468 passes_by_id_size
= id
+ 1;
470 passes_by_id
[id
] = pass
;
473 /* Return the pass with the static pass number ID. */
476 get_pass_for_id (int id
)
478 if (id
>= passes_by_id_size
)
480 return passes_by_id
[id
];
483 /* Iterate over the pass tree allocating dump file numbers. We want
484 to do this depth first, and independent of whether the pass is
488 register_one_dump_file (struct opt_pass
*pass
)
490 char *dot_name
, *flag_name
, *glob_name
;
491 const char *name
, *full_name
, *prefix
;
494 int optgroup_flags
= OPTGROUP_NONE
;
496 /* See below in next_pass_1. */
498 if (pass
->static_pass_number
!= -1)
499 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
500 ? 1 : pass
->static_pass_number
));
502 /* The name is both used to identify the pass for the purposes of plugins,
503 and to specify dump file name and option.
504 The latter two might want something short which is not quite unique; for
505 that reason, we may have a disambiguating prefix, followed by a space
506 to mark the start of the following dump file name / option string. */
507 name
= strchr (pass
->name
, ' ');
508 name
= name
? name
+ 1 : pass
->name
;
509 dot_name
= concat (".", name
, num
, NULL
);
510 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
514 optgroup_flags
|= OPTGROUP_IPA
;
516 else if (pass
->type
== GIMPLE_PASS
)
527 flag_name
= concat (prefix
, name
, num
, NULL
);
528 glob_name
= concat (prefix
, name
, NULL
);
529 optgroup_flags
|= pass
->optinfo_flags
;
530 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
, optgroup_flags
);
531 set_pass_for_id (id
, pass
);
532 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
533 register_pass_name (pass
, full_name
);
534 free (CONST_CAST (char *, full_name
));
537 /* Recursive worker function for register_dump_files. */
540 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
544 int new_properties
= (properties
| pass
->properties_provided
)
545 & ~pass
->properties_destroyed
;
547 if (pass
->name
&& pass
->name
[0] != '*')
548 register_one_dump_file (pass
);
551 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
553 /* If we have a gate, combine the properties that we could have with
554 and without the pass being examined. */
556 properties
&= new_properties
;
558 properties
= new_properties
;
567 /* Register the dump files for the pipeline starting at PASS.
568 PROPERTIES reflects the properties that are guaranteed to be available at
569 the beginning of the pipeline. */
572 register_dump_files (struct opt_pass
*pass
,int properties
)
574 pass
->properties_required
|= properties
;
575 register_dump_files_1 (pass
, properties
);
580 const char* unique_name
;
581 struct opt_pass
*pass
;
584 /* Pass registry hash function. */
587 passr_hash (const void *p
)
589 const struct pass_registry
*const s
= (const struct pass_registry
*const) p
;
590 return htab_hash_string (s
->unique_name
);
593 /* Hash equal function */
596 passr_eq (const void *p1
, const void *p2
)
598 const struct pass_registry
*const s1
= (const struct pass_registry
*const) p1
;
599 const struct pass_registry
*const s2
= (const struct pass_registry
*const) p2
;
601 return !strcmp (s1
->unique_name
, s2
->unique_name
);
604 static htab_t name_to_pass_map
= NULL
;
606 /* Register PASS with NAME. */
609 register_pass_name (struct opt_pass
*pass
, const char *name
)
611 struct pass_registry
**slot
;
612 struct pass_registry pr
;
614 if (!name_to_pass_map
)
615 name_to_pass_map
= htab_create (256, passr_hash
, passr_eq
, NULL
);
617 pr
.unique_name
= name
;
618 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
, &pr
, INSERT
);
621 struct pass_registry
*new_pr
;
623 new_pr
= XCNEW (struct pass_registry
);
624 new_pr
->unique_name
= xstrdup (name
);
629 return; /* Ignore plugin passes. */
632 /* Map from pass id to canonicalized pass name. */
634 typedef const char *char_ptr
;
635 static vec
<char_ptr
> pass_tab
= vNULL
;
637 /* Callback function for traversing NAME_TO_PASS_MAP. */
640 pass_traverse (void **slot
, void *data ATTRIBUTE_UNUSED
)
642 struct pass_registry
**p
= (struct pass_registry
**)slot
;
643 struct opt_pass
*pass
= (*p
)->pass
;
645 gcc_assert (pass
->static_pass_number
> 0);
646 gcc_assert (pass_tab
.exists ());
648 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
653 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
654 table for dumping purpose. */
657 create_pass_tab (void)
659 if (!flag_dump_passes
)
662 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
663 htab_traverse (name_to_pass_map
, pass_traverse
, NULL
);
666 static bool override_gate_status (struct opt_pass
*, tree
, bool);
668 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
669 is turned on or not. */
672 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
674 int indent
= 3 * pass_indent
;
676 bool is_on
, is_really_on
;
678 is_on
= (pass
->gate
== NULL
) ? true : pass
->gate();
679 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
681 if (pass
->static_pass_number
<= 0)
684 pn
= pass_tab
[pass
->static_pass_number
];
686 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
687 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
688 is_on
? " ON" : " OFF",
689 ((!is_on
) == (!is_really_on
) ? ""
690 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
693 /* Dump pass list PASS with indentation INDENT. */
696 dump_pass_list (struct opt_pass
*pass
, int indent
)
700 dump_one_pass (pass
, indent
);
702 dump_pass_list (pass
->sub
, indent
+ 1);
708 /* Dump all optimization passes. */
713 struct cgraph_node
*n
, *node
= NULL
;
717 FOR_EACH_DEFINED_FUNCTION (n
)
718 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
727 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
729 dump_pass_list (all_lowering_passes
, 1);
730 dump_pass_list (all_small_ipa_passes
, 1);
731 dump_pass_list (all_regular_ipa_passes
, 1);
732 dump_pass_list (all_lto_gen_passes
, 1);
733 dump_pass_list (all_late_ipa_passes
, 1);
734 dump_pass_list (all_passes
, 1);
740 /* Returns the pass with NAME. */
742 static struct opt_pass
*
743 get_pass_by_name (const char *name
)
745 struct pass_registry
**slot
, pr
;
747 pr
.unique_name
= name
;
748 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
,
754 return (*slot
)->pass
;
758 /* Range [start, last]. */
764 const char *assem_name
;
765 struct uid_range
*next
;
768 typedef struct uid_range
*uid_range_p
;
771 static vec
<uid_range_p
>
772 enabled_pass_uid_range_tab
= vNULL
;
773 static vec
<uid_range_p
>
774 disabled_pass_uid_range_tab
= vNULL
;
777 /* Parse option string for -fdisable- and -fenable-
778 The syntax of the options:
781 -fdisable-<pass_name>
783 -fenable-<pass_name>=s1:e1,s2:e2,...
784 -fdisable-<pass_name>=s1:e1,s2:e2,...
788 enable_disable_pass (const char *arg
, bool is_enable
)
790 struct opt_pass
*pass
;
791 char *range_str
, *phase_name
;
792 char *argstr
= xstrdup (arg
);
793 vec
<uid_range_p
> *tab
= 0;
795 range_str
= strchr (argstr
,'=');
806 error ("unrecognized option -fenable");
808 error ("unrecognized option -fdisable");
812 pass
= get_pass_by_name (phase_name
);
813 if (!pass
|| pass
->static_pass_number
== -1)
816 error ("unknown pass %s specified in -fenable", phase_name
);
818 error ("unknown pass %s specified in -fdisable", phase_name
);
824 tab
= &enabled_pass_uid_range_tab
;
826 tab
= &disabled_pass_uid_range_tab
;
828 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
829 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
834 uid_range_p new_range
= XCNEW (struct uid_range
);
836 new_range
->start
= 0;
837 new_range
->last
= (unsigned)-1;
839 slot
= (*tab
)[pass
->static_pass_number
];
840 new_range
->next
= slot
;
841 (*tab
)[pass
->static_pass_number
] = new_range
;
843 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
844 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
846 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
847 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
851 char *next_range
= NULL
;
852 char *one_range
= range_str
;
853 char *end_val
= NULL
;
858 uid_range_p new_range
;
859 char *invalid
= NULL
;
861 char *func_name
= NULL
;
863 next_range
= strchr (one_range
, ',');
870 end_val
= strchr (one_range
, ':');
876 start
= strtol (one_range
, &invalid
, 10);
877 if (*invalid
|| start
< 0)
879 if (end_val
|| (one_range
[0] >= '0'
880 && one_range
[0] <= '9'))
882 error ("Invalid range %s in option %s",
884 is_enable
? "-fenable" : "-fdisable");
888 func_name
= one_range
;
892 new_range
= XCNEW (struct uid_range
);
895 new_range
->start
= (unsigned) start
;
896 new_range
->last
= (unsigned) start
;
900 new_range
->start
= (unsigned) -1;
901 new_range
->last
= (unsigned) -1;
902 new_range
->assem_name
= xstrdup (func_name
);
907 long last
= strtol (end_val
, &invalid
, 10);
908 if (*invalid
|| last
< start
)
910 error ("Invalid range %s in option %s",
912 is_enable
? "-fenable" : "-fdisable");
916 new_range
= XCNEW (struct uid_range
);
917 new_range
->start
= (unsigned) start
;
918 new_range
->last
= (unsigned) last
;
921 slot
= (*tab
)[pass
->static_pass_number
];
922 new_range
->next
= slot
;
923 (*tab
)[pass
->static_pass_number
] = new_range
;
926 if (new_range
->assem_name
)
927 inform (UNKNOWN_LOCATION
,
928 "enable pass %s for function %s",
929 phase_name
, new_range
->assem_name
);
931 inform (UNKNOWN_LOCATION
,
932 "enable pass %s for functions in the range of [%u, %u]",
933 phase_name
, new_range
->start
, new_range
->last
);
937 if (new_range
->assem_name
)
938 inform (UNKNOWN_LOCATION
,
939 "disable pass %s for function %s",
940 phase_name
, new_range
->assem_name
);
942 inform (UNKNOWN_LOCATION
,
943 "disable pass %s for functions in the range of [%u, %u]",
944 phase_name
, new_range
->start
, new_range
->last
);
947 one_range
= next_range
;
948 } while (next_range
);
954 /* Enable pass specified by ARG. */
957 enable_pass (const char *arg
)
959 enable_disable_pass (arg
, true);
962 /* Disable pass specified by ARG. */
965 disable_pass (const char *arg
)
967 enable_disable_pass (arg
, false);
970 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
973 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
975 vec
<uid_range_p
> tab
)
977 uid_range_p slot
, range
;
979 const char *aname
= NULL
;
982 || (unsigned) pass
->static_pass_number
>= tab
.length ()
983 || pass
->static_pass_number
== -1)
986 slot
= tab
[pass
->static_pass_number
];
990 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
991 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
992 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
997 if ((unsigned) cgraph_uid
>= range
->start
998 && (unsigned) cgraph_uid
<= range
->last
)
1000 if (range
->assem_name
&& aname
1001 && !strcmp (range
->assem_name
, aname
))
1003 range
= range
->next
;
1009 /* Look at the static_pass_number and duplicate the pass
1010 if it is already added to a list. */
1012 static struct opt_pass
*
1013 make_pass_instance (struct opt_pass
*pass
, bool track_duplicates
)
1015 /* A nonzero static_pass_number indicates that the
1016 pass is already in the list. */
1017 if (pass
->static_pass_number
)
1019 struct opt_pass
*new_pass
;
1021 if (pass
->type
== GIMPLE_PASS
1022 || pass
->type
== RTL_PASS
1023 || pass
->type
== SIMPLE_IPA_PASS
)
1025 new_pass
= XNEW (struct opt_pass
);
1026 memcpy (new_pass
, pass
, sizeof (struct opt_pass
));
1028 else if (pass
->type
== IPA_PASS
)
1030 new_pass
= (struct opt_pass
*)XNEW (struct ipa_opt_pass_d
);
1031 memcpy (new_pass
, pass
, sizeof (struct ipa_opt_pass_d
));
1036 new_pass
->next
= NULL
;
1038 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1040 /* Indicate to register_dump_files that this pass has duplicates,
1041 and so it should rename the dump file. The first instance will
1042 be -1, and be number of duplicates = -static_pass_number - 1.
1043 Subsequent instances will be > 0 and just the duplicate number. */
1044 if ((pass
->name
&& pass
->name
[0] != '*') || track_duplicates
)
1046 pass
->static_pass_number
-= 1;
1047 new_pass
->static_pass_number
= -pass
->static_pass_number
;
1053 pass
->todo_flags_start
|= TODO_mark_first_instance
;
1054 pass
->static_pass_number
= -1;
1056 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, pass
);
1061 /* Add a pass to the pass list. Duplicate the pass if it's already
1064 static struct opt_pass
**
1065 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
)
1067 /* Every pass should have a name so that plugins can refer to them. */
1068 gcc_assert (pass
->name
!= NULL
);
1070 *list
= make_pass_instance (pass
, false);
1072 return &(*list
)->next
;
1075 /* List node for an inserted pass instance. We need to keep track of all
1076 the newly-added pass instances (with 'added_pass_nodes' defined below)
1077 so that we can register their dump files after pass-positioning is finished.
1078 Registering dumping files needs to be post-processed or the
1079 static_pass_number of the opt_pass object would be modified and mess up
1080 the dump file names of future pass instances to be added. */
1082 struct pass_list_node
1084 struct opt_pass
*pass
;
1085 struct pass_list_node
*next
;
1088 static struct pass_list_node
*added_pass_nodes
= NULL
;
1089 static struct pass_list_node
*prev_added_pass_node
;
1091 /* Insert the pass at the proper position. Return true if the pass
1092 is successfully added.
1094 NEW_PASS_INFO - new pass to be inserted
1095 PASS_LIST - root of the pass list to insert the new pass to */
1098 position_pass (struct register_pass_info
*new_pass_info
,
1099 struct opt_pass
**pass_list
)
1101 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1102 bool success
= false;
1104 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1106 /* Check if the current pass is of the same type as the new pass and
1107 matches the name and the instance number of the reference pass. */
1108 if (pass
->type
== new_pass_info
->pass
->type
1110 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1111 && ((new_pass_info
->ref_pass_instance_number
== 0)
1112 || (new_pass_info
->ref_pass_instance_number
==
1113 pass
->static_pass_number
)
1114 || (new_pass_info
->ref_pass_instance_number
== 1
1115 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1117 struct opt_pass
*new_pass
;
1118 struct pass_list_node
*new_pass_node
;
1120 new_pass
= make_pass_instance (new_pass_info
->pass
, true);
1122 /* Insert the new pass instance based on the positioning op. */
1123 switch (new_pass_info
->pos_op
)
1125 case PASS_POS_INSERT_AFTER
:
1126 new_pass
->next
= pass
->next
;
1127 pass
->next
= new_pass
;
1129 /* Skip newly inserted pass to avoid repeated
1130 insertions in the case where the new pass and the
1131 existing one have the same name. */
1134 case PASS_POS_INSERT_BEFORE
:
1135 new_pass
->next
= pass
;
1137 prev_pass
->next
= new_pass
;
1139 *pass_list
= new_pass
;
1141 case PASS_POS_REPLACE
:
1142 new_pass
->next
= pass
->next
;
1144 prev_pass
->next
= new_pass
;
1146 *pass_list
= new_pass
;
1147 new_pass
->sub
= pass
->sub
;
1148 new_pass
->tv_id
= pass
->tv_id
;
1152 error ("invalid pass positioning operation");
1156 /* Save the newly added pass (instance) in the added_pass_nodes
1157 list so that we can register its dump file later. Note that
1158 we cannot register the dump file now because doing so will modify
1159 the static_pass_number of the opt_pass object and therefore
1160 mess up the dump file name of future instances. */
1161 new_pass_node
= XCNEW (struct pass_list_node
);
1162 new_pass_node
->pass
= new_pass
;
1163 if (!added_pass_nodes
)
1164 added_pass_nodes
= new_pass_node
;
1166 prev_added_pass_node
->next
= new_pass_node
;
1167 prev_added_pass_node
= new_pass_node
;
1172 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1179 /* Hooks a new pass into the pass lists.
1181 PASS_INFO - pass information that specifies the opt_pass object,
1182 reference pass, instance number, and how to position
1186 register_pass (struct register_pass_info
*pass_info
)
1188 bool all_instances
, success
;
1190 /* The checks below could fail in buggy plugins. Existing GCC
1191 passes should never fail these checks, so we mention plugin in
1193 if (!pass_info
->pass
)
1194 fatal_error ("plugin cannot register a missing pass");
1196 if (!pass_info
->pass
->name
)
1197 fatal_error ("plugin cannot register an unnamed pass");
1199 if (!pass_info
->reference_pass_name
)
1201 ("plugin cannot register pass %qs without reference pass name",
1202 pass_info
->pass
->name
);
1204 /* Try to insert the new pass to the pass lists. We need to check
1205 all five lists as the reference pass could be in one (or all) of
1207 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1208 success
= position_pass (pass_info
, &all_lowering_passes
);
1209 if (!success
|| all_instances
)
1210 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1211 if (!success
|| all_instances
)
1212 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1213 if (!success
|| all_instances
)
1214 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1215 if (!success
|| all_instances
)
1216 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1217 if (!success
|| all_instances
)
1218 success
|= position_pass (pass_info
, &all_passes
);
1221 ("pass %qs not found but is referenced by new pass %qs",
1222 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1224 /* OK, we have successfully inserted the new pass. We need to register
1225 the dump files for the newly added pass and its duplicates (if any).
1226 Because the registration of plugin/backend passes happens after the
1227 command-line options are parsed, the options that specify single
1228 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1229 passes. Therefore we currently can only enable dumping of
1230 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1231 are specified. While doing so, we also delete the pass_list_node
1232 objects created during pass positioning. */
1233 while (added_pass_nodes
)
1235 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1236 enum tree_dump_index tdi
;
1237 register_one_dump_file (added_pass_nodes
->pass
);
1238 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1239 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1241 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1245 /* Check if dump-all flag is specified. */
1246 if (get_dump_file_info (tdi
)->pstate
)
1247 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1248 ->pstate
= get_dump_file_info (tdi
)->pstate
;
1249 XDELETE (added_pass_nodes
);
1250 added_pass_nodes
= next_node
;
1254 /* Construct the pass tree. The sequencing of passes is driven by
1255 the cgraph routines:
1257 finalize_compilation_unit ()
1258 for each node N in the cgraph
1259 cgraph_analyze_function (N)
1260 cgraph_lower_function (N) -> all_lowering_passes
1262 If we are optimizing, compile is then invoked:
1265 ipa_passes () -> all_small_ipa_passes
1266 -> Analysis of all_regular_ipa_passes
1267 * possible LTO streaming at copmilation time *
1268 -> Execution of all_regular_ipa_passes
1269 * possible LTO streaming at link time *
1270 -> all_late_ipa_passes
1271 expand_all_functions ()
1272 for each node N in the cgraph
1273 expand_function (N) -> Transformation of all_regular_ipa_passes
1278 init_optimization_passes (void)
1280 struct opt_pass
**p
;
1282 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1284 /* All passes needed to lower the function into shape optimizers can
1285 operate on. These passes are always run first on the function, but
1286 backend might produce already lowered functions that are not processed
1288 p
= &all_lowering_passes
;
1289 NEXT_PASS (pass_warn_unused_result
);
1290 NEXT_PASS (pass_diagnose_omp_blocks
);
1291 NEXT_PASS (pass_diagnose_tm_blocks
);
1292 NEXT_PASS (pass_mudflap_1
);
1293 NEXT_PASS (pass_lower_omp
);
1294 NEXT_PASS (pass_lower_cf
);
1295 NEXT_PASS (pass_lower_tm
);
1296 NEXT_PASS (pass_refactor_eh
);
1297 NEXT_PASS (pass_lower_eh
);
1298 NEXT_PASS (pass_build_cfg
);
1299 NEXT_PASS (pass_warn_function_return
);
1300 NEXT_PASS (pass_build_cgraph_edges
);
1303 /* Interprocedural optimization passes. */
1304 p
= &all_small_ipa_passes
;
1305 NEXT_PASS (pass_ipa_free_lang_data
);
1306 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
1307 NEXT_PASS (pass_early_local_passes
);
1309 struct opt_pass
**p
= &pass_early_local_passes
.pass
.sub
;
1310 NEXT_PASS (pass_fixup_cfg
);
1311 NEXT_PASS (pass_init_datastructures
);
1312 NEXT_PASS (pass_expand_omp
);
1314 NEXT_PASS (pass_build_ssa
);
1315 NEXT_PASS (pass_lower_vector
);
1316 NEXT_PASS (pass_early_warn_uninitialized
);
1317 NEXT_PASS (pass_rebuild_cgraph_edges
);
1318 NEXT_PASS (pass_inline_parameters
);
1319 NEXT_PASS (pass_early_inline
);
1320 NEXT_PASS (pass_all_early_optimizations
);
1322 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1323 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1324 NEXT_PASS (pass_rename_ssa_copies
);
1325 NEXT_PASS (pass_ccp
);
1326 /* After CCP we rewrite no longer addressed locals into SSA
1327 form if possible. */
1328 NEXT_PASS (pass_forwprop
);
1329 /* pass_build_ealias is a dummy pass that ensures that we
1330 execute TODO_rebuild_alias at this point. */
1331 NEXT_PASS (pass_build_ealias
);
1332 NEXT_PASS (pass_sra_early
);
1333 NEXT_PASS (pass_fre
);
1334 NEXT_PASS (pass_copy_prop
);
1335 NEXT_PASS (pass_merge_phi
);
1336 NEXT_PASS (pass_cd_dce
);
1337 NEXT_PASS (pass_early_ipa_sra
);
1338 NEXT_PASS (pass_tail_recursion
);
1339 NEXT_PASS (pass_convert_switch
);
1340 NEXT_PASS (pass_cleanup_eh
);
1341 NEXT_PASS (pass_profile
);
1342 NEXT_PASS (pass_local_pure_const
);
1343 /* Split functions creates parts that are not run through
1344 early optimizations again. It is thus good idea to do this
1346 NEXT_PASS (pass_split_functions
);
1348 NEXT_PASS (pass_release_ssa_names
);
1349 NEXT_PASS (pass_rebuild_cgraph_edges
);
1350 NEXT_PASS (pass_inline_parameters
);
1352 NEXT_PASS (pass_ipa_free_inline_summary
);
1353 NEXT_PASS (pass_ipa_tree_profile
);
1355 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1356 NEXT_PASS (pass_feedback_split_functions
);
1358 NEXT_PASS (pass_ipa_increase_alignment
);
1359 NEXT_PASS (pass_ipa_tm
);
1360 NEXT_PASS (pass_ipa_lower_emutls
);
1363 p
= &all_regular_ipa_passes
;
1364 NEXT_PASS (pass_ipa_whole_program_visibility
);
1365 NEXT_PASS (pass_ipa_profile
);
1366 NEXT_PASS (pass_ipa_cp
);
1367 NEXT_PASS (pass_ipa_cdtor_merge
);
1368 NEXT_PASS (pass_ipa_inline
);
1369 NEXT_PASS (pass_ipa_pure_const
);
1370 NEXT_PASS (pass_ipa_reference
);
1373 p
= &all_lto_gen_passes
;
1374 NEXT_PASS (pass_ipa_lto_gimple_out
);
1375 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1378 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1379 passes are executed after partitioning and thus see just parts of the
1381 p
= &all_late_ipa_passes
;
1382 NEXT_PASS (pass_ipa_pta
);
1385 /* These passes are run after IPA passes on every function that is being
1386 output to the assembler file. */
1388 NEXT_PASS (pass_fixup_cfg
);
1389 NEXT_PASS (pass_lower_eh_dispatch
);
1390 NEXT_PASS (pass_all_optimizations
);
1392 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1393 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1394 /* Initial scalar cleanups before alias computation.
1395 They ensure memory accesses are not indirect wherever possible. */
1396 NEXT_PASS (pass_strip_predict_hints
);
1397 NEXT_PASS (pass_rename_ssa_copies
);
1398 NEXT_PASS (pass_complete_unrolli
);
1399 NEXT_PASS (pass_ccp
);
1400 /* After CCP we rewrite no longer addressed locals into SSA
1401 form if possible. */
1402 NEXT_PASS (pass_forwprop
);
1403 /* pass_build_alias is a dummy pass that ensures that we
1404 execute TODO_rebuild_alias at this point. */
1405 NEXT_PASS (pass_build_alias
);
1406 NEXT_PASS (pass_return_slot
);
1407 NEXT_PASS (pass_phiprop
);
1408 NEXT_PASS (pass_fre
);
1409 NEXT_PASS (pass_copy_prop
);
1410 NEXT_PASS (pass_merge_phi
);
1411 NEXT_PASS (pass_vrp
);
1412 NEXT_PASS (pass_dce
);
1413 NEXT_PASS (pass_call_cdce
);
1414 NEXT_PASS (pass_cselim
);
1415 NEXT_PASS (pass_tree_ifcombine
);
1416 NEXT_PASS (pass_phiopt
);
1417 NEXT_PASS (pass_tail_recursion
);
1418 NEXT_PASS (pass_ch
);
1419 NEXT_PASS (pass_stdarg
);
1420 NEXT_PASS (pass_lower_complex
);
1421 NEXT_PASS (pass_sra
);
1422 NEXT_PASS (pass_rename_ssa_copies
);
1423 /* The dom pass will also resolve all __builtin_constant_p calls
1424 that are still there to 0. This has to be done after some
1425 propagations have already run, but before some more dead code
1426 is removed, and this place fits nicely. Remember this when
1427 trying to move or duplicate pass_dominator somewhere earlier. */
1428 NEXT_PASS (pass_dominator
);
1429 /* The only const/copy propagation opportunities left after
1430 DOM should be due to degenerate PHI nodes. So rather than
1431 run the full propagators, run a specialized pass which
1432 only examines PHIs to discover const/copy propagation
1434 NEXT_PASS (pass_phi_only_cprop
);
1435 NEXT_PASS (pass_dse
);
1436 NEXT_PASS (pass_reassoc
);
1437 NEXT_PASS (pass_dce
);
1438 NEXT_PASS (pass_forwprop
);
1439 NEXT_PASS (pass_phiopt
);
1440 NEXT_PASS (pass_object_sizes
);
1441 NEXT_PASS (pass_strlen
);
1442 NEXT_PASS (pass_ccp
);
1443 /* After CCP we rewrite no longer addressed locals into SSA
1444 form if possible. */
1445 NEXT_PASS (pass_copy_prop
);
1446 NEXT_PASS (pass_cse_sincos
);
1447 NEXT_PASS (pass_optimize_bswap
);
1448 NEXT_PASS (pass_split_crit_edges
);
1449 NEXT_PASS (pass_pre
);
1450 NEXT_PASS (pass_sink_code
);
1451 NEXT_PASS (pass_asan
);
1452 NEXT_PASS (pass_tsan
);
1453 NEXT_PASS (pass_tree_loop
);
1455 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1456 NEXT_PASS (pass_tree_loop_init
);
1457 NEXT_PASS (pass_lim
);
1458 NEXT_PASS (pass_copy_prop
);
1459 NEXT_PASS (pass_dce_loop
);
1460 NEXT_PASS (pass_tree_unswitch
);
1461 NEXT_PASS (pass_scev_cprop
);
1462 NEXT_PASS (pass_record_bounds
);
1463 NEXT_PASS (pass_check_data_deps
);
1464 NEXT_PASS (pass_loop_distribution
);
1465 NEXT_PASS (pass_copy_prop
);
1466 NEXT_PASS (pass_graphite
);
1468 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1469 NEXT_PASS (pass_graphite_transforms
);
1470 NEXT_PASS (pass_lim
);
1471 NEXT_PASS (pass_copy_prop
);
1472 NEXT_PASS (pass_dce_loop
);
1474 NEXT_PASS (pass_iv_canon
);
1475 NEXT_PASS (pass_if_conversion
);
1476 NEXT_PASS (pass_vectorize
);
1478 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1479 NEXT_PASS (pass_dce_loop
);
1481 NEXT_PASS (pass_predcom
);
1482 NEXT_PASS (pass_complete_unroll
);
1483 NEXT_PASS (pass_slp_vectorize
);
1484 NEXT_PASS (pass_parallelize_loops
);
1485 NEXT_PASS (pass_loop_prefetch
);
1486 NEXT_PASS (pass_iv_optimize
);
1487 NEXT_PASS (pass_lim
);
1488 NEXT_PASS (pass_tree_loop_done
);
1490 NEXT_PASS (pass_lower_vector_ssa
);
1491 NEXT_PASS (pass_cse_reciprocals
);
1492 NEXT_PASS (pass_reassoc
);
1493 NEXT_PASS (pass_vrp
);
1494 NEXT_PASS (pass_strength_reduction
);
1495 NEXT_PASS (pass_dominator
);
1496 /* The only const/copy propagation opportunities left after
1497 DOM should be due to degenerate PHI nodes. So rather than
1498 run the full propagators, run a specialized pass which
1499 only examines PHIs to discover const/copy propagation
1501 NEXT_PASS (pass_phi_only_cprop
);
1502 NEXT_PASS (pass_cd_dce
);
1503 NEXT_PASS (pass_tracer
);
1505 /* FIXME: If DCE is not run before checking for uninitialized uses,
1506 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1507 However, this also causes us to misdiagnose cases that should be
1508 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1510 To fix the false positives in uninit-5.c, we would have to
1511 account for the predicates protecting the set and the use of each
1512 variable. Using a representation like Gated Single Assignment
1514 NEXT_PASS (pass_late_warn_uninitialized
);
1515 NEXT_PASS (pass_dse
);
1516 NEXT_PASS (pass_forwprop
);
1517 NEXT_PASS (pass_phiopt
);
1518 NEXT_PASS (pass_fold_builtins
);
1519 NEXT_PASS (pass_optimize_widening_mul
);
1520 NEXT_PASS (pass_tail_calls
);
1521 NEXT_PASS (pass_rename_ssa_copies
);
1522 NEXT_PASS (pass_uncprop
);
1523 NEXT_PASS (pass_local_pure_const
);
1525 NEXT_PASS (pass_all_optimizations_g
);
1527 struct opt_pass
**p
= &pass_all_optimizations_g
.pass
.sub
;
1528 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1529 NEXT_PASS (pass_strip_predict_hints
);
1530 /* Lower remaining pieces of GIMPLE. */
1531 NEXT_PASS (pass_lower_complex
);
1532 NEXT_PASS (pass_lower_vector_ssa
);
1533 /* Perform simple scalar cleanup which is constant/copy propagation. */
1534 NEXT_PASS (pass_ccp
);
1535 NEXT_PASS (pass_object_sizes
);
1536 /* Copy propagation also copy-propagates constants, this is necessary
1537 to forward object-size results properly. */
1538 NEXT_PASS (pass_copy_prop
);
1539 NEXT_PASS (pass_asan
);
1540 NEXT_PASS (pass_tsan
);
1541 NEXT_PASS (pass_rename_ssa_copies
);
1542 NEXT_PASS (pass_dce
);
1543 /* Fold remaining builtins. */
1544 NEXT_PASS (pass_fold_builtins
);
1545 /* ??? We do want some kind of loop invariant motion, but we possibly
1546 need to adjust LIM to be more friendly towards preserving accurate
1547 debug information here. */
1548 NEXT_PASS (pass_late_warn_uninitialized
);
1549 NEXT_PASS (pass_uncprop
);
1550 NEXT_PASS (pass_local_pure_const
);
1552 NEXT_PASS (pass_tm_init
);
1554 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1555 NEXT_PASS (pass_tm_mark
);
1556 NEXT_PASS (pass_tm_memopt
);
1557 NEXT_PASS (pass_tm_edges
);
1559 NEXT_PASS (pass_lower_complex_O0
);
1560 NEXT_PASS (pass_asan_O0
);
1561 NEXT_PASS (pass_tsan_O0
);
1562 NEXT_PASS (pass_cleanup_eh
);
1563 NEXT_PASS (pass_lower_resx
);
1564 NEXT_PASS (pass_nrv
);
1565 NEXT_PASS (pass_mudflap_2
);
1566 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
1567 NEXT_PASS (pass_warn_function_noreturn
);
1569 NEXT_PASS (pass_expand
);
1571 NEXT_PASS (pass_rest_of_compilation
);
1573 struct opt_pass
**p
= &pass_rest_of_compilation
.pass
.sub
;
1574 NEXT_PASS (pass_instantiate_virtual_regs
);
1575 NEXT_PASS (pass_into_cfg_layout_mode
);
1576 NEXT_PASS (pass_jump
);
1577 NEXT_PASS (pass_lower_subreg
);
1578 NEXT_PASS (pass_df_initialize_opt
);
1579 NEXT_PASS (pass_cse
);
1580 NEXT_PASS (pass_rtl_fwprop
);
1581 NEXT_PASS (pass_rtl_cprop
);
1582 NEXT_PASS (pass_rtl_pre
);
1583 NEXT_PASS (pass_rtl_hoist
);
1584 NEXT_PASS (pass_rtl_cprop
);
1585 NEXT_PASS (pass_rtl_store_motion
);
1586 NEXT_PASS (pass_cse_after_global_opts
);
1587 NEXT_PASS (pass_rtl_ifcvt
);
1588 NEXT_PASS (pass_reginfo_init
);
1589 /* Perform loop optimizations. It might be better to do them a bit
1590 sooner, but we want the profile feedback to work more
1592 NEXT_PASS (pass_loop2
);
1594 struct opt_pass
**p
= &pass_loop2
.pass
.sub
;
1595 NEXT_PASS (pass_rtl_loop_init
);
1596 NEXT_PASS (pass_rtl_move_loop_invariants
);
1597 NEXT_PASS (pass_rtl_unswitch
);
1598 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
1599 NEXT_PASS (pass_rtl_doloop
);
1600 NEXT_PASS (pass_rtl_loop_done
);
1603 NEXT_PASS (pass_web
);
1604 NEXT_PASS (pass_rtl_cprop
);
1605 NEXT_PASS (pass_cse2
);
1606 NEXT_PASS (pass_rtl_dse1
);
1607 NEXT_PASS (pass_rtl_fwprop_addr
);
1608 NEXT_PASS (pass_inc_dec
);
1609 NEXT_PASS (pass_initialize_regs
);
1610 NEXT_PASS (pass_ud_rtl_dce
);
1611 NEXT_PASS (pass_combine
);
1612 NEXT_PASS (pass_if_after_combine
);
1613 NEXT_PASS (pass_partition_blocks
);
1614 NEXT_PASS (pass_regmove
);
1615 NEXT_PASS (pass_outof_cfg_layout_mode
);
1616 NEXT_PASS (pass_split_all_insns
);
1617 NEXT_PASS (pass_lower_subreg2
);
1618 NEXT_PASS (pass_df_initialize_no_opt
);
1619 NEXT_PASS (pass_stack_ptr_mod
);
1620 NEXT_PASS (pass_mode_switching
);
1621 NEXT_PASS (pass_match_asm_constraints
);
1622 NEXT_PASS (pass_sms
);
1623 NEXT_PASS (pass_sched
);
1624 NEXT_PASS (pass_ira
);
1625 NEXT_PASS (pass_reload
);
1626 NEXT_PASS (pass_postreload
);
1628 struct opt_pass
**p
= &pass_postreload
.pass
.sub
;
1629 NEXT_PASS (pass_postreload_cse
);
1630 NEXT_PASS (pass_gcse2
);
1631 NEXT_PASS (pass_split_after_reload
);
1632 NEXT_PASS (pass_ree
);
1633 NEXT_PASS (pass_compare_elim_after_reload
);
1634 NEXT_PASS (pass_branch_target_load_optimize1
);
1635 NEXT_PASS (pass_thread_prologue_and_epilogue
);
1636 NEXT_PASS (pass_rtl_dse2
);
1637 NEXT_PASS (pass_stack_adjustments
);
1638 NEXT_PASS (pass_jump2
);
1639 NEXT_PASS (pass_peephole2
);
1640 NEXT_PASS (pass_if_after_reload
);
1641 NEXT_PASS (pass_regrename
);
1642 NEXT_PASS (pass_cprop_hardreg
);
1643 NEXT_PASS (pass_fast_rtl_dce
);
1644 NEXT_PASS (pass_reorder_blocks
);
1645 NEXT_PASS (pass_branch_target_load_optimize2
);
1646 NEXT_PASS (pass_leaf_regs
);
1647 NEXT_PASS (pass_split_before_sched2
);
1648 NEXT_PASS (pass_sched2
);
1649 NEXT_PASS (pass_stack_regs
);
1651 struct opt_pass
**p
= &pass_stack_regs
.pass
.sub
;
1652 NEXT_PASS (pass_split_before_regstack
);
1653 NEXT_PASS (pass_stack_regs_run
);
1655 NEXT_PASS (pass_compute_alignments
);
1656 NEXT_PASS (pass_duplicate_computed_gotos
);
1657 NEXT_PASS (pass_variable_tracking
);
1658 NEXT_PASS (pass_free_cfg
);
1659 NEXT_PASS (pass_machine_reorg
);
1660 NEXT_PASS (pass_cleanup_barriers
);
1661 NEXT_PASS (pass_delay_slots
);
1662 NEXT_PASS (pass_split_for_shorten_branches
);
1663 NEXT_PASS (pass_convert_to_eh_region_ranges
);
1664 NEXT_PASS (pass_shorten_branches
);
1665 NEXT_PASS (pass_set_nothrow_function_flags
);
1666 NEXT_PASS (pass_dwarf2_frame
);
1667 NEXT_PASS (pass_final
);
1669 NEXT_PASS (pass_df_finish
);
1671 NEXT_PASS (pass_clean_state
);
1676 /* Register the passes with the tree dump code. */
1677 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1678 register_dump_files (all_small_ipa_passes
,
1679 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1681 register_dump_files (all_regular_ipa_passes
,
1682 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1684 register_dump_files (all_lto_gen_passes
,
1685 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1687 register_dump_files (all_late_ipa_passes
,
1688 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1690 register_dump_files (all_passes
,
1691 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1695 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1696 function CALLBACK for every function in the call graph. Otherwise,
1697 call CALLBACK on the current function. */
1700 do_per_function (void (*callback
) (void *data
), void *data
)
1702 if (current_function_decl
)
1706 struct cgraph_node
*node
;
1707 FOR_EACH_DEFINED_FUNCTION (node
)
1708 if (gimple_has_body_p (node
->symbol
.decl
)
1709 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1711 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1715 free_dominance_info (CDI_DOMINATORS
);
1716 free_dominance_info (CDI_POST_DOMINATORS
);
1724 /* Because inlining might remove no-longer reachable nodes, we need to
1725 keep the array visible to garbage collector to avoid reading collected
1728 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1730 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1731 function CALLBACK for every function in the call graph. Otherwise,
1732 call CALLBACK on the current function.
1733 This function is global so that plugins can use it. */
1735 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1739 if (current_function_decl
)
1743 gcc_assert (!order
);
1744 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1745 nnodes
= ipa_reverse_postorder (order
);
1746 for (i
= nnodes
- 1; i
>= 0; i
--)
1747 order
[i
]->process
= 1;
1748 for (i
= nnodes
- 1; i
>= 0; i
--)
1750 struct cgraph_node
*node
= order
[i
];
1752 /* Allow possibly removed nodes to be garbage collected. */
1755 if (cgraph_function_with_gimple_body_p (node
))
1757 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1759 free_dominance_info (CDI_DOMINATORS
);
1760 free_dominance_info (CDI_POST_DOMINATORS
);
1771 /* Helper function to perform function body dump. */
1774 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1776 if (dump_file
&& current_function_decl
)
1778 if (cfun
->curr_properties
& PROP_trees
)
1779 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1781 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1783 /* Flush the file. If verification fails, we won't be able to
1784 close the file before aborting. */
1787 if ((cfun
->curr_properties
& PROP_cfg
)
1788 && (cfun
->curr_properties
& PROP_rtl
)
1789 && (dump_flags
& TDF_GRAPH
))
1790 print_rtl_graph_with_bb (dump_file_name
, cfun
->decl
);
1794 static struct profile_record
*profile_record
;
1796 /* Do profile consistency book-keeping for the pass with static number INDEX.
1797 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1798 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1799 if we are only book-keeping on passes that may have selectively disabled
1800 themselves on a given function. */
1802 check_profile_consistency (int index
, int subpass
, bool run
)
1806 if (!profile_record
)
1807 profile_record
= XCNEWVEC (struct profile_record
,
1809 gcc_assert (index
< passes_by_id_size
&& index
>= 0);
1810 gcc_assert (subpass
< 2);
1811 profile_record
[index
].run
|= run
;
1812 account_profile_record (&profile_record
[index
], subpass
);
1815 /* Output profile consistency. */
1818 dump_profile_report (void)
1821 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1822 gcov_type last_time
= 0, last_size
= 0;
1823 double rel_time_change
, rel_size_change
;
1824 int last_reported
= 0;
1826 if (!profile_record
)
1828 fprintf (stderr
, "\nProfile consistency report:\n\n");
1829 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1830 fprintf (stderr
, " |freq count |freq count |size time\n");
1832 for (i
= 0; i
< passes_by_id_size
; i
++)
1833 for (j
= 0 ; j
< 2; j
++)
1834 if (profile_record
[i
].run
)
1837 rel_time_change
= (profile_record
[i
].time
[j
]
1838 - (double)last_time
) * 100 / (double)last_time
;
1840 rel_time_change
= 0;
1842 rel_size_change
= (profile_record
[i
].size
[j
]
1843 - (double)last_size
) * 100 / (double)last_size
;
1845 rel_size_change
= 0;
1847 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1848 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1849 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1850 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1851 || rel_time_change
|| rel_size_change
)
1854 fprintf (stderr
, "%-20s %s",
1855 passes_by_id
[i
]->name
,
1856 j
? "(after TODO)" : " ");
1857 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1858 fprintf (stderr
, "| %+5i",
1859 profile_record
[i
].num_mismatched_freq_in
[j
]
1862 fprintf (stderr
, "| ");
1863 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1864 fprintf (stderr
, " %+5i",
1865 profile_record
[i
].num_mismatched_count_in
[j
]
1868 fprintf (stderr
, " ");
1869 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1870 fprintf (stderr
, "| %+5i",
1871 profile_record
[i
].num_mismatched_freq_out
[j
]
1874 fprintf (stderr
, "| ");
1875 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1876 fprintf (stderr
, " %+5i",
1877 profile_record
[i
].num_mismatched_count_out
[j
]
1880 fprintf (stderr
, " ");
1882 /* Size/time units change across gimple and RTL. */
1883 if (i
== pass_expand
.pass
.static_pass_number
)
1884 fprintf (stderr
, "|----------");
1887 if (rel_size_change
)
1888 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1890 fprintf (stderr
, "| ");
1891 if (rel_time_change
)
1892 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1894 fprintf (stderr
, "\n");
1895 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1896 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1897 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1898 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1900 else if (j
&& last_reported
!= i
)
1903 fprintf (stderr
, "%-20s ------------| | |\n",
1904 passes_by_id
[i
]->name
);
1906 last_time
= profile_record
[i
].time
[j
];
1907 last_size
= profile_record
[i
].size
[j
];
1911 /* Perform all TODO actions that ought to be done on each function. */
1914 execute_function_todo (void *data
)
1916 unsigned int flags
= (size_t)data
;
1917 flags
&= ~cfun
->last_verified
;
1921 /* Always cleanup the CFG before trying to update SSA. */
1922 if (flags
& TODO_cleanup_cfg
)
1924 bool cleanup
= cleanup_tree_cfg ();
1926 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
1927 flags
|= TODO_remove_unused_locals
;
1929 /* When cleanup_tree_cfg merges consecutive blocks, it may
1930 perform some simplistic propagation when removing single
1931 valued PHI nodes. This propagation may, in turn, cause the
1932 SSA form to become out-of-date (see PR 22037). So, even
1933 if the parent pass had not scheduled an SSA update, we may
1934 still need to do one. */
1935 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1936 flags
|= TODO_update_ssa
;
1939 if (flags
& TODO_update_ssa_any
)
1941 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1942 update_ssa (update_flags
);
1943 cfun
->last_verified
&= ~TODO_verify_ssa
;
1946 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1947 compute_may_aliases ();
1949 if (optimize
&& (flags
& TODO_update_address_taken
))
1950 execute_update_addresses_taken ();
1952 if (flags
& TODO_remove_unused_locals
)
1953 remove_unused_locals ();
1955 if (flags
& TODO_rebuild_frequencies
)
1956 rebuild_frequencies ();
1958 if (flags
& TODO_rebuild_cgraph_edges
)
1959 rebuild_cgraph_edges ();
1961 /* If we've seen errors do not bother running any verifiers. */
1965 #if defined ENABLE_CHECKING
1966 if (flags
& TODO_verify_ssa
1967 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1969 verify_gimple_in_cfg (cfun
);
1972 else if (flags
& TODO_verify_stmts
)
1973 verify_gimple_in_cfg (cfun
);
1974 if (flags
& TODO_verify_flow
)
1975 verify_flow_info ();
1976 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1977 verify_loop_closed_ssa (false);
1978 if (flags
& TODO_verify_rtl_sharing
)
1979 verify_rtl_sharing ();
1982 cfun
->last_verified
= flags
& TODO_verify_all
;
1985 /* Perform all TODO actions. */
1987 execute_todo (unsigned int flags
)
1989 #if defined ENABLE_CHECKING
1991 && need_ssa_update_p (cfun
))
1992 gcc_assert (flags
& TODO_update_ssa_any
);
1995 timevar_push (TV_TODO
);
1997 /* Inform the pass whether it is the first time it is run. */
1998 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2000 statistics_fini_pass ();
2002 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2004 /* Always remove functions just as before inlining: IPA passes might be
2005 interested to see bodies of extern inline functions that are not inlined
2006 to analyze side effects. The full removal is done just at the end
2007 of IPA pass queue. */
2008 if (flags
& TODO_remove_functions
)
2011 symtab_remove_unreachable_nodes (true, dump_file
);
2014 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2017 dump_symtab (dump_file
);
2018 /* Flush the file. If verification fails, we won't be able to
2019 close the file before aborting. */
2023 if (flags
& TODO_ggc_collect
)
2026 /* Now that the dumping has been done, we can get rid of the optional
2028 if (flags
& TODO_df_finish
)
2029 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2031 timevar_pop (TV_TODO
);
2034 /* Verify invariants that should hold between passes. This is a place
2035 to put simple sanity checks. */
2038 verify_interpass_invariants (void)
2040 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2043 /* Clear the last verified flag. */
2046 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
2048 cfun
->last_verified
= 0;
2051 /* Helper function. Verify that the properties has been turn into the
2052 properties expected by the pass. */
2054 #ifdef ENABLE_CHECKING
2056 verify_curr_properties (void *data
)
2058 unsigned int props
= (size_t)data
;
2059 gcc_assert ((cfun
->curr_properties
& props
) == props
);
2063 /* Initialize pass dump file. */
2064 /* This is non-static so that the plugins can use it. */
2067 pass_init_dump_file (struct opt_pass
*pass
)
2069 /* If a dump file name is present, open it if enabled. */
2070 if (pass
->static_pass_number
!= -1)
2072 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
2073 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
2074 dump_start (pass
->static_pass_number
, &dump_flags
);
2075 if (dump_file
&& current_function_decl
)
2076 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2077 return initializing_dump
;
2083 /* Flush PASS dump file. */
2084 /* This is non-static so that plugins can use it. */
2087 pass_fini_dump_file (struct opt_pass
*pass
)
2089 /* Flush and close dump file. */
2092 free (CONST_CAST (char *, dump_file_name
));
2093 dump_file_name
= NULL
;
2096 dump_finish (pass
->static_pass_number
);
2099 /* After executing the pass, apply expected changes to the function
2103 update_properties_after_pass (void *data
)
2105 struct opt_pass
*pass
= (struct opt_pass
*) data
;
2106 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
2107 & ~pass
->properties_destroyed
;
2110 /* Execute summary generation for all of the passes in IPA_PASS. */
2113 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
2117 struct opt_pass
*pass
= &ipa_pass
->pass
;
2119 /* Execute all of the IPA_PASSes in the list. */
2120 if (ipa_pass
->pass
.type
== IPA_PASS
2121 && (!pass
->gate
|| pass
->gate ())
2122 && ipa_pass
->generate_summary
)
2124 pass_init_dump_file (pass
);
2126 /* If a timevar is present, start it. */
2128 timevar_push (pass
->tv_id
);
2130 ipa_pass
->generate_summary ();
2134 timevar_pop (pass
->tv_id
);
2136 pass_fini_dump_file (pass
);
2138 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->pass
.next
;
2142 /* Execute IPA_PASS function transform on NODE. */
2145 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2146 struct ipa_opt_pass_d
*ipa_pass
)
2148 struct opt_pass
*pass
= &ipa_pass
->pass
;
2149 unsigned int todo_after
= 0;
2151 current_pass
= pass
;
2152 if (!ipa_pass
->function_transform
)
2155 /* Note that the folders should only create gimple expressions.
2156 This is a hack until the new folder is ready. */
2157 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2159 pass_init_dump_file (pass
);
2161 /* Run pre-pass verification. */
2162 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2164 /* If a timevar is present, start it. */
2165 if (pass
->tv_id
!= TV_NONE
)
2166 timevar_push (pass
->tv_id
);
2169 todo_after
= ipa_pass
->function_transform (node
);
2172 if (pass
->tv_id
!= TV_NONE
)
2173 timevar_pop (pass
->tv_id
);
2175 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2176 check_profile_consistency (pass
->static_pass_number
, 0, true);
2178 /* Run post-pass cleanup and verification. */
2179 execute_todo (todo_after
);
2180 verify_interpass_invariants ();
2181 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2182 check_profile_consistency (pass
->static_pass_number
, 1, true);
2184 do_per_function (execute_function_dump
, NULL
);
2185 pass_fini_dump_file (pass
);
2187 current_pass
= NULL
;
2190 /* For the current function, execute all ipa transforms. */
2193 execute_all_ipa_transforms (void)
2195 struct cgraph_node
*node
;
2198 node
= cgraph_get_node (current_function_decl
);
2200 if (node
->ipa_transforms_to_apply
.exists ())
2204 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2205 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2206 node
->ipa_transforms_to_apply
.release ();
2210 /* Callback for do_per_function to apply all IPA transforms. */
2213 apply_ipa_transforms (void *data
)
2215 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2216 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2218 *(bool *)data
= true;
2219 execute_all_ipa_transforms();
2220 rebuild_cgraph_edges ();
2224 /* Check if PASS is explicitly disabled or enabled and return
2225 the gate status. FUNC is the function to be processed, and
2226 GATE_STATUS is the gate status determined by pass manager by
2230 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2232 bool explicitly_enabled
= false;
2233 bool explicitly_disabled
= false;
2236 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2237 enabled_pass_uid_range_tab
);
2239 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2240 disabled_pass_uid_range_tab
);
2242 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2251 execute_one_pass (struct opt_pass
*pass
)
2253 bool initializing_dump
;
2254 unsigned int todo_after
= 0;
2258 /* IPA passes are executed on whole program, so cfun should be NULL.
2259 Other passes need function context set. */
2260 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2261 gcc_assert (!cfun
&& !current_function_decl
);
2263 gcc_assert (cfun
&& current_function_decl
);
2265 current_pass
= pass
;
2267 /* Check whether gate check should be avoided.
2268 User controls the value of the gate through the parameter "gate_status". */
2269 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2270 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2272 /* Override gate with plugin. */
2273 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2277 /* Run so passes selectively disabling themselves on a given function
2278 are not miscounted. */
2279 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2281 check_profile_consistency (pass
->static_pass_number
, 0, false);
2282 check_profile_consistency (pass
->static_pass_number
, 1, false);
2284 current_pass
= NULL
;
2288 /* Pass execution event trigger: useful to identify passes being
2290 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2292 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2293 Apply all trnasforms first. */
2294 if (pass
->type
== SIMPLE_IPA_PASS
)
2296 bool applied
= false;
2297 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2299 symtab_remove_unreachable_nodes (true, dump_file
);
2300 /* Restore current_pass. */
2301 current_pass
= pass
;
2304 if (!quiet_flag
&& !cfun
)
2305 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2307 /* Note that the folders should only create gimple expressions.
2308 This is a hack until the new folder is ready. */
2309 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2311 initializing_dump
= pass_init_dump_file (pass
);
2313 /* Run pre-pass verification. */
2314 execute_todo (pass
->todo_flags_start
);
2316 #ifdef ENABLE_CHECKING
2317 do_per_function (verify_curr_properties
,
2318 (void *)(size_t)pass
->properties_required
);
2321 /* If a timevar is present, start it. */
2322 if (pass
->tv_id
!= TV_NONE
)
2323 timevar_push (pass
->tv_id
);
2328 todo_after
= pass
->execute ();
2329 do_per_function (clear_last_verified
, NULL
);
2333 if (pass
->tv_id
!= TV_NONE
)
2334 timevar_pop (pass
->tv_id
);
2336 do_per_function (update_properties_after_pass
, pass
);
2338 if (initializing_dump
2340 && (dump_flags
& TDF_GRAPH
)
2342 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
2343 == (PROP_cfg
| PROP_rtl
))
2345 clean_graph_dump_file (dump_file_name
);
2348 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2349 check_profile_consistency (pass
->static_pass_number
, 0, true);
2351 /* Run post-pass cleanup and verification. */
2352 execute_todo (todo_after
| pass
->todo_flags_finish
);
2353 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2354 check_profile_consistency (pass
->static_pass_number
, 1, true);
2356 verify_interpass_invariants ();
2357 do_per_function (execute_function_dump
, NULL
);
2358 if (pass
->type
== IPA_PASS
)
2360 struct cgraph_node
*node
;
2361 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2362 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2365 if (!current_function_decl
)
2366 cgraph_process_new_functions ();
2368 pass_fini_dump_file (pass
);
2370 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2371 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2372 || pass
->type
!= RTL_PASS
);
2374 current_pass
= NULL
;
2380 execute_pass_list (struct opt_pass
*pass
)
2384 gcc_assert (pass
->type
== GIMPLE_PASS
2385 || pass
->type
== RTL_PASS
);
2386 if (execute_one_pass (pass
) && pass
->sub
)
2387 execute_pass_list (pass
->sub
);
2393 /* Same as execute_pass_list but assume that subpasses of IPA passes
2394 are local passes. If SET is not NULL, write out summaries of only
2395 those node in SET. */
2398 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2402 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2403 gcc_assert (!current_function_decl
);
2405 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2406 if (pass
->type
== IPA_PASS
2407 && ipa_pass
->write_summary
2408 && (!pass
->gate
|| pass
->gate ()))
2410 /* If a timevar is present, start it. */
2412 timevar_push (pass
->tv_id
);
2414 pass_init_dump_file (pass
);
2416 ipa_pass
->write_summary ();
2418 pass_fini_dump_file (pass
);
2420 /* If a timevar is present, start it. */
2422 timevar_pop (pass
->tv_id
);
2425 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2426 ipa_write_summaries_2 (pass
->sub
, state
);
2432 /* Helper function of ipa_write_summaries. Creates and destroys the
2433 decl state and calls ipa_write_summaries_2 for all passes that have
2434 summaries. SET is the set of nodes to be written. */
2437 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2439 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2440 state
->symtab_node_encoder
= encoder
;
2442 lto_push_out_decl_state (state
);
2444 gcc_assert (!flag_wpa
);
2445 ipa_write_summaries_2 (all_regular_ipa_passes
, state
);
2446 ipa_write_summaries_2 (all_lto_gen_passes
, state
);
2448 gcc_assert (lto_get_out_decl_state () == state
);
2449 lto_pop_out_decl_state ();
2450 lto_delete_out_decl_state (state
);
2453 /* Write out summaries for all the nodes in the callgraph. */
2456 ipa_write_summaries (void)
2458 lto_symtab_encoder_t encoder
;
2460 struct varpool_node
*vnode
;
2461 struct cgraph_node
**order
;
2463 if (!flag_generate_lto
|| seen_error ())
2466 encoder
= lto_symtab_encoder_new (false);
2468 /* Create the callgraph set in the same order used in
2469 cgraph_expand_all_functions. This mostly facilitates debugging,
2470 since it causes the gimple file to be processed in the same order
2471 as the source code. */
2472 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2473 order_pos
= ipa_reverse_postorder (order
);
2474 gcc_assert (order_pos
== cgraph_n_nodes
);
2476 for (i
= order_pos
- 1; i
>= 0; i
--)
2478 struct cgraph_node
*node
= order
[i
];
2480 if (cgraph_function_with_gimple_body_p (node
))
2482 /* When streaming out references to statements as part of some IPA
2483 pass summary, the statements need to have uids assigned and the
2484 following does that for all the IPA passes here. Naturally, this
2485 ordering then matches the one IPA-passes get in their stmt_fixup
2488 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2489 renumber_gimple_stmt_uids ();
2493 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2496 FOR_EACH_DEFINED_VARIABLE (vnode
)
2497 if ((!vnode
->alias
|| vnode
->alias_of
))
2498 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2500 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2505 /* Same as execute_pass_list but assume that subpasses of IPA passes
2506 are local passes. If SET is not NULL, write out optimization summaries of
2507 only those node in SET. */
2510 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2514 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2515 gcc_assert (!current_function_decl
);
2517 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2518 if (pass
->type
== IPA_PASS
2519 && ipa_pass
->write_optimization_summary
2520 && (!pass
->gate
|| pass
->gate ()))
2522 /* If a timevar is present, start it. */
2524 timevar_push (pass
->tv_id
);
2526 pass_init_dump_file (pass
);
2528 ipa_pass
->write_optimization_summary ();
2530 pass_fini_dump_file (pass
);
2532 /* If a timevar is present, start it. */
2534 timevar_pop (pass
->tv_id
);
2537 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2538 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2544 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2545 NULL, write out all summaries of all nodes. */
2548 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2550 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2551 lto_symtab_encoder_iterator lsei
;
2552 state
->symtab_node_encoder
= encoder
;
2554 lto_push_out_decl_state (state
);
2555 for (lsei
= lsei_start_function_in_partition (encoder
);
2556 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2558 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2559 /* When streaming out references to statements as part of some IPA
2560 pass summary, the statements need to have uids assigned.
2562 For functions newly born at WPA stage we need to initialize
2565 && gimple_has_body_p (node
->symbol
.decl
))
2567 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2568 renumber_gimple_stmt_uids ();
2573 gcc_assert (flag_wpa
);
2574 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, state
);
2575 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, state
);
2577 gcc_assert (lto_get_out_decl_state () == state
);
2578 lto_pop_out_decl_state ();
2579 lto_delete_out_decl_state (state
);
2582 /* Same as execute_pass_list but assume that subpasses of IPA passes
2583 are local passes. */
2586 ipa_read_summaries_1 (struct opt_pass
*pass
)
2590 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2592 gcc_assert (!current_function_decl
);
2594 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2596 if (pass
->gate
== NULL
|| pass
->gate ())
2598 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2600 /* If a timevar is present, start it. */
2602 timevar_push (pass
->tv_id
);
2604 pass_init_dump_file (pass
);
2606 ipa_pass
->read_summary ();
2608 pass_fini_dump_file (pass
);
2612 timevar_pop (pass
->tv_id
);
2615 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2616 ipa_read_summaries_1 (pass
->sub
);
2623 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2626 ipa_read_summaries (void)
2628 ipa_read_summaries_1 (all_regular_ipa_passes
);
2629 ipa_read_summaries_1 (all_lto_gen_passes
);
2632 /* Same as execute_pass_list but assume that subpasses of IPA passes
2633 are local passes. */
2636 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2640 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2642 gcc_assert (!current_function_decl
);
2644 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2646 if (pass
->gate
== NULL
|| pass
->gate ())
2648 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2650 /* If a timevar is present, start it. */
2652 timevar_push (pass
->tv_id
);
2654 pass_init_dump_file (pass
);
2656 ipa_pass
->read_optimization_summary ();
2658 pass_fini_dump_file (pass
);
2662 timevar_pop (pass
->tv_id
);
2665 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2666 ipa_read_optimization_summaries_1 (pass
->sub
);
2672 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2675 ipa_read_optimization_summaries (void)
2677 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2678 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2681 /* Same as execute_pass_list but assume that subpasses of IPA passes
2682 are local passes. */
2684 execute_ipa_pass_list (struct opt_pass
*pass
)
2688 gcc_assert (!current_function_decl
);
2690 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2691 if (execute_one_pass (pass
) && pass
->sub
)
2693 if (pass
->sub
->type
== GIMPLE_PASS
)
2695 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2696 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2698 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2700 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2701 || pass
->sub
->type
== IPA_PASS
)
2702 execute_ipa_pass_list (pass
->sub
);
2706 gcc_assert (!current_function_decl
);
2707 cgraph_process_new_functions ();
2713 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2716 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2717 struct cgraph_node
*node
, gimple
*stmts
)
2721 /* Execute all of the IPA_PASSes in the list. */
2722 if (pass
->type
== IPA_PASS
2723 && (!pass
->gate
|| pass
->gate ()))
2725 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2727 if (ipa_pass
->stmt_fixup
)
2729 pass_init_dump_file (pass
);
2730 /* If a timevar is present, start it. */
2732 timevar_push (pass
->tv_id
);
2734 ipa_pass
->stmt_fixup (node
, stmts
);
2738 timevar_pop (pass
->tv_id
);
2739 pass_fini_dump_file (pass
);
2742 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2748 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2751 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2753 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2757 extern void debug_properties (unsigned int);
2758 extern void dump_properties (FILE *, unsigned int);
2761 dump_properties (FILE *dump
, unsigned int props
)
2763 fprintf (dump
, "Properties:\n");
2764 if (props
& PROP_gimple_any
)
2765 fprintf (dump
, "PROP_gimple_any\n");
2766 if (props
& PROP_gimple_lcf
)
2767 fprintf (dump
, "PROP_gimple_lcf\n");
2768 if (props
& PROP_gimple_leh
)
2769 fprintf (dump
, "PROP_gimple_leh\n");
2770 if (props
& PROP_cfg
)
2771 fprintf (dump
, "PROP_cfg\n");
2772 if (props
& PROP_ssa
)
2773 fprintf (dump
, "PROP_ssa\n");
2774 if (props
& PROP_no_crit_edges
)
2775 fprintf (dump
, "PROP_no_crit_edges\n");
2776 if (props
& PROP_rtl
)
2777 fprintf (dump
, "PROP_rtl\n");
2778 if (props
& PROP_gimple_lomp
)
2779 fprintf (dump
, "PROP_gimple_lomp\n");
2780 if (props
& PROP_gimple_lcx
)
2781 fprintf (dump
, "PROP_gimple_lcx\n");
2782 if (props
& PROP_cfglayout
)
2783 fprintf (dump
, "PROP_cfglayout\n");
2787 debug_properties (unsigned int props
)
2789 dump_properties (stderr
, props
);
2792 /* Called by local passes to see if function is called by already processed nodes.
2793 Because we process nodes in topological order, this means that function is
2794 in recursive cycle or we introduced new direct calls. */
2796 function_called_by_processed_nodes_p (void)
2798 struct cgraph_edge
*e
;
2799 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2803 if (e
->caller
->symbol
.decl
== current_function_decl
)
2805 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2807 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2809 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2814 fprintf (dump_file
, "Already processed call to:\n");
2815 dump_cgraph_node (dump_file
, e
->caller
);
2820 #include "gt-passes.h"