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 0 /* 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_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_early_warn_uninitialized
);
1314 NEXT_PASS (pass_rebuild_cgraph_edges
);
1315 NEXT_PASS (pass_inline_parameters
);
1316 NEXT_PASS (pass_early_inline
);
1317 NEXT_PASS (pass_all_early_optimizations
);
1319 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1320 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1321 NEXT_PASS (pass_rename_ssa_copies
);
1322 NEXT_PASS (pass_ccp
);
1323 /* After CCP we rewrite no longer addressed locals into SSA
1324 form if possible. */
1325 NEXT_PASS (pass_forwprop
);
1326 /* pass_build_ealias is a dummy pass that ensures that we
1327 execute TODO_rebuild_alias at this point. */
1328 NEXT_PASS (pass_build_ealias
);
1329 NEXT_PASS (pass_sra_early
);
1330 NEXT_PASS (pass_fre
);
1331 NEXT_PASS (pass_copy_prop
);
1332 NEXT_PASS (pass_merge_phi
);
1333 NEXT_PASS (pass_cd_dce
);
1334 NEXT_PASS (pass_early_ipa_sra
);
1335 NEXT_PASS (pass_tail_recursion
);
1336 NEXT_PASS (pass_convert_switch
);
1337 NEXT_PASS (pass_cleanup_eh
);
1338 NEXT_PASS (pass_profile
);
1339 NEXT_PASS (pass_local_pure_const
);
1340 /* Split functions creates parts that are not run through
1341 early optimizations again. It is thus good idea to do this
1343 NEXT_PASS (pass_split_functions
);
1345 NEXT_PASS (pass_release_ssa_names
);
1346 NEXT_PASS (pass_rebuild_cgraph_edges
);
1347 NEXT_PASS (pass_inline_parameters
);
1349 NEXT_PASS (pass_ipa_free_inline_summary
);
1350 NEXT_PASS (pass_ipa_tree_profile
);
1352 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1353 NEXT_PASS (pass_feedback_split_functions
);
1355 NEXT_PASS (pass_ipa_increase_alignment
);
1356 NEXT_PASS (pass_ipa_tm
);
1357 NEXT_PASS (pass_ipa_lower_emutls
);
1360 p
= &all_regular_ipa_passes
;
1361 NEXT_PASS (pass_ipa_whole_program_visibility
);
1362 NEXT_PASS (pass_ipa_profile
);
1363 NEXT_PASS (pass_ipa_cp
);
1364 NEXT_PASS (pass_ipa_cdtor_merge
);
1365 NEXT_PASS (pass_ipa_inline
);
1366 NEXT_PASS (pass_ipa_pure_const
);
1367 NEXT_PASS (pass_ipa_reference
);
1370 p
= &all_lto_gen_passes
;
1371 NEXT_PASS (pass_ipa_lto_gimple_out
);
1372 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1375 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1376 passes are executed after partitioning and thus see just parts of the
1378 p
= &all_late_ipa_passes
;
1379 NEXT_PASS (pass_ipa_pta
);
1382 /* These passes are run after IPA passes on every function that is being
1383 output to the assembler file. */
1385 NEXT_PASS (pass_fixup_cfg
);
1386 NEXT_PASS (pass_lower_eh_dispatch
);
1387 NEXT_PASS (pass_all_optimizations
);
1389 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1390 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1391 /* Initial scalar cleanups before alias computation.
1392 They ensure memory accesses are not indirect wherever possible. */
1393 NEXT_PASS (pass_strip_predict_hints
);
1394 NEXT_PASS (pass_rename_ssa_copies
);
1395 NEXT_PASS (pass_complete_unrolli
);
1396 NEXT_PASS (pass_ccp
);
1397 /* After CCP we rewrite no longer addressed locals into SSA
1398 form if possible. */
1399 NEXT_PASS (pass_forwprop
);
1400 /* pass_build_alias is a dummy pass that ensures that we
1401 execute TODO_rebuild_alias at this point. */
1402 NEXT_PASS (pass_build_alias
);
1403 NEXT_PASS (pass_return_slot
);
1404 NEXT_PASS (pass_phiprop
);
1405 NEXT_PASS (pass_fre
);
1406 NEXT_PASS (pass_copy_prop
);
1407 NEXT_PASS (pass_merge_phi
);
1408 NEXT_PASS (pass_vrp
);
1409 NEXT_PASS (pass_dce
);
1410 NEXT_PASS (pass_call_cdce
);
1411 NEXT_PASS (pass_cselim
);
1412 NEXT_PASS (pass_tree_ifcombine
);
1413 NEXT_PASS (pass_phiopt
);
1414 NEXT_PASS (pass_tail_recursion
);
1415 NEXT_PASS (pass_ch
);
1416 NEXT_PASS (pass_stdarg
);
1417 NEXT_PASS (pass_lower_complex
);
1418 NEXT_PASS (pass_sra
);
1419 NEXT_PASS (pass_rename_ssa_copies
);
1420 /* The dom pass will also resolve all __builtin_constant_p calls
1421 that are still there to 0. This has to be done after some
1422 propagations have already run, but before some more dead code
1423 is removed, and this place fits nicely. Remember this when
1424 trying to move or duplicate pass_dominator somewhere earlier. */
1425 NEXT_PASS (pass_dominator
);
1426 /* The only const/copy propagation opportunities left after
1427 DOM should be due to degenerate PHI nodes. So rather than
1428 run the full propagators, run a specialized pass which
1429 only examines PHIs to discover const/copy propagation
1431 NEXT_PASS (pass_phi_only_cprop
);
1432 NEXT_PASS (pass_dse
);
1433 NEXT_PASS (pass_reassoc
);
1434 NEXT_PASS (pass_dce
);
1435 NEXT_PASS (pass_forwprop
);
1436 NEXT_PASS (pass_phiopt
);
1437 NEXT_PASS (pass_object_sizes
);
1438 NEXT_PASS (pass_strlen
);
1439 NEXT_PASS (pass_ccp
);
1440 /* After CCP we rewrite no longer addressed locals into SSA
1441 form if possible. */
1442 NEXT_PASS (pass_copy_prop
);
1443 NEXT_PASS (pass_cse_sincos
);
1444 NEXT_PASS (pass_optimize_bswap
);
1445 NEXT_PASS (pass_split_crit_edges
);
1446 NEXT_PASS (pass_pre
);
1447 NEXT_PASS (pass_sink_code
);
1448 NEXT_PASS (pass_asan
);
1449 NEXT_PASS (pass_tsan
);
1450 NEXT_PASS (pass_tree_loop
);
1452 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1453 NEXT_PASS (pass_tree_loop_init
);
1454 NEXT_PASS (pass_lim
);
1455 NEXT_PASS (pass_copy_prop
);
1456 NEXT_PASS (pass_dce_loop
);
1457 NEXT_PASS (pass_tree_unswitch
);
1458 NEXT_PASS (pass_scev_cprop
);
1459 NEXT_PASS (pass_record_bounds
);
1460 NEXT_PASS (pass_check_data_deps
);
1461 NEXT_PASS (pass_loop_distribution
);
1462 NEXT_PASS (pass_copy_prop
);
1463 NEXT_PASS (pass_graphite
);
1465 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1466 NEXT_PASS (pass_graphite_transforms
);
1467 NEXT_PASS (pass_lim
);
1468 NEXT_PASS (pass_copy_prop
);
1469 NEXT_PASS (pass_dce_loop
);
1471 NEXT_PASS (pass_iv_canon
);
1472 NEXT_PASS (pass_if_conversion
);
1473 NEXT_PASS (pass_vectorize
);
1475 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1476 NEXT_PASS (pass_dce_loop
);
1478 NEXT_PASS (pass_predcom
);
1479 NEXT_PASS (pass_complete_unroll
);
1480 NEXT_PASS (pass_slp_vectorize
);
1481 NEXT_PASS (pass_parallelize_loops
);
1482 NEXT_PASS (pass_loop_prefetch
);
1483 NEXT_PASS (pass_iv_optimize
);
1484 NEXT_PASS (pass_lim
);
1485 NEXT_PASS (pass_tree_loop_done
);
1487 NEXT_PASS (pass_lower_vector_ssa
);
1488 NEXT_PASS (pass_cse_reciprocals
);
1489 NEXT_PASS (pass_reassoc
);
1490 NEXT_PASS (pass_strength_reduction
);
1491 NEXT_PASS (pass_dominator
);
1492 /* The only const/copy propagation opportunities left after
1493 DOM should be due to degenerate PHI nodes. So rather than
1494 run the full propagators, run a specialized pass which
1495 only examines PHIs to discover const/copy propagation
1497 NEXT_PASS (pass_phi_only_cprop
);
1498 NEXT_PASS (pass_vrp
);
1499 NEXT_PASS (pass_cd_dce
);
1500 NEXT_PASS (pass_tracer
);
1502 /* FIXME: If DCE is not run before checking for uninitialized uses,
1503 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1504 However, this also causes us to misdiagnose cases that should be
1505 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1507 To fix the false positives in uninit-5.c, we would have to
1508 account for the predicates protecting the set and the use of each
1509 variable. Using a representation like Gated Single Assignment
1511 NEXT_PASS (pass_late_warn_uninitialized
);
1512 NEXT_PASS (pass_dse
);
1513 NEXT_PASS (pass_forwprop
);
1514 NEXT_PASS (pass_phiopt
);
1515 NEXT_PASS (pass_fold_builtins
);
1516 NEXT_PASS (pass_optimize_widening_mul
);
1517 NEXT_PASS (pass_tail_calls
);
1518 NEXT_PASS (pass_rename_ssa_copies
);
1519 NEXT_PASS (pass_uncprop
);
1520 NEXT_PASS (pass_local_pure_const
);
1522 NEXT_PASS (pass_all_optimizations_g
);
1524 struct opt_pass
**p
= &pass_all_optimizations_g
.pass
.sub
;
1525 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1526 NEXT_PASS (pass_strip_predict_hints
);
1527 /* Lower remaining pieces of GIMPLE. */
1528 NEXT_PASS (pass_lower_complex
);
1529 NEXT_PASS (pass_lower_vector_ssa
);
1530 /* Perform simple scalar cleanup which is constant/copy propagation. */
1531 NEXT_PASS (pass_ccp
);
1532 NEXT_PASS (pass_object_sizes
);
1533 /* Copy propagation also copy-propagates constants, this is necessary
1534 to forward object-size results properly. */
1535 NEXT_PASS (pass_copy_prop
);
1536 NEXT_PASS (pass_asan
);
1537 NEXT_PASS (pass_tsan
);
1538 NEXT_PASS (pass_rename_ssa_copies
);
1539 NEXT_PASS (pass_dce
);
1540 /* Fold remaining builtins. */
1541 NEXT_PASS (pass_fold_builtins
);
1542 /* ??? We do want some kind of loop invariant motion, but we possibly
1543 need to adjust LIM to be more friendly towards preserving accurate
1544 debug information here. */
1545 NEXT_PASS (pass_late_warn_uninitialized
);
1546 NEXT_PASS (pass_uncprop
);
1547 NEXT_PASS (pass_local_pure_const
);
1549 NEXT_PASS (pass_tm_init
);
1551 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1552 NEXT_PASS (pass_tm_mark
);
1553 NEXT_PASS (pass_tm_memopt
);
1554 NEXT_PASS (pass_tm_edges
);
1556 NEXT_PASS (pass_lower_vector
);
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 /* Now that the dumping has been done, we can get rid of the optional
2019 if (flags
& TODO_df_finish
)
2020 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2022 timevar_pop (TV_TODO
);
2025 /* Verify invariants that should hold between passes. This is a place
2026 to put simple sanity checks. */
2029 verify_interpass_invariants (void)
2031 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2034 /* Clear the last verified flag. */
2037 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
2039 cfun
->last_verified
= 0;
2042 /* Helper function. Verify that the properties has been turn into the
2043 properties expected by the pass. */
2045 #ifdef ENABLE_CHECKING
2047 verify_curr_properties (void *data
)
2049 unsigned int props
= (size_t)data
;
2050 gcc_assert ((cfun
->curr_properties
& props
) == props
);
2054 /* Initialize pass dump file. */
2055 /* This is non-static so that the plugins can use it. */
2058 pass_init_dump_file (struct opt_pass
*pass
)
2060 /* If a dump file name is present, open it if enabled. */
2061 if (pass
->static_pass_number
!= -1)
2063 timevar_push (TV_DUMP
);
2064 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
2065 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
2066 dump_start (pass
->static_pass_number
, &dump_flags
);
2067 if (dump_file
&& current_function_decl
)
2068 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2069 if (initializing_dump
2070 && dump_file
&& (dump_flags
& TDF_GRAPH
)
2071 && cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2072 clean_graph_dump_file (dump_file_name
);
2073 timevar_pop (TV_DUMP
);
2074 return initializing_dump
;
2080 /* Flush PASS dump file. */
2081 /* This is non-static so that plugins can use it. */
2084 pass_fini_dump_file (struct opt_pass
*pass
)
2086 timevar_push (TV_DUMP
);
2088 /* Flush and close dump file. */
2091 free (CONST_CAST (char *, dump_file_name
));
2092 dump_file_name
= NULL
;
2095 dump_finish (pass
->static_pass_number
);
2096 timevar_pop (TV_DUMP
);
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
;
2189 /* Signal this is a suitable GC collection point. */
2190 if (!(todo_after
& TODO_do_not_ggc_collect
))
2194 /* For the current function, execute all ipa transforms. */
2197 execute_all_ipa_transforms (void)
2199 struct cgraph_node
*node
;
2202 node
= cgraph_get_node (current_function_decl
);
2204 if (node
->ipa_transforms_to_apply
.exists ())
2208 for (i
= 0; i
< node
->ipa_transforms_to_apply
.length (); i
++)
2209 execute_one_ipa_transform_pass (node
, node
->ipa_transforms_to_apply
[i
]);
2210 node
->ipa_transforms_to_apply
.release ();
2214 /* Callback for do_per_function to apply all IPA transforms. */
2217 apply_ipa_transforms (void *data
)
2219 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2220 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
.exists ())
2222 *(bool *)data
= true;
2223 execute_all_ipa_transforms();
2224 rebuild_cgraph_edges ();
2228 /* Check if PASS is explicitly disabled or enabled and return
2229 the gate status. FUNC is the function to be processed, and
2230 GATE_STATUS is the gate status determined by pass manager by
2234 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2236 bool explicitly_enabled
= false;
2237 bool explicitly_disabled
= false;
2240 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2241 enabled_pass_uid_range_tab
);
2243 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2244 disabled_pass_uid_range_tab
);
2246 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2255 execute_one_pass (struct opt_pass
*pass
)
2257 unsigned int todo_after
= 0;
2261 /* IPA passes are executed on whole program, so cfun should be NULL.
2262 Other passes need function context set. */
2263 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2264 gcc_assert (!cfun
&& !current_function_decl
);
2266 gcc_assert (cfun
&& current_function_decl
);
2268 current_pass
= pass
;
2270 /* Check whether gate check should be avoided.
2271 User controls the value of the gate through the parameter "gate_status". */
2272 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2273 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2275 /* Override gate with plugin. */
2276 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2280 /* Run so passes selectively disabling themselves on a given function
2281 are not miscounted. */
2282 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2284 check_profile_consistency (pass
->static_pass_number
, 0, false);
2285 check_profile_consistency (pass
->static_pass_number
, 1, false);
2287 current_pass
= NULL
;
2291 /* Pass execution event trigger: useful to identify passes being
2293 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2295 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2296 Apply all trnasforms first. */
2297 if (pass
->type
== SIMPLE_IPA_PASS
)
2299 bool applied
= false;
2300 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2302 symtab_remove_unreachable_nodes (true, dump_file
);
2303 /* Restore current_pass. */
2304 current_pass
= pass
;
2307 if (!quiet_flag
&& !cfun
)
2308 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2310 /* Note that the folders should only create gimple expressions.
2311 This is a hack until the new folder is ready. */
2312 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2314 pass_init_dump_file (pass
);
2316 /* Run pre-pass verification. */
2317 execute_todo (pass
->todo_flags_start
);
2319 #ifdef ENABLE_CHECKING
2320 do_per_function (verify_curr_properties
,
2321 (void *)(size_t)pass
->properties_required
);
2324 /* If a timevar is present, start it. */
2325 if (pass
->tv_id
!= TV_NONE
)
2326 timevar_push (pass
->tv_id
);
2331 todo_after
= pass
->execute ();
2332 do_per_function (clear_last_verified
, NULL
);
2336 if (pass
->tv_id
!= TV_NONE
)
2337 timevar_pop (pass
->tv_id
);
2339 do_per_function (update_properties_after_pass
, pass
);
2341 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2342 check_profile_consistency (pass
->static_pass_number
, 0, true);
2344 /* Run post-pass cleanup and verification. */
2345 execute_todo (todo_after
| pass
->todo_flags_finish
);
2346 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2347 check_profile_consistency (pass
->static_pass_number
, 1, true);
2349 verify_interpass_invariants ();
2350 do_per_function (execute_function_dump
, NULL
);
2351 if (pass
->type
== IPA_PASS
)
2353 struct cgraph_node
*node
;
2354 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2355 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*)pass
);
2358 if (!current_function_decl
)
2359 cgraph_process_new_functions ();
2361 pass_fini_dump_file (pass
);
2363 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2364 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2365 || pass
->type
!= RTL_PASS
);
2367 current_pass
= NULL
;
2369 /* Signal this is a suitable GC collection point. */
2370 if (!((todo_after
| pass
->todo_flags_finish
) & TODO_do_not_ggc_collect
))
2377 execute_pass_list (struct opt_pass
*pass
)
2381 gcc_assert (pass
->type
== GIMPLE_PASS
2382 || pass
->type
== RTL_PASS
);
2383 if (execute_one_pass (pass
) && pass
->sub
)
2384 execute_pass_list (pass
->sub
);
2390 /* Same as execute_pass_list but assume that subpasses of IPA passes
2391 are local passes. If SET is not NULL, write out summaries of only
2392 those node in SET. */
2395 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2399 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2400 gcc_assert (!current_function_decl
);
2402 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2403 if (pass
->type
== IPA_PASS
2404 && ipa_pass
->write_summary
2405 && (!pass
->gate
|| pass
->gate ()))
2407 /* If a timevar is present, start it. */
2409 timevar_push (pass
->tv_id
);
2411 pass_init_dump_file (pass
);
2413 ipa_pass
->write_summary ();
2415 pass_fini_dump_file (pass
);
2417 /* If a timevar is present, start it. */
2419 timevar_pop (pass
->tv_id
);
2422 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2423 ipa_write_summaries_2 (pass
->sub
, state
);
2429 /* Helper function of ipa_write_summaries. Creates and destroys the
2430 decl state and calls ipa_write_summaries_2 for all passes that have
2431 summaries. SET is the set of nodes to be written. */
2434 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2436 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2437 state
->symtab_node_encoder
= encoder
;
2439 lto_push_out_decl_state (state
);
2441 gcc_assert (!flag_wpa
);
2442 ipa_write_summaries_2 (all_regular_ipa_passes
, state
);
2443 ipa_write_summaries_2 (all_lto_gen_passes
, state
);
2445 gcc_assert (lto_get_out_decl_state () == state
);
2446 lto_pop_out_decl_state ();
2447 lto_delete_out_decl_state (state
);
2450 /* Write out summaries for all the nodes in the callgraph. */
2453 ipa_write_summaries (void)
2455 lto_symtab_encoder_t encoder
;
2457 struct varpool_node
*vnode
;
2458 struct cgraph_node
**order
;
2460 if (!flag_generate_lto
|| seen_error ())
2463 encoder
= lto_symtab_encoder_new (false);
2465 /* Create the callgraph set in the same order used in
2466 cgraph_expand_all_functions. This mostly facilitates debugging,
2467 since it causes the gimple file to be processed in the same order
2468 as the source code. */
2469 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2470 order_pos
= ipa_reverse_postorder (order
);
2471 gcc_assert (order_pos
== cgraph_n_nodes
);
2473 for (i
= order_pos
- 1; i
>= 0; i
--)
2475 struct cgraph_node
*node
= order
[i
];
2477 if (cgraph_function_with_gimple_body_p (node
))
2479 /* When streaming out references to statements as part of some IPA
2480 pass summary, the statements need to have uids assigned and the
2481 following does that for all the IPA passes here. Naturally, this
2482 ordering then matches the one IPA-passes get in their stmt_fixup
2485 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2486 renumber_gimple_stmt_uids ();
2490 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2493 FOR_EACH_DEFINED_VARIABLE (vnode
)
2494 if ((!vnode
->alias
|| vnode
->alias_of
))
2495 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2497 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2502 /* Same as execute_pass_list but assume that subpasses of IPA passes
2503 are local passes. If SET is not NULL, write out optimization summaries of
2504 only those node in SET. */
2507 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2511 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2512 gcc_assert (!current_function_decl
);
2514 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2515 if (pass
->type
== IPA_PASS
2516 && ipa_pass
->write_optimization_summary
2517 && (!pass
->gate
|| pass
->gate ()))
2519 /* If a timevar is present, start it. */
2521 timevar_push (pass
->tv_id
);
2523 pass_init_dump_file (pass
);
2525 ipa_pass
->write_optimization_summary ();
2527 pass_fini_dump_file (pass
);
2529 /* If a timevar is present, start it. */
2531 timevar_pop (pass
->tv_id
);
2534 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2535 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2541 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2542 NULL, write out all summaries of all nodes. */
2545 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2547 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2548 lto_symtab_encoder_iterator lsei
;
2549 state
->symtab_node_encoder
= encoder
;
2551 lto_push_out_decl_state (state
);
2552 for (lsei
= lsei_start_function_in_partition (encoder
);
2553 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2555 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2556 /* When streaming out references to statements as part of some IPA
2557 pass summary, the statements need to have uids assigned.
2559 For functions newly born at WPA stage we need to initialize
2562 && gimple_has_body_p (node
->symbol
.decl
))
2564 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2565 renumber_gimple_stmt_uids ();
2570 gcc_assert (flag_wpa
);
2571 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, state
);
2572 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, state
);
2574 gcc_assert (lto_get_out_decl_state () == state
);
2575 lto_pop_out_decl_state ();
2576 lto_delete_out_decl_state (state
);
2579 /* Same as execute_pass_list but assume that subpasses of IPA passes
2580 are local passes. */
2583 ipa_read_summaries_1 (struct opt_pass
*pass
)
2587 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2589 gcc_assert (!current_function_decl
);
2591 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2593 if (pass
->gate
== NULL
|| pass
->gate ())
2595 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2597 /* If a timevar is present, start it. */
2599 timevar_push (pass
->tv_id
);
2601 pass_init_dump_file (pass
);
2603 ipa_pass
->read_summary ();
2605 pass_fini_dump_file (pass
);
2609 timevar_pop (pass
->tv_id
);
2612 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2613 ipa_read_summaries_1 (pass
->sub
);
2620 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2623 ipa_read_summaries (void)
2625 ipa_read_summaries_1 (all_regular_ipa_passes
);
2626 ipa_read_summaries_1 (all_lto_gen_passes
);
2629 /* Same as execute_pass_list but assume that subpasses of IPA passes
2630 are local passes. */
2633 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2637 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2639 gcc_assert (!current_function_decl
);
2641 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2643 if (pass
->gate
== NULL
|| pass
->gate ())
2645 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2647 /* If a timevar is present, start it. */
2649 timevar_push (pass
->tv_id
);
2651 pass_init_dump_file (pass
);
2653 ipa_pass
->read_optimization_summary ();
2655 pass_fini_dump_file (pass
);
2659 timevar_pop (pass
->tv_id
);
2662 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2663 ipa_read_optimization_summaries_1 (pass
->sub
);
2669 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2672 ipa_read_optimization_summaries (void)
2674 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2675 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2678 /* Same as execute_pass_list but assume that subpasses of IPA passes
2679 are local passes. */
2681 execute_ipa_pass_list (struct opt_pass
*pass
)
2685 gcc_assert (!current_function_decl
);
2687 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2688 if (execute_one_pass (pass
) && pass
->sub
)
2690 if (pass
->sub
->type
== GIMPLE_PASS
)
2692 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2693 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2695 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2697 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2698 || pass
->sub
->type
== IPA_PASS
)
2699 execute_ipa_pass_list (pass
->sub
);
2703 gcc_assert (!current_function_decl
);
2704 cgraph_process_new_functions ();
2710 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2713 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2714 struct cgraph_node
*node
, gimple
*stmts
)
2718 /* Execute all of the IPA_PASSes in the list. */
2719 if (pass
->type
== IPA_PASS
2720 && (!pass
->gate
|| pass
->gate ()))
2722 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2724 if (ipa_pass
->stmt_fixup
)
2726 pass_init_dump_file (pass
);
2727 /* If a timevar is present, start it. */
2729 timevar_push (pass
->tv_id
);
2731 ipa_pass
->stmt_fixup (node
, stmts
);
2735 timevar_pop (pass
->tv_id
);
2736 pass_fini_dump_file (pass
);
2739 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2745 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2748 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2750 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2754 extern void debug_properties (unsigned int);
2755 extern void dump_properties (FILE *, unsigned int);
2758 dump_properties (FILE *dump
, unsigned int props
)
2760 fprintf (dump
, "Properties:\n");
2761 if (props
& PROP_gimple_any
)
2762 fprintf (dump
, "PROP_gimple_any\n");
2763 if (props
& PROP_gimple_lcf
)
2764 fprintf (dump
, "PROP_gimple_lcf\n");
2765 if (props
& PROP_gimple_leh
)
2766 fprintf (dump
, "PROP_gimple_leh\n");
2767 if (props
& PROP_cfg
)
2768 fprintf (dump
, "PROP_cfg\n");
2769 if (props
& PROP_ssa
)
2770 fprintf (dump
, "PROP_ssa\n");
2771 if (props
& PROP_no_crit_edges
)
2772 fprintf (dump
, "PROP_no_crit_edges\n");
2773 if (props
& PROP_rtl
)
2774 fprintf (dump
, "PROP_rtl\n");
2775 if (props
& PROP_gimple_lomp
)
2776 fprintf (dump
, "PROP_gimple_lomp\n");
2777 if (props
& PROP_gimple_lcx
)
2778 fprintf (dump
, "PROP_gimple_lcx\n");
2779 if (props
& PROP_gimple_lvec
)
2780 fprintf (dump
, "PROP_gimple_lvec\n");
2781 if (props
& PROP_cfglayout
)
2782 fprintf (dump
, "PROP_cfglayout\n");
2786 debug_properties (unsigned int props
)
2788 dump_properties (stderr
, props
);
2791 /* Called by local passes to see if function is called by already processed nodes.
2792 Because we process nodes in topological order, this means that function is
2793 in recursive cycle or we introduced new direct calls. */
2795 function_called_by_processed_nodes_p (void)
2797 struct cgraph_edge
*e
;
2798 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2802 if (e
->caller
->symbol
.decl
== current_function_decl
)
2804 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2806 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2808 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2813 fprintf (dump_file
, "Already processed call to:\n");
2814 dump_cgraph_node (dump_file
, e
->caller
);
2819 #include "gt-passes.h"