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"
35 #include "insn-attr.h"
36 #include "insn-config.h"
37 #include "insn-flags.h"
38 #include "hard-reg-set.h"
45 #include "basic-block.h"
50 #include "diagnostic-core.h"
55 #include "langhooks.h"
57 #include "hosthooks.h"
61 #include "value-prof.h"
62 #include "tree-inline.h"
63 #include "tree-flow.h"
64 #include "tree-pass.h"
65 #include "tree-dump.h"
68 #include "lto-streamer.h"
70 #include "ipa-utils.h"
71 #include "tree-pretty-print.h" /* for dump_function_header */
73 /* This is used for debugging. It allows the current pass to printed
74 from anywhere in compilation.
75 The variable current_pass is also used for statistics and plugins. */
76 struct opt_pass
*current_pass
;
78 static void register_pass_name (struct opt_pass
*, const char *);
80 /* Call from anywhere to find out what pass this is. Useful for
81 printing out debugging information deep inside an service
84 print_current_pass (FILE *file
)
87 fprintf (file
, "current pass = %s (%d)\n",
88 current_pass
->name
, current_pass
->static_pass_number
);
90 fprintf (file
, "no current pass.\n");
94 /* Call from the debugger to get the current pass name. */
98 print_current_pass (stderr
);
103 /* Global variables used to communicate with passes. */
105 bool first_pass_instance
;
108 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
111 This does nothing for local (non-static) variables, unless the
112 variable is a register variable with DECL_ASSEMBLER_NAME set. In
113 that case, or if the variable is not an automatic, it sets up the
114 RTL and outputs any assembler code (label definition, storage
115 allocation and initialization).
117 DECL is the declaration. TOP_LEVEL is nonzero
118 if this declaration is not within a function. */
121 rest_of_decl_compilation (tree decl
,
125 /* We deferred calling assemble_alias so that we could collect
126 other attributes such as visibility. Emit the alias now. */
130 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
133 alias
= TREE_VALUE (TREE_VALUE (alias
));
134 alias
= get_identifier (TREE_STRING_POINTER (alias
));
135 /* A quirk of the initial implementation of aliases required that the
136 user add "extern" to all of them. Which is silly, but now
137 historical. Do note that the symbol is in fact locally defined. */
138 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
139 DECL_EXTERNAL (decl
) = 0;
140 assemble_alias (decl
, alias
);
144 /* Can't defer this, because it needs to happen before any
145 later function definitions are processed. */
146 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
147 make_decl_rtl (decl
);
149 /* Forward declarations for nested functions are not "external",
150 but we need to treat them as if they were. */
151 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
152 || TREE_CODE (decl
) == FUNCTION_DECL
)
154 timevar_push (TV_VARCONST
);
156 /* Don't output anything when a tentative file-scope definition
157 is seen. But at end of compilation, do output code for them.
159 We do output all variables and rely on
160 callgraph code to defer them except for forward declarations
161 (see gcc.c-torture/compile/920624-1.c) */
163 || !DECL_DEFER_OUTPUT (decl
)
164 || DECL_INITIAL (decl
))
165 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
166 && !DECL_EXTERNAL (decl
))
168 /* When reading LTO unit, we also read varpool, so do not
170 if (in_lto_p
&& !at_end
)
172 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
173 varpool_finalize_decl (decl
);
176 #ifdef ASM_FINISH_DECLARE_OBJECT
177 if (decl
== last_assemble_variable_decl
)
179 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
184 timevar_pop (TV_VARCONST
);
186 else if (TREE_CODE (decl
) == TYPE_DECL
187 /* Like in rest_of_type_compilation, avoid confusing the debug
188 information machinery when there are errors. */
191 timevar_push (TV_SYMOUT
);
192 debug_hooks
->type_decl (decl
, !top_level
);
193 timevar_pop (TV_SYMOUT
);
196 /* Let cgraph know about the existence of variables. */
197 if (in_lto_p
&& !at_end
)
199 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
200 && TREE_STATIC (decl
))
201 varpool_node_for_decl (decl
);
204 /* Called after finishing a record, union or enumeral type. */
207 rest_of_type_compilation (tree type
, int toplev
)
209 /* Avoid confusing the debug information machinery when there are
214 timevar_push (TV_SYMOUT
);
215 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
216 timevar_pop (TV_SYMOUT
);
222 finish_optimization_passes (void)
225 struct dump_file_info
*dfi
;
228 timevar_push (TV_DUMP
);
229 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
231 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
233 dump_finish (pass_profile
.pass
.static_pass_number
);
238 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
239 print_combine_total_stats ();
240 dump_finish (pass_profile
.pass
.static_pass_number
);
243 /* Do whatever is necessary to finish printing the graphs. */
244 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
245 if (dump_initialized_p (i
)
246 && (dfi
->pflags
& TDF_GRAPH
) != 0
247 && (name
= get_dump_file_name (i
)) != NULL
)
249 finish_graph_dump_file (name
);
253 timevar_pop (TV_DUMP
);
257 execute_all_early_local_passes (void)
259 /* Once this pass (and its sub-passes) are complete, all functions
260 will be in SSA form. Technically this state change is happening
261 a tad early, since the sub-passes have not yet run, but since
262 none of the sub-passes are IPA passes and do not create new
263 functions, this is ok. We're setting this value for the benefit
264 of IPA passes that follow. */
265 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
266 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
270 /* Gate: execute, or not, all of the non-trivial optimizations. */
273 gate_all_early_local_passes (void)
275 /* Don't bother doing anything if the program has errors. */
276 return (!seen_error () && !in_lto_p
);
279 struct simple_ipa_opt_pass pass_early_local_passes
=
283 "early_local_cleanups", /* name */
284 OPTGROUP_NONE
, /* optinfo_flags */
285 gate_all_early_local_passes
, /* gate */
286 execute_all_early_local_passes
, /* execute */
289 0, /* static_pass_number */
290 TV_EARLY_LOCAL
, /* tv_id */
291 0, /* properties_required */
292 0, /* properties_provided */
293 0, /* properties_destroyed */
294 0, /* todo_flags_start */
295 TODO_remove_functions
/* todo_flags_finish */
299 /* Gate: execute, or not, all of the non-trivial optimizations. */
302 gate_all_early_optimizations (void)
304 return (optimize
>= 1
305 /* Don't bother doing anything if the program has errors. */
309 static struct gimple_opt_pass pass_all_early_optimizations
=
313 "early_optimizations", /* name */
314 OPTGROUP_NONE
, /* optinfo_flags */
315 gate_all_early_optimizations
, /* gate */
319 0, /* static_pass_number */
321 0, /* properties_required */
322 0, /* properties_provided */
323 0, /* properties_destroyed */
324 0, /* todo_flags_start */
325 0 /* todo_flags_finish */
329 /* Gate: execute, or not, all of the non-trivial optimizations. */
332 gate_all_optimizations (void)
334 return optimize
>= 1 && !optimize_debug
;
337 static struct gimple_opt_pass pass_all_optimizations
=
341 "*all_optimizations", /* name */
342 OPTGROUP_NONE
, /* optinfo_flags */
343 gate_all_optimizations
, /* gate */
347 0, /* static_pass_number */
348 TV_OPTIMIZE
, /* tv_id */
349 0, /* properties_required */
350 0, /* properties_provided */
351 0, /* properties_destroyed */
352 0, /* todo_flags_start */
353 0 /* todo_flags_finish */
357 /* Gate: execute, or not, all of the non-trivial optimizations. */
360 gate_all_optimizations_g (void)
362 return optimize
>= 1 && optimize_debug
;
365 static struct gimple_opt_pass pass_all_optimizations_g
=
369 "*all_optimizations_g", /* name */
370 OPTGROUP_NONE
, /* optinfo_flags */
371 gate_all_optimizations_g
, /* gate */
375 0, /* static_pass_number */
376 TV_OPTIMIZE
, /* tv_id */
377 0, /* properties_required */
378 0, /* properties_provided */
379 0, /* properties_destroyed */
380 0, /* todo_flags_start */
381 0 /* todo_flags_finish */
386 gate_rest_of_compilation (void)
388 /* Early return if there were errors. We can run afoul of our
389 consistency checks, and there's not really much point in fixing them. */
390 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
393 static struct rtl_opt_pass pass_rest_of_compilation
=
397 "*rest_of_compilation", /* name */
398 OPTGROUP_NONE
, /* optinfo_flags */
399 gate_rest_of_compilation
, /* gate */
403 0, /* static_pass_number */
404 TV_REST_OF_COMPILATION
, /* tv_id */
405 PROP_rtl
, /* properties_required */
406 0, /* properties_provided */
407 0, /* properties_destroyed */
408 0, /* todo_flags_start */
409 TODO_ggc_collect
/* todo_flags_finish */
414 gate_postreload (void)
416 return reload_completed
;
419 static struct rtl_opt_pass pass_postreload
=
423 "*all-postreload", /* name */
424 OPTGROUP_NONE
, /* optinfo_flags */
425 gate_postreload
, /* gate */
429 0, /* static_pass_number */
430 TV_POSTRELOAD
, /* tv_id */
431 PROP_rtl
, /* properties_required */
432 0, /* properties_provided */
433 0, /* properties_destroyed */
434 0, /* todo_flags_start */
435 TODO_ggc_collect
| TODO_verify_rtl_sharing
/* todo_flags_finish */
441 /* The root of the compilation pass tree, once constructed. */
442 struct opt_pass
*all_passes
, *all_small_ipa_passes
, *all_lowering_passes
,
443 *all_regular_ipa_passes
, *all_late_ipa_passes
, *all_lto_gen_passes
;
445 /* This is used by plugins, and should also be used in register_pass. */
446 #define DEF_PASS_LIST(LIST) &LIST,
447 struct opt_pass
**gcc_pass_lists
[] = { GCC_PASS_LISTS NULL
};
450 /* A map from static pass id to optimization pass. */
451 struct opt_pass
**passes_by_id
;
452 int passes_by_id_size
;
454 /* Set the static pass number of pass PASS to ID and record that
455 in the mapping from static pass number to pass. */
458 set_pass_for_id (int id
, struct opt_pass
*pass
)
460 pass
->static_pass_number
= id
;
461 if (passes_by_id_size
<= id
)
463 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
464 memset (passes_by_id
+ passes_by_id_size
, 0,
465 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
466 passes_by_id_size
= id
+ 1;
468 passes_by_id
[id
] = pass
;
471 /* Return the pass with the static pass number ID. */
474 get_pass_for_id (int id
)
476 if (id
>= passes_by_id_size
)
478 return passes_by_id
[id
];
481 /* Iterate over the pass tree allocating dump file numbers. We want
482 to do this depth first, and independent of whether the pass is
486 register_one_dump_file (struct opt_pass
*pass
)
488 char *dot_name
, *flag_name
, *glob_name
;
489 const char *name
, *full_name
, *prefix
;
492 int optgroup_flags
= OPTGROUP_NONE
;
494 /* See below in next_pass_1. */
496 if (pass
->static_pass_number
!= -1)
497 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
498 ? 1 : pass
->static_pass_number
));
500 /* The name is both used to identify the pass for the purposes of plugins,
501 and to specify dump file name and option.
502 The latter two might want something short which is not quite unique; for
503 that reason, we may have a disambiguating prefix, followed by a space
504 to mark the start of the following dump file name / option string. */
505 name
= strchr (pass
->name
, ' ');
506 name
= name
? name
+ 1 : pass
->name
;
507 dot_name
= concat (".", name
, num
, NULL
);
508 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
512 optgroup_flags
|= OPTGROUP_IPA
;
514 else if (pass
->type
== GIMPLE_PASS
)
525 flag_name
= concat (prefix
, name
, num
, NULL
);
526 glob_name
= concat (prefix
, name
, NULL
);
527 optgroup_flags
|= pass
->optinfo_flags
;
528 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
, optgroup_flags
);
529 set_pass_for_id (id
, pass
);
530 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
531 register_pass_name (pass
, full_name
);
532 free (CONST_CAST (char *, full_name
));
535 /* Recursive worker function for register_dump_files. */
538 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
542 int new_properties
= (properties
| pass
->properties_provided
)
543 & ~pass
->properties_destroyed
;
545 if (pass
->name
&& pass
->name
[0] != '*')
546 register_one_dump_file (pass
);
549 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
551 /* If we have a gate, combine the properties that we could have with
552 and without the pass being examined. */
554 properties
&= new_properties
;
556 properties
= new_properties
;
565 /* Register the dump files for the pipeline starting at PASS.
566 PROPERTIES reflects the properties that are guaranteed to be available at
567 the beginning of the pipeline. */
570 register_dump_files (struct opt_pass
*pass
,int properties
)
572 pass
->properties_required
|= properties
;
573 register_dump_files_1 (pass
, properties
);
578 const char* unique_name
;
579 struct opt_pass
*pass
;
582 /* Pass registry hash function. */
585 passr_hash (const void *p
)
587 const struct pass_registry
*const s
= (const struct pass_registry
*const) p
;
588 return htab_hash_string (s
->unique_name
);
591 /* Hash equal function */
594 passr_eq (const void *p1
, const void *p2
)
596 const struct pass_registry
*const s1
= (const struct pass_registry
*const) p1
;
597 const struct pass_registry
*const s2
= (const struct pass_registry
*const) p2
;
599 return !strcmp (s1
->unique_name
, s2
->unique_name
);
602 static htab_t name_to_pass_map
= NULL
;
604 /* Register PASS with NAME. */
607 register_pass_name (struct opt_pass
*pass
, const char *name
)
609 struct pass_registry
**slot
;
610 struct pass_registry pr
;
612 if (!name_to_pass_map
)
613 name_to_pass_map
= htab_create (256, passr_hash
, passr_eq
, NULL
);
615 pr
.unique_name
= name
;
616 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
, &pr
, INSERT
);
619 struct pass_registry
*new_pr
;
621 new_pr
= XCNEW (struct pass_registry
);
622 new_pr
->unique_name
= xstrdup (name
);
627 return; /* Ignore plugin passes. */
630 /* Map from pass id to canonicalized pass name. */
632 typedef const char *char_ptr
;
633 static vec
<char_ptr
> pass_tab
= vNULL
;
635 /* Callback function for traversing NAME_TO_PASS_MAP. */
638 pass_traverse (void **slot
, void *data ATTRIBUTE_UNUSED
)
640 struct pass_registry
**p
= (struct pass_registry
**)slot
;
641 struct opt_pass
*pass
= (*p
)->pass
;
643 gcc_assert (pass
->static_pass_number
> 0);
644 gcc_assert (pass_tab
.exists ());
646 pass_tab
[pass
->static_pass_number
] = (*p
)->unique_name
;
651 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
652 table for dumping purpose. */
655 create_pass_tab (void)
657 if (!flag_dump_passes
)
660 pass_tab
.safe_grow_cleared (passes_by_id_size
+ 1);
661 htab_traverse (name_to_pass_map
, pass_traverse
, NULL
);
664 static bool override_gate_status (struct opt_pass
*, tree
, bool);
666 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
667 is turned on or not. */
670 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
672 int indent
= 3 * pass_indent
;
674 bool is_on
, is_really_on
;
676 is_on
= (pass
->gate
== NULL
) ? true : pass
->gate();
677 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
679 if (pass
->static_pass_number
<= 0)
682 pn
= pass_tab
[pass
->static_pass_number
];
684 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
685 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
686 is_on
? " ON" : " OFF",
687 ((!is_on
) == (!is_really_on
) ? ""
688 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
691 /* Dump pass list PASS with indentation INDENT. */
694 dump_pass_list (struct opt_pass
*pass
, int indent
)
698 dump_one_pass (pass
, indent
);
700 dump_pass_list (pass
->sub
, indent
+ 1);
706 /* Dump all optimization passes. */
711 struct cgraph_node
*n
, *node
= NULL
;
715 FOR_EACH_DEFINED_FUNCTION (n
)
716 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
725 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
727 dump_pass_list (all_lowering_passes
, 1);
728 dump_pass_list (all_small_ipa_passes
, 1);
729 dump_pass_list (all_regular_ipa_passes
, 1);
730 dump_pass_list (all_lto_gen_passes
, 1);
731 dump_pass_list (all_late_ipa_passes
, 1);
732 dump_pass_list (all_passes
, 1);
738 /* Returns the pass with NAME. */
740 static struct opt_pass
*
741 get_pass_by_name (const char *name
)
743 struct pass_registry
**slot
, pr
;
745 pr
.unique_name
= name
;
746 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
,
752 return (*slot
)->pass
;
756 /* Range [start, last]. */
762 const char *assem_name
;
763 struct uid_range
*next
;
766 typedef struct uid_range
*uid_range_p
;
769 static vec
<uid_range_p
>
770 enabled_pass_uid_range_tab
= vNULL
;
771 static vec
<uid_range_p
>
772 disabled_pass_uid_range_tab
= vNULL
;
775 /* Parse option string for -fdisable- and -fenable-
776 The syntax of the options:
779 -fdisable-<pass_name>
781 -fenable-<pass_name>=s1:e1,s2:e2,...
782 -fdisable-<pass_name>=s1:e1,s2:e2,...
786 enable_disable_pass (const char *arg
, bool is_enable
)
788 struct opt_pass
*pass
;
789 char *range_str
, *phase_name
;
790 char *argstr
= xstrdup (arg
);
791 vec
<uid_range_p
> *tab
= 0;
793 range_str
= strchr (argstr
,'=');
804 error ("unrecognized option -fenable");
806 error ("unrecognized option -fdisable");
810 pass
= get_pass_by_name (phase_name
);
811 if (!pass
|| pass
->static_pass_number
== -1)
814 error ("unknown pass %s specified in -fenable", phase_name
);
816 error ("unknown pass %s specified in -fdisable", phase_name
);
822 tab
= &enabled_pass_uid_range_tab
;
824 tab
= &disabled_pass_uid_range_tab
;
826 if ((unsigned) pass
->static_pass_number
>= tab
->length ())
827 tab
->safe_grow_cleared (pass
->static_pass_number
+ 1);
832 uid_range_p new_range
= XCNEW (struct uid_range
);
834 new_range
->start
= 0;
835 new_range
->last
= (unsigned)-1;
837 slot
= (*tab
)[pass
->static_pass_number
];
838 new_range
->next
= slot
;
839 (*tab
)[pass
->static_pass_number
] = new_range
;
841 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
842 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
844 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
845 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
849 char *next_range
= NULL
;
850 char *one_range
= range_str
;
851 char *end_val
= NULL
;
856 uid_range_p new_range
;
857 char *invalid
= NULL
;
859 char *func_name
= NULL
;
861 next_range
= strchr (one_range
, ',');
868 end_val
= strchr (one_range
, ':');
874 start
= strtol (one_range
, &invalid
, 10);
875 if (*invalid
|| start
< 0)
877 if (end_val
|| (one_range
[0] >= '0'
878 && one_range
[0] <= '9'))
880 error ("Invalid range %s in option %s",
882 is_enable
? "-fenable" : "-fdisable");
886 func_name
= one_range
;
890 new_range
= XCNEW (struct uid_range
);
893 new_range
->start
= (unsigned) start
;
894 new_range
->last
= (unsigned) start
;
898 new_range
->start
= (unsigned) -1;
899 new_range
->last
= (unsigned) -1;
900 new_range
->assem_name
= xstrdup (func_name
);
905 long last
= strtol (end_val
, &invalid
, 10);
906 if (*invalid
|| last
< start
)
908 error ("Invalid range %s in option %s",
910 is_enable
? "-fenable" : "-fdisable");
914 new_range
= XCNEW (struct uid_range
);
915 new_range
->start
= (unsigned) start
;
916 new_range
->last
= (unsigned) last
;
919 slot
= (*tab
)[pass
->static_pass_number
];
920 new_range
->next
= slot
;
921 (*tab
)[pass
->static_pass_number
] = new_range
;
924 if (new_range
->assem_name
)
925 inform (UNKNOWN_LOCATION
,
926 "enable pass %s for function %s",
927 phase_name
, new_range
->assem_name
);
929 inform (UNKNOWN_LOCATION
,
930 "enable pass %s for functions in the range of [%u, %u]",
931 phase_name
, new_range
->start
, new_range
->last
);
935 if (new_range
->assem_name
)
936 inform (UNKNOWN_LOCATION
,
937 "disable pass %s for function %s",
938 phase_name
, new_range
->assem_name
);
940 inform (UNKNOWN_LOCATION
,
941 "disable pass %s for functions in the range of [%u, %u]",
942 phase_name
, new_range
->start
, new_range
->last
);
945 one_range
= next_range
;
946 } while (next_range
);
952 /* Enable pass specified by ARG. */
955 enable_pass (const char *arg
)
957 enable_disable_pass (arg
, true);
960 /* Disable pass specified by ARG. */
963 disable_pass (const char *arg
)
965 enable_disable_pass (arg
, false);
968 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
971 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
973 vec
<uid_range_p
> tab
)
975 uid_range_p slot
, range
;
977 const char *aname
= NULL
;
980 || (unsigned) pass
->static_pass_number
>= tab
.length ()
981 || pass
->static_pass_number
== -1)
984 slot
= tab
[pass
->static_pass_number
];
988 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
989 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
990 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
995 if ((unsigned) cgraph_uid
>= range
->start
996 && (unsigned) cgraph_uid
<= range
->last
)
998 if (range
->assem_name
&& aname
999 && !strcmp (range
->assem_name
, aname
))
1001 range
= range
->next
;
1007 /* Look at the static_pass_number and duplicate the pass
1008 if it is already added to a list. */
1010 static struct opt_pass
*
1011 make_pass_instance (struct opt_pass
*pass
, bool track_duplicates
)
1013 /* A nonzero static_pass_number indicates that the
1014 pass is already in the list. */
1015 if (pass
->static_pass_number
)
1017 struct opt_pass
*new_pass
;
1019 if (pass
->type
== GIMPLE_PASS
1020 || pass
->type
== RTL_PASS
1021 || pass
->type
== SIMPLE_IPA_PASS
)
1023 new_pass
= XNEW (struct opt_pass
);
1024 memcpy (new_pass
, pass
, sizeof (struct opt_pass
));
1026 else if (pass
->type
== IPA_PASS
)
1028 new_pass
= (struct opt_pass
*)XNEW (struct ipa_opt_pass_d
);
1029 memcpy (new_pass
, pass
, sizeof (struct ipa_opt_pass_d
));
1034 new_pass
->next
= NULL
;
1036 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1038 /* Indicate to register_dump_files that this pass has duplicates,
1039 and so it should rename the dump file. The first instance will
1040 be -1, and be number of duplicates = -static_pass_number - 1.
1041 Subsequent instances will be > 0 and just the duplicate number. */
1042 if ((pass
->name
&& pass
->name
[0] != '*') || track_duplicates
)
1044 pass
->static_pass_number
-= 1;
1045 new_pass
->static_pass_number
= -pass
->static_pass_number
;
1051 pass
->todo_flags_start
|= TODO_mark_first_instance
;
1052 pass
->static_pass_number
= -1;
1054 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, pass
);
1059 /* Add a pass to the pass list. Duplicate the pass if it's already
1062 static struct opt_pass
**
1063 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
)
1065 /* Every pass should have a name so that plugins can refer to them. */
1066 gcc_assert (pass
->name
!= NULL
);
1068 *list
= make_pass_instance (pass
, false);
1070 return &(*list
)->next
;
1073 /* List node for an inserted pass instance. We need to keep track of all
1074 the newly-added pass instances (with 'added_pass_nodes' defined below)
1075 so that we can register their dump files after pass-positioning is finished.
1076 Registering dumping files needs to be post-processed or the
1077 static_pass_number of the opt_pass object would be modified and mess up
1078 the dump file names of future pass instances to be added. */
1080 struct pass_list_node
1082 struct opt_pass
*pass
;
1083 struct pass_list_node
*next
;
1086 static struct pass_list_node
*added_pass_nodes
= NULL
;
1087 static struct pass_list_node
*prev_added_pass_node
;
1089 /* Insert the pass at the proper position. Return true if the pass
1090 is successfully added.
1092 NEW_PASS_INFO - new pass to be inserted
1093 PASS_LIST - root of the pass list to insert the new pass to */
1096 position_pass (struct register_pass_info
*new_pass_info
,
1097 struct opt_pass
**pass_list
)
1099 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1100 bool success
= false;
1102 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1104 /* Check if the current pass is of the same type as the new pass and
1105 matches the name and the instance number of the reference pass. */
1106 if (pass
->type
== new_pass_info
->pass
->type
1108 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1109 && ((new_pass_info
->ref_pass_instance_number
== 0)
1110 || (new_pass_info
->ref_pass_instance_number
==
1111 pass
->static_pass_number
)
1112 || (new_pass_info
->ref_pass_instance_number
== 1
1113 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1115 struct opt_pass
*new_pass
;
1116 struct pass_list_node
*new_pass_node
;
1118 new_pass
= make_pass_instance (new_pass_info
->pass
, true);
1120 /* Insert the new pass instance based on the positioning op. */
1121 switch (new_pass_info
->pos_op
)
1123 case PASS_POS_INSERT_AFTER
:
1124 new_pass
->next
= pass
->next
;
1125 pass
->next
= new_pass
;
1127 /* Skip newly inserted pass to avoid repeated
1128 insertions in the case where the new pass and the
1129 existing one have the same name. */
1132 case PASS_POS_INSERT_BEFORE
:
1133 new_pass
->next
= pass
;
1135 prev_pass
->next
= new_pass
;
1137 *pass_list
= new_pass
;
1139 case PASS_POS_REPLACE
:
1140 new_pass
->next
= pass
->next
;
1142 prev_pass
->next
= new_pass
;
1144 *pass_list
= new_pass
;
1145 new_pass
->sub
= pass
->sub
;
1146 new_pass
->tv_id
= pass
->tv_id
;
1150 error ("invalid pass positioning operation");
1154 /* Save the newly added pass (instance) in the added_pass_nodes
1155 list so that we can register its dump file later. Note that
1156 we cannot register the dump file now because doing so will modify
1157 the static_pass_number of the opt_pass object and therefore
1158 mess up the dump file name of future instances. */
1159 new_pass_node
= XCNEW (struct pass_list_node
);
1160 new_pass_node
->pass
= new_pass
;
1161 if (!added_pass_nodes
)
1162 added_pass_nodes
= new_pass_node
;
1164 prev_added_pass_node
->next
= new_pass_node
;
1165 prev_added_pass_node
= new_pass_node
;
1170 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1177 /* Hooks a new pass into the pass lists.
1179 PASS_INFO - pass information that specifies the opt_pass object,
1180 reference pass, instance number, and how to position
1184 register_pass (struct register_pass_info
*pass_info
)
1186 bool all_instances
, success
;
1188 /* The checks below could fail in buggy plugins. Existing GCC
1189 passes should never fail these checks, so we mention plugin in
1191 if (!pass_info
->pass
)
1192 fatal_error ("plugin cannot register a missing pass");
1194 if (!pass_info
->pass
->name
)
1195 fatal_error ("plugin cannot register an unnamed pass");
1197 if (!pass_info
->reference_pass_name
)
1199 ("plugin cannot register pass %qs without reference pass name",
1200 pass_info
->pass
->name
);
1202 /* Try to insert the new pass to the pass lists. We need to check
1203 all five lists as the reference pass could be in one (or all) of
1205 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1206 success
= position_pass (pass_info
, &all_lowering_passes
);
1207 if (!success
|| all_instances
)
1208 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1209 if (!success
|| all_instances
)
1210 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1211 if (!success
|| all_instances
)
1212 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1213 if (!success
|| all_instances
)
1214 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1215 if (!success
|| all_instances
)
1216 success
|= position_pass (pass_info
, &all_passes
);
1219 ("pass %qs not found but is referenced by new pass %qs",
1220 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1222 /* OK, we have successfully inserted the new pass. We need to register
1223 the dump files for the newly added pass and its duplicates (if any).
1224 Because the registration of plugin/backend passes happens after the
1225 command-line options are parsed, the options that specify single
1226 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1227 passes. Therefore we currently can only enable dumping of
1228 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1229 are specified. While doing so, we also delete the pass_list_node
1230 objects created during pass positioning. */
1231 while (added_pass_nodes
)
1233 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1234 enum tree_dump_index tdi
;
1235 register_one_dump_file (added_pass_nodes
->pass
);
1236 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1237 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1239 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1243 /* Check if dump-all flag is specified. */
1244 if (get_dump_file_info (tdi
)->pstate
)
1245 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1246 ->pstate
= get_dump_file_info (tdi
)->pstate
;
1247 XDELETE (added_pass_nodes
);
1248 added_pass_nodes
= next_node
;
1252 /* Construct the pass tree. The sequencing of passes is driven by
1253 the cgraph routines:
1255 finalize_compilation_unit ()
1256 for each node N in the cgraph
1257 cgraph_analyze_function (N)
1258 cgraph_lower_function (N) -> all_lowering_passes
1260 If we are optimizing, compile is then invoked:
1263 ipa_passes () -> all_small_ipa_passes
1264 -> Analysis of all_regular_ipa_passes
1265 * possible LTO streaming at copmilation time *
1266 -> Execution of all_regular_ipa_passes
1267 * possible LTO streaming at link time *
1268 -> all_late_ipa_passes
1269 expand_all_functions ()
1270 for each node N in the cgraph
1271 expand_function (N) -> Transformation of all_regular_ipa_passes
1276 init_optimization_passes (void)
1278 struct opt_pass
**p
;
1280 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1282 /* All passes needed to lower the function into shape optimizers can
1283 operate on. These passes are always run first on the function, but
1284 backend might produce already lowered functions that are not processed
1286 p
= &all_lowering_passes
;
1287 NEXT_PASS (pass_warn_unused_result
);
1288 NEXT_PASS (pass_diagnose_omp_blocks
);
1289 NEXT_PASS (pass_diagnose_tm_blocks
);
1290 NEXT_PASS (pass_mudflap_1
);
1291 NEXT_PASS (pass_lower_omp
);
1292 NEXT_PASS (pass_lower_cf
);
1293 NEXT_PASS (pass_lower_tm
);
1294 NEXT_PASS (pass_refactor_eh
);
1295 NEXT_PASS (pass_lower_eh
);
1296 NEXT_PASS (pass_build_cfg
);
1297 NEXT_PASS (pass_warn_function_return
);
1298 NEXT_PASS (pass_build_cgraph_edges
);
1301 /* Interprocedural optimization passes. */
1302 p
= &all_small_ipa_passes
;
1303 NEXT_PASS (pass_ipa_free_lang_data
);
1304 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
1305 NEXT_PASS (pass_early_local_passes
);
1307 struct opt_pass
**p
= &pass_early_local_passes
.pass
.sub
;
1308 NEXT_PASS (pass_fixup_cfg
);
1309 NEXT_PASS (pass_init_datastructures
);
1310 NEXT_PASS (pass_expand_omp
);
1312 NEXT_PASS (pass_build_ssa
);
1313 NEXT_PASS (pass_lower_vector
);
1314 NEXT_PASS (pass_early_warn_uninitialized
);
1315 NEXT_PASS (pass_rebuild_cgraph_edges
);
1316 NEXT_PASS (pass_inline_parameters
);
1317 NEXT_PASS (pass_early_inline
);
1318 NEXT_PASS (pass_all_early_optimizations
);
1320 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1321 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1322 NEXT_PASS (pass_rename_ssa_copies
);
1323 NEXT_PASS (pass_ccp
);
1324 /* After CCP we rewrite no longer addressed locals into SSA
1325 form if possible. */
1326 NEXT_PASS (pass_forwprop
);
1327 /* pass_build_ealias is a dummy pass that ensures that we
1328 execute TODO_rebuild_alias at this point. */
1329 NEXT_PASS (pass_build_ealias
);
1330 NEXT_PASS (pass_sra_early
);
1331 NEXT_PASS (pass_fre
);
1332 NEXT_PASS (pass_copy_prop
);
1333 NEXT_PASS (pass_merge_phi
);
1334 NEXT_PASS (pass_cd_dce
);
1335 NEXT_PASS (pass_early_ipa_sra
);
1336 NEXT_PASS (pass_tail_recursion
);
1337 NEXT_PASS (pass_convert_switch
);
1338 NEXT_PASS (pass_cleanup_eh
);
1339 NEXT_PASS (pass_profile
);
1340 NEXT_PASS (pass_local_pure_const
);
1341 /* Split functions creates parts that are not run through
1342 early optimizations again. It is thus good idea to do this
1344 NEXT_PASS (pass_split_functions
);
1346 NEXT_PASS (pass_release_ssa_names
);
1347 NEXT_PASS (pass_rebuild_cgraph_edges
);
1348 NEXT_PASS (pass_inline_parameters
);
1350 NEXT_PASS (pass_ipa_free_inline_summary
);
1351 NEXT_PASS (pass_ipa_tree_profile
);
1353 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1354 NEXT_PASS (pass_feedback_split_functions
);
1356 NEXT_PASS (pass_ipa_increase_alignment
);
1357 NEXT_PASS (pass_ipa_tm
);
1358 NEXT_PASS (pass_ipa_lower_emutls
);
1361 p
= &all_regular_ipa_passes
;
1362 NEXT_PASS (pass_ipa_whole_program_visibility
);
1363 NEXT_PASS (pass_ipa_profile
);
1364 NEXT_PASS (pass_ipa_cp
);
1365 NEXT_PASS (pass_ipa_cdtor_merge
);
1366 NEXT_PASS (pass_ipa_inline
);
1367 NEXT_PASS (pass_ipa_pure_const
);
1368 NEXT_PASS (pass_ipa_reference
);
1371 p
= &all_lto_gen_passes
;
1372 NEXT_PASS (pass_ipa_lto_gimple_out
);
1373 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1376 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1377 passes are executed after partitioning and thus see just parts of the
1379 p
= &all_late_ipa_passes
;
1380 NEXT_PASS (pass_ipa_pta
);
1383 /* These passes are run after IPA passes on every function that is being
1384 output to the assembler file. */
1386 NEXT_PASS (pass_fixup_cfg
);
1387 NEXT_PASS (pass_lower_eh_dispatch
);
1388 NEXT_PASS (pass_all_optimizations
);
1390 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1391 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1392 /* Initial scalar cleanups before alias computation.
1393 They ensure memory accesses are not indirect wherever possible. */
1394 NEXT_PASS (pass_strip_predict_hints
);
1395 NEXT_PASS (pass_rename_ssa_copies
);
1396 NEXT_PASS (pass_complete_unrolli
);
1397 NEXT_PASS (pass_ccp
);
1398 /* After CCP we rewrite no longer addressed locals into SSA
1399 form if possible. */
1400 NEXT_PASS (pass_forwprop
);
1401 /* pass_build_alias is a dummy pass that ensures that we
1402 execute TODO_rebuild_alias at this point. */
1403 NEXT_PASS (pass_build_alias
);
1404 NEXT_PASS (pass_return_slot
);
1405 NEXT_PASS (pass_phiprop
);
1406 NEXT_PASS (pass_fre
);
1407 NEXT_PASS (pass_copy_prop
);
1408 NEXT_PASS (pass_merge_phi
);
1409 NEXT_PASS (pass_vrp
);
1410 NEXT_PASS (pass_dce
);
1411 NEXT_PASS (pass_call_cdce
);
1412 NEXT_PASS (pass_cselim
);
1413 NEXT_PASS (pass_tree_ifcombine
);
1414 NEXT_PASS (pass_phiopt
);
1415 NEXT_PASS (pass_tail_recursion
);
1416 NEXT_PASS (pass_ch
);
1417 NEXT_PASS (pass_stdarg
);
1418 NEXT_PASS (pass_lower_complex
);
1419 NEXT_PASS (pass_sra
);
1420 NEXT_PASS (pass_rename_ssa_copies
);
1421 /* The dom pass will also resolve all __builtin_constant_p calls
1422 that are still there to 0. This has to be done after some
1423 propagations have already run, but before some more dead code
1424 is removed, and this place fits nicely. Remember this when
1425 trying to move or duplicate pass_dominator somewhere earlier. */
1426 NEXT_PASS (pass_dominator
);
1427 /* The only const/copy propagation opportunities left after
1428 DOM should be due to degenerate PHI nodes. So rather than
1429 run the full propagators, run a specialized pass which
1430 only examines PHIs to discover const/copy propagation
1432 NEXT_PASS (pass_phi_only_cprop
);
1433 NEXT_PASS (pass_dse
);
1434 NEXT_PASS (pass_reassoc
);
1435 NEXT_PASS (pass_dce
);
1436 NEXT_PASS (pass_forwprop
);
1437 NEXT_PASS (pass_phiopt
);
1438 NEXT_PASS (pass_object_sizes
);
1439 NEXT_PASS (pass_strlen
);
1440 NEXT_PASS (pass_ccp
);
1441 /* After CCP we rewrite no longer addressed locals into SSA
1442 form if possible. */
1443 NEXT_PASS (pass_copy_prop
);
1444 NEXT_PASS (pass_cse_sincos
);
1445 NEXT_PASS (pass_optimize_bswap
);
1446 NEXT_PASS (pass_split_crit_edges
);
1447 NEXT_PASS (pass_pre
);
1448 NEXT_PASS (pass_sink_code
);
1449 NEXT_PASS (pass_asan
);
1450 NEXT_PASS (pass_tsan
);
1451 NEXT_PASS (pass_tree_loop
);
1453 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1454 NEXT_PASS (pass_tree_loop_init
);
1455 NEXT_PASS (pass_lim
);
1456 NEXT_PASS (pass_copy_prop
);
1457 NEXT_PASS (pass_dce_loop
);
1458 NEXT_PASS (pass_tree_unswitch
);
1459 NEXT_PASS (pass_scev_cprop
);
1460 NEXT_PASS (pass_record_bounds
);
1461 NEXT_PASS (pass_check_data_deps
);
1462 NEXT_PASS (pass_loop_distribution
);
1463 NEXT_PASS (pass_copy_prop
);
1464 NEXT_PASS (pass_graphite
);
1466 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1467 NEXT_PASS (pass_graphite_transforms
);
1468 NEXT_PASS (pass_lim
);
1469 NEXT_PASS (pass_copy_prop
);
1470 NEXT_PASS (pass_dce_loop
);
1472 NEXT_PASS (pass_iv_canon
);
1473 NEXT_PASS (pass_if_conversion
);
1474 NEXT_PASS (pass_vectorize
);
1476 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1477 NEXT_PASS (pass_dce_loop
);
1479 NEXT_PASS (pass_predcom
);
1480 NEXT_PASS (pass_complete_unroll
);
1481 NEXT_PASS (pass_slp_vectorize
);
1482 NEXT_PASS (pass_parallelize_loops
);
1483 NEXT_PASS (pass_loop_prefetch
);
1484 NEXT_PASS (pass_iv_optimize
);
1485 NEXT_PASS (pass_lim
);
1486 NEXT_PASS (pass_tree_loop_done
);
1488 NEXT_PASS (pass_lower_vector_ssa
);
1489 NEXT_PASS (pass_cse_reciprocals
);
1490 NEXT_PASS (pass_reassoc
);
1491 NEXT_PASS (pass_vrp
);
1492 NEXT_PASS (pass_strength_reduction
);
1493 NEXT_PASS (pass_dominator
);
1494 /* The only const/copy propagation opportunities left after
1495 DOM should be due to degenerate PHI nodes. So rather than
1496 run the full propagators, run a specialized pass which
1497 only examines PHIs to discover const/copy propagation
1499 NEXT_PASS (pass_phi_only_cprop
);
1500 NEXT_PASS (pass_cd_dce
);
1501 NEXT_PASS (pass_tracer
);
1503 /* FIXME: If DCE is not run before checking for uninitialized uses,
1504 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1505 However, this also causes us to misdiagnose cases that should be
1506 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1508 To fix the false positives in uninit-5.c, we would have to
1509 account for the predicates protecting the set and the use of each
1510 variable. Using a representation like Gated Single Assignment
1512 NEXT_PASS (pass_late_warn_uninitialized
);
1513 NEXT_PASS (pass_dse
);
1514 NEXT_PASS (pass_forwprop
);
1515 NEXT_PASS (pass_phiopt
);
1516 NEXT_PASS (pass_fold_builtins
);
1517 NEXT_PASS (pass_optimize_widening_mul
);
1518 NEXT_PASS (pass_tail_calls
);
1519 NEXT_PASS (pass_rename_ssa_copies
);
1520 NEXT_PASS (pass_uncprop
);
1521 NEXT_PASS (pass_local_pure_const
);
1523 NEXT_PASS (pass_all_optimizations_g
);
1525 struct opt_pass
**p
= &pass_all_optimizations_g
.pass
.sub
;
1526 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1527 NEXT_PASS (pass_strip_predict_hints
);
1528 /* Lower remaining pieces of GIMPLE. */
1529 NEXT_PASS (pass_lower_complex
);
1530 NEXT_PASS (pass_lower_vector_ssa
);
1531 /* Perform simple scalar cleanup which is constant/copy propagation. */
1532 NEXT_PASS (pass_ccp
);
1533 NEXT_PASS (pass_object_sizes
);
1534 /* Copy propagation also copy-propagates constants, this is necessary
1535 to forward object-size results properly. */
1536 NEXT_PASS (pass_copy_prop
);
1537 NEXT_PASS (pass_asan
);
1538 NEXT_PASS (pass_tsan
);
1539 NEXT_PASS (pass_rename_ssa_copies
);
1540 NEXT_PASS (pass_dce
);
1541 /* Fold remaining builtins. */
1542 NEXT_PASS (pass_fold_builtins
);
1543 /* ??? We do want some kind of loop invariant motion, but we possibly
1544 need to adjust LIM to be more friendly towards preserving accurate
1545 debug information here. */
1546 NEXT_PASS (pass_late_warn_uninitialized
);
1547 NEXT_PASS (pass_uncprop
);
1548 NEXT_PASS (pass_local_pure_const
);
1550 NEXT_PASS (pass_tm_init
);
1552 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1553 NEXT_PASS (pass_tm_mark
);
1554 NEXT_PASS (pass_tm_memopt
);
1555 NEXT_PASS (pass_tm_edges
);
1557 NEXT_PASS (pass_lower_complex_O0
);
1558 NEXT_PASS (pass_asan_O0
);
1559 NEXT_PASS (pass_tsan_O0
);
1560 NEXT_PASS (pass_cleanup_eh
);
1561 NEXT_PASS (pass_lower_resx
);
1562 NEXT_PASS (pass_nrv
);
1563 NEXT_PASS (pass_mudflap_2
);
1564 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
1565 NEXT_PASS (pass_warn_function_noreturn
);
1567 NEXT_PASS (pass_expand
);
1569 NEXT_PASS (pass_rest_of_compilation
);
1571 struct opt_pass
**p
= &pass_rest_of_compilation
.pass
.sub
;
1572 NEXT_PASS (pass_instantiate_virtual_regs
);
1573 NEXT_PASS (pass_into_cfg_layout_mode
);
1574 NEXT_PASS (pass_jump
);
1575 NEXT_PASS (pass_lower_subreg
);
1576 NEXT_PASS (pass_df_initialize_opt
);
1577 NEXT_PASS (pass_cse
);
1578 NEXT_PASS (pass_rtl_fwprop
);
1579 NEXT_PASS (pass_rtl_cprop
);
1580 NEXT_PASS (pass_rtl_pre
);
1581 NEXT_PASS (pass_rtl_hoist
);
1582 NEXT_PASS (pass_rtl_cprop
);
1583 NEXT_PASS (pass_rtl_store_motion
);
1584 NEXT_PASS (pass_cse_after_global_opts
);
1585 NEXT_PASS (pass_rtl_ifcvt
);
1586 NEXT_PASS (pass_reginfo_init
);
1587 /* Perform loop optimizations. It might be better to do them a bit
1588 sooner, but we want the profile feedback to work more
1590 NEXT_PASS (pass_loop2
);
1592 struct opt_pass
**p
= &pass_loop2
.pass
.sub
;
1593 NEXT_PASS (pass_rtl_loop_init
);
1594 NEXT_PASS (pass_rtl_move_loop_invariants
);
1595 NEXT_PASS (pass_rtl_unswitch
);
1596 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
1597 NEXT_PASS (pass_rtl_doloop
);
1598 NEXT_PASS (pass_rtl_loop_done
);
1601 NEXT_PASS (pass_web
);
1602 NEXT_PASS (pass_rtl_cprop
);
1603 NEXT_PASS (pass_cse2
);
1604 NEXT_PASS (pass_rtl_dse1
);
1605 NEXT_PASS (pass_rtl_fwprop_addr
);
1606 NEXT_PASS (pass_inc_dec
);
1607 NEXT_PASS (pass_initialize_regs
);
1608 NEXT_PASS (pass_ud_rtl_dce
);
1609 NEXT_PASS (pass_combine
);
1610 NEXT_PASS (pass_if_after_combine
);
1611 NEXT_PASS (pass_partition_blocks
);
1612 NEXT_PASS (pass_regmove
);
1613 NEXT_PASS (pass_outof_cfg_layout_mode
);
1614 NEXT_PASS (pass_split_all_insns
);
1615 NEXT_PASS (pass_lower_subreg2
);
1616 NEXT_PASS (pass_df_initialize_no_opt
);
1617 NEXT_PASS (pass_stack_ptr_mod
);
1618 NEXT_PASS (pass_mode_switching
);
1619 NEXT_PASS (pass_match_asm_constraints
);
1620 NEXT_PASS (pass_sms
);
1621 NEXT_PASS (pass_sched
);
1622 NEXT_PASS (pass_ira
);
1623 NEXT_PASS (pass_reload
);
1624 NEXT_PASS (pass_postreload
);
1626 struct opt_pass
**p
= &pass_postreload
.pass
.sub
;
1627 NEXT_PASS (pass_postreload_cse
);
1628 NEXT_PASS (pass_gcse2
);
1629 NEXT_PASS (pass_split_after_reload
);
1630 NEXT_PASS (pass_ree
);
1631 NEXT_PASS (pass_compare_elim_after_reload
);
1632 NEXT_PASS (pass_branch_target_load_optimize1
);
1633 NEXT_PASS (pass_thread_prologue_and_epilogue
);
1634 NEXT_PASS (pass_rtl_dse2
);
1635 NEXT_PASS (pass_stack_adjustments
);
1636 NEXT_PASS (pass_jump2
);
1637 NEXT_PASS (pass_peephole2
);
1638 NEXT_PASS (pass_if_after_reload
);
1639 NEXT_PASS (pass_regrename
);
1640 NEXT_PASS (pass_cprop_hardreg
);
1641 NEXT_PASS (pass_fast_rtl_dce
);
1642 NEXT_PASS (pass_reorder_blocks
);
1643 NEXT_PASS (pass_branch_target_load_optimize2
);
1644 NEXT_PASS (pass_leaf_regs
);
1645 NEXT_PASS (pass_split_before_sched2
);
1646 NEXT_PASS (pass_sched2
);
1647 NEXT_PASS (pass_stack_regs
);
1649 struct opt_pass
**p
= &pass_stack_regs
.pass
.sub
;
1650 NEXT_PASS (pass_split_before_regstack
);
1651 NEXT_PASS (pass_stack_regs_run
);
1653 NEXT_PASS (pass_compute_alignments
);
1654 NEXT_PASS (pass_duplicate_computed_gotos
);
1655 NEXT_PASS (pass_variable_tracking
);
1656 NEXT_PASS (pass_free_cfg
);
1657 NEXT_PASS (pass_machine_reorg
);
1658 NEXT_PASS (pass_cleanup_barriers
);
1659 NEXT_PASS (pass_delay_slots
);
1660 NEXT_PASS (pass_split_for_shorten_branches
);
1661 NEXT_PASS (pass_convert_to_eh_region_ranges
);
1662 NEXT_PASS (pass_shorten_branches
);
1663 NEXT_PASS (pass_set_nothrow_function_flags
);
1664 NEXT_PASS (pass_dwarf2_frame
);
1665 NEXT_PASS (pass_final
);
1667 NEXT_PASS (pass_df_finish
);
1669 NEXT_PASS (pass_clean_state
);
1674 /* Register the passes with the tree dump code. */
1675 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1676 register_dump_files (all_small_ipa_passes
,
1677 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1679 register_dump_files (all_regular_ipa_passes
,
1680 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1682 register_dump_files (all_lto_gen_passes
,
1683 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1685 register_dump_files (all_late_ipa_passes
,
1686 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1688 register_dump_files (all_passes
,
1689 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1693 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1694 function CALLBACK for every function in the call graph. Otherwise,
1695 call CALLBACK on the current function. */
1698 do_per_function (void (*callback
) (void *data
), void *data
)
1700 if (current_function_decl
)
1704 struct cgraph_node
*node
;
1705 FOR_EACH_DEFINED_FUNCTION (node
)
1706 if (gimple_has_body_p (node
->symbol
.decl
)
1707 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1709 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1713 free_dominance_info (CDI_DOMINATORS
);
1714 free_dominance_info (CDI_POST_DOMINATORS
);
1722 /* Because inlining might remove no-longer reachable nodes, we need to
1723 keep the array visible to garbage collector to avoid reading collected
1726 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1728 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1729 function CALLBACK for every function in the call graph. Otherwise,
1730 call CALLBACK on the current function.
1731 This function is global so that plugins can use it. */
1733 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1737 if (current_function_decl
)
1741 gcc_assert (!order
);
1742 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1743 nnodes
= ipa_reverse_postorder (order
);
1744 for (i
= nnodes
- 1; i
>= 0; i
--)
1745 order
[i
]->process
= 1;
1746 for (i
= nnodes
- 1; i
>= 0; i
--)
1748 struct cgraph_node
*node
= order
[i
];
1750 /* Allow possibly removed nodes to be garbage collected. */
1753 if (cgraph_function_with_gimple_body_p (node
))
1755 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1757 free_dominance_info (CDI_DOMINATORS
);
1758 free_dominance_info (CDI_POST_DOMINATORS
);
1769 /* Helper function to perform function body dump. */
1772 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1774 if (dump_file
&& current_function_decl
)
1776 if (cfun
->curr_properties
& PROP_trees
)
1777 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1779 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1781 /* Flush the file. If verification fails, we won't be able to
1782 close the file before aborting. */
1785 if ((cfun
->curr_properties
& PROP_cfg
)
1786 && (dump_flags
& TDF_GRAPH
))
1787 print_graph_cfg (dump_file_name
, cfun
);
1791 static struct profile_record
*profile_record
;
1793 /* Do profile consistency book-keeping for the pass with static number INDEX.
1794 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1795 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1796 if we are only book-keeping on passes that may have selectively disabled
1797 themselves on a given function. */
1799 check_profile_consistency (int index
, int subpass
, bool run
)
1803 if (!profile_record
)
1804 profile_record
= XCNEWVEC (struct profile_record
,
1806 gcc_assert (index
< passes_by_id_size
&& index
>= 0);
1807 gcc_assert (subpass
< 2);
1808 profile_record
[index
].run
|= run
;
1809 account_profile_record (&profile_record
[index
], subpass
);
1812 /* Output profile consistency. */
1815 dump_profile_report (void)
1818 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1819 gcov_type last_time
= 0, last_size
= 0;
1820 double rel_time_change
, rel_size_change
;
1821 int last_reported
= 0;
1823 if (!profile_record
)
1825 fprintf (stderr
, "\nProfile consistency report:\n\n");
1826 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1827 fprintf (stderr
, " |freq count |freq count |size time\n");
1829 for (i
= 0; i
< passes_by_id_size
; i
++)
1830 for (j
= 0 ; j
< 2; j
++)
1831 if (profile_record
[i
].run
)
1834 rel_time_change
= (profile_record
[i
].time
[j
]
1835 - (double)last_time
) * 100 / (double)last_time
;
1837 rel_time_change
= 0;
1839 rel_size_change
= (profile_record
[i
].size
[j
]
1840 - (double)last_size
) * 100 / (double)last_size
;
1842 rel_size_change
= 0;
1844 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1845 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1846 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1847 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1848 || rel_time_change
|| rel_size_change
)
1851 fprintf (stderr
, "%-20s %s",
1852 passes_by_id
[i
]->name
,
1853 j
? "(after TODO)" : " ");
1854 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1855 fprintf (stderr
, "| %+5i",
1856 profile_record
[i
].num_mismatched_freq_in
[j
]
1859 fprintf (stderr
, "| ");
1860 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1861 fprintf (stderr
, " %+5i",
1862 profile_record
[i
].num_mismatched_count_in
[j
]
1865 fprintf (stderr
, " ");
1866 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1867 fprintf (stderr
, "| %+5i",
1868 profile_record
[i
].num_mismatched_freq_out
[j
]
1871 fprintf (stderr
, "| ");
1872 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1873 fprintf (stderr
, " %+5i",
1874 profile_record
[i
].num_mismatched_count_out
[j
]
1877 fprintf (stderr
, " ");
1879 /* Size/time units change across gimple and RTL. */
1880 if (i
== pass_expand
.pass
.static_pass_number
)
1881 fprintf (stderr
, "|----------");
1884 if (rel_size_change
)
1885 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1887 fprintf (stderr
, "| ");
1888 if (rel_time_change
)
1889 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1891 fprintf (stderr
, "\n");
1892 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1893 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1894 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1895 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1897 else if (j
&& last_reported
!= i
)
1900 fprintf (stderr
, "%-20s ------------| | |\n",
1901 passes_by_id
[i
]->name
);
1903 last_time
= profile_record
[i
].time
[j
];
1904 last_size
= profile_record
[i
].size
[j
];
1908 /* Perform all TODO actions that ought to be done on each function. */
1911 execute_function_todo (void *data
)
1913 unsigned int flags
= (size_t)data
;
1914 flags
&= ~cfun
->last_verified
;
1918 /* Always cleanup the CFG before trying to update SSA. */
1919 if (flags
& TODO_cleanup_cfg
)
1921 cleanup_tree_cfg ();
1923 /* When cleanup_tree_cfg merges consecutive blocks, it may
1924 perform some simplistic propagation when removing single
1925 valued PHI nodes. This propagation may, in turn, cause the
1926 SSA form to become out-of-date (see PR 22037). So, even
1927 if the parent pass had not scheduled an SSA update, we may
1928 still need to do one. */
1929 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1930 flags
|= TODO_update_ssa
;
1933 if (flags
& TODO_update_ssa_any
)
1935 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1936 update_ssa (update_flags
);
1937 cfun
->last_verified
&= ~TODO_verify_ssa
;
1940 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1941 compute_may_aliases ();
1943 if (optimize
&& (flags
& TODO_update_address_taken
))
1944 execute_update_addresses_taken ();
1946 if (flags
& TODO_remove_unused_locals
)
1947 remove_unused_locals ();
1949 if (flags
& TODO_rebuild_frequencies
)
1950 rebuild_frequencies ();
1952 if (flags
& TODO_rebuild_cgraph_edges
)
1953 rebuild_cgraph_edges ();
1955 /* If we've seen errors do not bother running any verifiers. */
1959 #if defined ENABLE_CHECKING
1960 if (flags
& TODO_verify_ssa
1961 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1963 verify_gimple_in_cfg (cfun
);
1966 else if (flags
& TODO_verify_stmts
)
1967 verify_gimple_in_cfg (cfun
);
1968 if (flags
& TODO_verify_flow
)
1969 verify_flow_info ();
1970 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1971 verify_loop_closed_ssa (false);
1972 if (flags
& TODO_verify_rtl_sharing
)
1973 verify_rtl_sharing ();
1976 cfun
->last_verified
= flags
& TODO_verify_all
;
1979 /* Perform all TODO actions. */
1981 execute_todo (unsigned int flags
)
1983 #if defined ENABLE_CHECKING
1985 && need_ssa_update_p (cfun
))
1986 gcc_assert (flags
& TODO_update_ssa_any
);
1989 timevar_push (TV_TODO
);
1991 /* Inform the pass whether it is the first time it is run. */
1992 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1994 statistics_fini_pass ();
1996 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1998 /* Always remove functions just as before inlining: IPA passes might be
1999 interested to see bodies of extern inline functions that are not inlined
2000 to analyze side effects. The full removal is done just at the end
2001 of IPA pass queue. */
2002 if (flags
& TODO_remove_functions
)
2005 symtab_remove_unreachable_nodes (true, dump_file
);
2008 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2011 dump_symtab (dump_file
);
2012 /* Flush the file. If verification fails, we won't be able to
2013 close the file before aborting. */
2017 if (flags
& TODO_ggc_collect
)
2020 /* Now that the dumping has been done, we can get rid of the optional
2022 if (flags
& TODO_df_finish
)
2023 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2025 timevar_pop (TV_TODO
);
2028 /* Verify invariants that should hold between passes. This is a place
2029 to put simple sanity checks. */
2032 verify_interpass_invariants (void)
2034 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2037 /* Clear the last verified flag. */
2040 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
2042 cfun
->last_verified
= 0;
2045 /* Helper function. Verify that the properties has been turn into the
2046 properties expected by the pass. */
2048 #ifdef ENABLE_CHECKING
2050 verify_curr_properties (void *data
)
2052 unsigned int props
= (size_t)data
;
2053 gcc_assert ((cfun
->curr_properties
& props
) == props
);
2057 /* Initialize pass dump file. */
2058 /* This is non-static so that the plugins can use it. */
2061 pass_init_dump_file (struct opt_pass
*pass
)
2063 /* If a dump file name is present, open it if enabled. */
2064 if (pass
->static_pass_number
!= -1)
2066 timevar_push (TV_DUMP
);
2067 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
2068 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
2069 dump_start (pass
->static_pass_number
, &dump_flags
);
2070 if (dump_file
&& current_function_decl
)
2071 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2072 if (initializing_dump
2073 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2074 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2075 clean_graph_dump_file (dump_file_name
);
2076 timevar_pop (TV_DUMP
);
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 timevar_push (TV_DUMP
);
2091 /* Flush and close dump file. */
2094 free (CONST_CAST (char *, dump_file_name
));
2095 dump_file_name
= NULL
;
2098 dump_finish (pass
->static_pass_number
);
2099 timevar_pop (TV_DUMP
);
2102 /* After executing the pass, apply expected changes to the function
2106 update_properties_after_pass (void *data
)
2108 struct opt_pass
*pass
= (struct opt_pass
*) data
;
2109 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
2110 & ~pass
->properties_destroyed
;
2113 /* Execute summary generation for all of the passes in IPA_PASS. */
2116 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
2120 struct opt_pass
*pass
= &ipa_pass
->pass
;
2122 /* Execute all of the IPA_PASSes in the list. */
2123 if (ipa_pass
->pass
.type
== IPA_PASS
2124 && (!pass
->gate
|| pass
->gate ())
2125 && ipa_pass
->generate_summary
)
2127 pass_init_dump_file (pass
);
2129 /* If a timevar is present, start it. */
2131 timevar_push (pass
->tv_id
);
2133 ipa_pass
->generate_summary ();
2137 timevar_pop (pass
->tv_id
);
2139 pass_fini_dump_file (pass
);
2141 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->pass
.next
;
2145 /* Execute IPA_PASS function transform on NODE. */
2148 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2149 struct ipa_opt_pass_d
*ipa_pass
)
2151 struct opt_pass
*pass
= &ipa_pass
->pass
;
2152 unsigned int todo_after
= 0;
2154 current_pass
= pass
;
2155 if (!ipa_pass
->function_transform
)
2158 /* Note that the folders should only create gimple expressions.
2159 This is a hack until the new folder is ready. */
2160 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2162 pass_init_dump_file (pass
);
2164 /* Run pre-pass verification. */
2165 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2167 /* If a timevar is present, start it. */
2168 if (pass
->tv_id
!= TV_NONE
)
2169 timevar_push (pass
->tv_id
);
2172 todo_after
= ipa_pass
->function_transform (node
);
2175 if (pass
->tv_id
!= TV_NONE
)
2176 timevar_pop (pass
->tv_id
);
2178 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2179 check_profile_consistency (pass
->static_pass_number
, 0, true);
2181 /* Run post-pass cleanup and verification. */
2182 execute_todo (todo_after
);
2183 verify_interpass_invariants ();
2184 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2185 check_profile_consistency (pass
->static_pass_number
, 1, true);
2187 do_per_function (execute_function_dump
, NULL
);
2188 pass_fini_dump_file (pass
);
2190 current_pass
= NULL
;
2193 /* For the current function, execute all ipa transforms. */
2196 execute_all_ipa_transforms (void)
2198 struct cgraph_node
*node
;
2201 node
= cgraph_get_node (current_function_decl
);
2203 if (node
->ipa_transforms_to_apply
.exists ())
2207 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2208 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2209 node
->ipa_transforms_to_apply
.release ();
2213 /* Callback for do_per_function to apply all IPA transforms. */
2216 apply_ipa_transforms (void *data
)
2218 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2219 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2221 *(bool *)data
= true;
2222 execute_all_ipa_transforms();
2223 rebuild_cgraph_edges ();
2227 /* Check if PASS is explicitly disabled or enabled and return
2228 the gate status. FUNC is the function to be processed, and
2229 GATE_STATUS is the gate status determined by pass manager by
2233 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2235 bool explicitly_enabled
= false;
2236 bool explicitly_disabled
= false;
2239 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2240 enabled_pass_uid_range_tab
);
2242 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2243 disabled_pass_uid_range_tab
);
2245 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2254 execute_one_pass (struct opt_pass
*pass
)
2256 unsigned int todo_after
= 0;
2260 /* IPA passes are executed on whole program, so cfun should be NULL.
2261 Other passes need function context set. */
2262 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2263 gcc_assert (!cfun
&& !current_function_decl
);
2265 gcc_assert (cfun
&& current_function_decl
);
2267 current_pass
= pass
;
2269 /* Check whether gate check should be avoided.
2270 User controls the value of the gate through the parameter "gate_status". */
2271 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2272 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2274 /* Override gate with plugin. */
2275 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2279 /* Run so passes selectively disabling themselves on a given function
2280 are not miscounted. */
2281 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2283 check_profile_consistency (pass
->static_pass_number
, 0, false);
2284 check_profile_consistency (pass
->static_pass_number
, 1, false);
2286 current_pass
= NULL
;
2290 /* Pass execution event trigger: useful to identify passes being
2292 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2294 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2295 Apply all trnasforms first. */
2296 if (pass
->type
== SIMPLE_IPA_PASS
)
2298 bool applied
= false;
2299 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2301 symtab_remove_unreachable_nodes (true, dump_file
);
2302 /* Restore current_pass. */
2303 current_pass
= pass
;
2306 if (!quiet_flag
&& !cfun
)
2307 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2309 /* Note that the folders should only create gimple expressions.
2310 This is a hack until the new folder is ready. */
2311 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2313 pass_init_dump_file (pass
);
2315 /* Run pre-pass verification. */
2316 execute_todo (pass
->todo_flags_start
);
2318 #ifdef ENABLE_CHECKING
2319 do_per_function (verify_curr_properties
,
2320 (void *)(size_t)pass
->properties_required
);
2323 /* If a timevar is present, start it. */
2324 if (pass
->tv_id
!= TV_NONE
)
2325 timevar_push (pass
->tv_id
);
2330 todo_after
= pass
->execute ();
2331 do_per_function (clear_last_verified
, NULL
);
2335 if (pass
->tv_id
!= TV_NONE
)
2336 timevar_pop (pass
->tv_id
);
2338 do_per_function (update_properties_after_pass
, pass
);
2340 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2341 check_profile_consistency (pass
->static_pass_number
, 0, true);
2343 /* Run post-pass cleanup and verification. */
2344 execute_todo (todo_after
| pass
->todo_flags_finish
);
2345 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2346 check_profile_consistency (pass
->static_pass_number
, 1, true);
2348 verify_interpass_invariants ();
2349 do_per_function (execute_function_dump
, NULL
);
2350 if (pass
->type
== IPA_PASS
)
2352 struct cgraph_node
*node
;
2353 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2354 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2357 if (!current_function_decl
)
2358 cgraph_process_new_functions ();
2360 pass_fini_dump_file (pass
);
2362 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2363 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2364 || pass
->type
!= RTL_PASS
);
2366 current_pass
= NULL
;
2372 execute_pass_list (struct opt_pass
*pass
)
2376 gcc_assert (pass
->type
== GIMPLE_PASS
2377 || pass
->type
== RTL_PASS
);
2378 if (execute_one_pass (pass
) && pass
->sub
)
2379 execute_pass_list (pass
->sub
);
2385 /* Same as execute_pass_list but assume that subpasses of IPA passes
2386 are local passes. If SET is not NULL, write out summaries of only
2387 those node in SET. */
2390 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2394 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2395 gcc_assert (!current_function_decl
);
2397 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2398 if (pass
->type
== IPA_PASS
2399 && ipa_pass
->write_summary
2400 && (!pass
->gate
|| pass
->gate ()))
2402 /* If a timevar is present, start it. */
2404 timevar_push (pass
->tv_id
);
2406 pass_init_dump_file (pass
);
2408 ipa_pass
->write_summary ();
2410 pass_fini_dump_file (pass
);
2412 /* If a timevar is present, start it. */
2414 timevar_pop (pass
->tv_id
);
2417 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2418 ipa_write_summaries_2 (pass
->sub
, state
);
2424 /* Helper function of ipa_write_summaries. Creates and destroys the
2425 decl state and calls ipa_write_summaries_2 for all passes that have
2426 summaries. SET is the set of nodes to be written. */
2429 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2431 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2432 state
->symtab_node_encoder
= encoder
;
2434 lto_push_out_decl_state (state
);
2436 gcc_assert (!flag_wpa
);
2437 ipa_write_summaries_2 (all_regular_ipa_passes
, state
);
2438 ipa_write_summaries_2 (all_lto_gen_passes
, state
);
2440 gcc_assert (lto_get_out_decl_state () == state
);
2441 lto_pop_out_decl_state ();
2442 lto_delete_out_decl_state (state
);
2445 /* Write out summaries for all the nodes in the callgraph. */
2448 ipa_write_summaries (void)
2450 lto_symtab_encoder_t encoder
;
2452 struct varpool_node
*vnode
;
2453 struct cgraph_node
**order
;
2455 if (!flag_generate_lto
|| seen_error ())
2458 encoder
= lto_symtab_encoder_new (false);
2460 /* Create the callgraph set in the same order used in
2461 cgraph_expand_all_functions. This mostly facilitates debugging,
2462 since it causes the gimple file to be processed in the same order
2463 as the source code. */
2464 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2465 order_pos
= ipa_reverse_postorder (order
);
2466 gcc_assert (order_pos
== cgraph_n_nodes
);
2468 for (i
= order_pos
- 1; i
>= 0; i
--)
2470 struct cgraph_node
*node
= order
[i
];
2472 if (cgraph_function_with_gimple_body_p (node
))
2474 /* When streaming out references to statements as part of some IPA
2475 pass summary, the statements need to have uids assigned and the
2476 following does that for all the IPA passes here. Naturally, this
2477 ordering then matches the one IPA-passes get in their stmt_fixup
2480 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2481 renumber_gimple_stmt_uids ();
2485 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2488 FOR_EACH_DEFINED_VARIABLE (vnode
)
2489 if ((!vnode
->alias
|| vnode
->alias_of
))
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
->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
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 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, state
);
2567 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, state
);
2569 gcc_assert (lto_get_out_decl_state () == state
);
2570 lto_pop_out_decl_state ();
2571 lto_delete_out_decl_state (state
);
2574 /* Same as execute_pass_list but assume that subpasses of IPA passes
2575 are local passes. */
2578 ipa_read_summaries_1 (struct opt_pass
*pass
)
2582 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2584 gcc_assert (!current_function_decl
);
2586 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2588 if (pass
->gate
== NULL
|| pass
->gate ())
2590 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2592 /* If a timevar is present, start it. */
2594 timevar_push (pass
->tv_id
);
2596 pass_init_dump_file (pass
);
2598 ipa_pass
->read_summary ();
2600 pass_fini_dump_file (pass
);
2604 timevar_pop (pass
->tv_id
);
2607 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2608 ipa_read_summaries_1 (pass
->sub
);
2615 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2618 ipa_read_summaries (void)
2620 ipa_read_summaries_1 (all_regular_ipa_passes
);
2621 ipa_read_summaries_1 (all_lto_gen_passes
);
2624 /* Same as execute_pass_list but assume that subpasses of IPA passes
2625 are local passes. */
2628 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2632 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2634 gcc_assert (!current_function_decl
);
2636 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2638 if (pass
->gate
== NULL
|| pass
->gate ())
2640 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2642 /* If a timevar is present, start it. */
2644 timevar_push (pass
->tv_id
);
2646 pass_init_dump_file (pass
);
2648 ipa_pass
->read_optimization_summary ();
2650 pass_fini_dump_file (pass
);
2654 timevar_pop (pass
->tv_id
);
2657 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2658 ipa_read_optimization_summaries_1 (pass
->sub
);
2664 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2667 ipa_read_optimization_summaries (void)
2669 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2670 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2673 /* Same as execute_pass_list but assume that subpasses of IPA passes
2674 are local passes. */
2676 execute_ipa_pass_list (struct opt_pass
*pass
)
2680 gcc_assert (!current_function_decl
);
2682 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2683 if (execute_one_pass (pass
) && pass
->sub
)
2685 if (pass
->sub
->type
== GIMPLE_PASS
)
2687 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2688 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2690 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2692 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2693 || pass
->sub
->type
== IPA_PASS
)
2694 execute_ipa_pass_list (pass
->sub
);
2698 gcc_assert (!current_function_decl
);
2699 cgraph_process_new_functions ();
2705 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2708 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2709 struct cgraph_node
*node
, gimple
*stmts
)
2713 /* Execute all of the IPA_PASSes in the list. */
2714 if (pass
->type
== IPA_PASS
2715 && (!pass
->gate
|| pass
->gate ()))
2717 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2719 if (ipa_pass
->stmt_fixup
)
2721 pass_init_dump_file (pass
);
2722 /* If a timevar is present, start it. */
2724 timevar_push (pass
->tv_id
);
2726 ipa_pass
->stmt_fixup (node
, stmts
);
2730 timevar_pop (pass
->tv_id
);
2731 pass_fini_dump_file (pass
);
2734 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2740 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2743 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2745 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2749 extern void debug_properties (unsigned int);
2750 extern void dump_properties (FILE *, unsigned int);
2753 dump_properties (FILE *dump
, unsigned int props
)
2755 fprintf (dump
, "Properties:\n");
2756 if (props
& PROP_gimple_any
)
2757 fprintf (dump
, "PROP_gimple_any\n");
2758 if (props
& PROP_gimple_lcf
)
2759 fprintf (dump
, "PROP_gimple_lcf\n");
2760 if (props
& PROP_gimple_leh
)
2761 fprintf (dump
, "PROP_gimple_leh\n");
2762 if (props
& PROP_cfg
)
2763 fprintf (dump
, "PROP_cfg\n");
2764 if (props
& PROP_ssa
)
2765 fprintf (dump
, "PROP_ssa\n");
2766 if (props
& PROP_no_crit_edges
)
2767 fprintf (dump
, "PROP_no_crit_edges\n");
2768 if (props
& PROP_rtl
)
2769 fprintf (dump
, "PROP_rtl\n");
2770 if (props
& PROP_gimple_lomp
)
2771 fprintf (dump
, "PROP_gimple_lomp\n");
2772 if (props
& PROP_gimple_lcx
)
2773 fprintf (dump
, "PROP_gimple_lcx\n");
2774 if (props
& PROP_cfglayout
)
2775 fprintf (dump
, "PROP_cfglayout\n");
2779 debug_properties (unsigned int props
)
2781 dump_properties (stderr
, props
);
2784 /* Called by local passes to see if function is called by already processed nodes.
2785 Because we process nodes in topological order, this means that function is
2786 in recursive cycle or we introduced new direct calls. */
2788 function_called_by_processed_nodes_p (void)
2790 struct cgraph_edge
*e
;
2791 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2795 if (e
->caller
->symbol
.decl
== current_function_decl
)
2797 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2799 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2801 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2806 fprintf (dump_file
, "Already processed call to:\n");
2807 dump_cgraph_node (dump_file
, e
->caller
);
2812 #include "gt-passes.h"