1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
29 #include "coretypes.h"
37 #include "insn-attr.h"
38 #include "insn-config.h"
39 #include "insn-flags.h"
40 #include "hard-reg-set.h"
47 #include "basic-block.h"
52 #include "diagnostic-core.h"
57 #include "langhooks.h"
59 #include "hosthooks.h"
63 #include "value-prof.h"
64 #include "tree-inline.h"
65 #include "tree-flow.h"
66 #include "tree-pass.h"
67 #include "tree-dump.h"
70 #include "lto-streamer.h"
72 #include "ipa-utils.h"
73 #include "tree-pretty-print.h" /* for dump_function_header */
75 /* This is used for debugging. It allows the current pass to printed
76 from anywhere in compilation.
77 The variable current_pass is also used for statistics and plugins. */
78 struct opt_pass
*current_pass
;
80 static void register_pass_name (struct opt_pass
*, const char *);
82 /* Call from anywhere to find out what pass this is. Useful for
83 printing out debugging information deep inside an service
86 print_current_pass (FILE *file
)
89 fprintf (file
, "current pass = %s (%d)\n",
90 current_pass
->name
, current_pass
->static_pass_number
);
92 fprintf (file
, "no current pass.\n");
96 /* Call from the debugger to get the current pass name. */
100 print_current_pass (stderr
);
105 /* Global variables used to communicate with passes. */
107 bool first_pass_instance
;
110 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
113 This does nothing for local (non-static) variables, unless the
114 variable is a register variable with DECL_ASSEMBLER_NAME set. In
115 that case, or if the variable is not an automatic, it sets up the
116 RTL and outputs any assembler code (label definition, storage
117 allocation and initialization).
119 DECL is the declaration. TOP_LEVEL is nonzero
120 if this declaration is not within a function. */
123 rest_of_decl_compilation (tree decl
,
127 /* We deferred calling assemble_alias so that we could collect
128 other attributes such as visibility. Emit the alias now. */
132 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
135 alias
= TREE_VALUE (TREE_VALUE (alias
));
136 alias
= get_identifier (TREE_STRING_POINTER (alias
));
137 /* A quirk of the initial implementation of aliases required that the
138 user add "extern" to all of them. Which is silly, but now
139 historical. Do note that the symbol is in fact locally defined. */
140 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
141 DECL_EXTERNAL (decl
) = 0;
142 assemble_alias (decl
, alias
);
146 /* Can't defer this, because it needs to happen before any
147 later function definitions are processed. */
148 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
149 make_decl_rtl (decl
);
151 /* Forward declarations for nested functions are not "external",
152 but we need to treat them as if they were. */
153 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
154 || TREE_CODE (decl
) == FUNCTION_DECL
)
156 timevar_push (TV_VARCONST
);
158 /* Don't output anything when a tentative file-scope definition
159 is seen. But at end of compilation, do output code for them.
161 We do output all variables and rely on
162 callgraph code to defer them except for forward declarations
163 (see gcc.c-torture/compile/920624-1.c) */
165 || !DECL_DEFER_OUTPUT (decl
)
166 || DECL_INITIAL (decl
))
167 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
168 && !DECL_EXTERNAL (decl
))
170 /* When reading LTO unit, we also read varpool, so do not
172 if (in_lto_p
&& !at_end
)
174 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
175 varpool_finalize_decl (decl
);
178 #ifdef ASM_FINISH_DECLARE_OBJECT
179 if (decl
== last_assemble_variable_decl
)
181 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
186 timevar_pop (TV_VARCONST
);
188 else if (TREE_CODE (decl
) == TYPE_DECL
189 /* Like in rest_of_type_compilation, avoid confusing the debug
190 information machinery when there are errors. */
193 timevar_push (TV_SYMOUT
);
194 debug_hooks
->type_decl (decl
, !top_level
);
195 timevar_pop (TV_SYMOUT
);
198 /* Let cgraph know about the existence of variables. */
199 if (in_lto_p
&& !at_end
)
201 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
202 && TREE_STATIC (decl
))
203 varpool_node_for_decl (decl
);
206 /* Called after finishing a record, union or enumeral type. */
209 rest_of_type_compilation (tree type
, int toplev
)
211 /* Avoid confusing the debug information machinery when there are
216 timevar_push (TV_SYMOUT
);
217 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
218 timevar_pop (TV_SYMOUT
);
224 finish_optimization_passes (void)
227 struct dump_file_info
*dfi
;
230 timevar_push (TV_DUMP
);
231 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
233 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
235 dump_finish (pass_profile
.pass
.static_pass_number
);
240 dump_start (pass_profile
.pass
.static_pass_number
, NULL
);
241 print_combine_total_stats ();
242 dump_finish (pass_combine
.pass
.static_pass_number
);
245 /* Do whatever is necessary to finish printing the graphs. */
246 if (graph_dump_format
!= no_graph
)
247 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
248 if (dump_initialized_p (i
)
249 && (dfi
->pflags
& TDF_GRAPH
) != 0
250 && (name
= get_dump_file_name (i
)) != NULL
)
252 finish_graph_dump_file (name
);
256 timevar_pop (TV_DUMP
);
260 execute_all_early_local_passes (void)
262 /* Once this pass (and its sub-passes) are complete, all functions
263 will be in SSA form. Technically this state change is happening
264 a tad early, since the sub-passes have not yet run, but since
265 none of the sub-passes are IPA passes and do not create new
266 functions, this is ok. We're setting this value for the benefit
267 of IPA passes that follow. */
268 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
269 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
273 /* Gate: execute, or not, all of the non-trivial optimizations. */
276 gate_all_early_local_passes (void)
278 /* Don't bother doing anything if the program has errors. */
279 return (!seen_error () && !in_lto_p
);
282 struct simple_ipa_opt_pass pass_early_local_passes
=
286 "early_local_cleanups", /* name */
287 OPTGROUP_NONE
, /* optinfo_flags */
288 gate_all_early_local_passes
, /* gate */
289 execute_all_early_local_passes
, /* execute */
292 0, /* static_pass_number */
293 TV_EARLY_LOCAL
, /* tv_id */
294 0, /* properties_required */
295 0, /* properties_provided */
296 0, /* properties_destroyed */
297 0, /* todo_flags_start */
298 TODO_remove_functions
/* todo_flags_finish */
302 /* Gate: execute, or not, all of the non-trivial optimizations. */
305 gate_all_early_optimizations (void)
307 return (optimize
>= 1
308 /* Don't bother doing anything if the program has errors. */
312 static struct gimple_opt_pass pass_all_early_optimizations
=
316 "early_optimizations", /* name */
317 OPTGROUP_NONE
, /* optinfo_flags */
318 gate_all_early_optimizations
, /* gate */
322 0, /* static_pass_number */
324 0, /* properties_required */
325 0, /* properties_provided */
326 0, /* properties_destroyed */
327 0, /* todo_flags_start */
328 0 /* todo_flags_finish */
332 /* Gate: execute, or not, all of the non-trivial optimizations. */
335 gate_all_optimizations (void)
337 return optimize
>= 1 && !optimize_debug
;
340 static struct gimple_opt_pass pass_all_optimizations
=
344 "*all_optimizations", /* name */
345 OPTGROUP_NONE
, /* optinfo_flags */
346 gate_all_optimizations
, /* gate */
350 0, /* static_pass_number */
351 TV_OPTIMIZE
, /* tv_id */
352 0, /* properties_required */
353 0, /* properties_provided */
354 0, /* properties_destroyed */
355 0, /* todo_flags_start */
356 0 /* todo_flags_finish */
360 /* Gate: execute, or not, all of the non-trivial optimizations. */
363 gate_all_optimizations_g (void)
365 return optimize
>= 1 && optimize_debug
;
368 static struct gimple_opt_pass pass_all_optimizations_g
=
372 "*all_optimizations_g", /* name */
373 OPTGROUP_NONE
, /* optinfo_flags */
374 gate_all_optimizations_g
, /* gate */
378 0, /* static_pass_number */
379 TV_OPTIMIZE
, /* tv_id */
380 0, /* properties_required */
381 0, /* properties_provided */
382 0, /* properties_destroyed */
383 0, /* todo_flags_start */
384 0 /* todo_flags_finish */
389 gate_rest_of_compilation (void)
391 /* Early return if there were errors. We can run afoul of our
392 consistency checks, and there's not really much point in fixing them. */
393 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
396 static struct rtl_opt_pass pass_rest_of_compilation
=
400 "*rest_of_compilation", /* name */
401 OPTGROUP_NONE
, /* optinfo_flags */
402 gate_rest_of_compilation
, /* gate */
406 0, /* static_pass_number */
407 TV_REST_OF_COMPILATION
, /* tv_id */
408 PROP_rtl
, /* properties_required */
409 0, /* properties_provided */
410 0, /* properties_destroyed */
411 0, /* todo_flags_start */
412 TODO_ggc_collect
/* todo_flags_finish */
417 gate_postreload (void)
419 return reload_completed
;
422 static struct rtl_opt_pass pass_postreload
=
426 "*all-postreload", /* name */
427 OPTGROUP_NONE
, /* optinfo_flags */
428 gate_postreload
, /* gate */
432 0, /* static_pass_number */
433 TV_POSTRELOAD
, /* tv_id */
434 PROP_rtl
, /* properties_required */
435 0, /* properties_provided */
436 0, /* properties_destroyed */
437 0, /* todo_flags_start */
438 TODO_ggc_collect
| TODO_verify_rtl_sharing
/* todo_flags_finish */
444 /* The root of the compilation pass tree, once constructed. */
445 struct opt_pass
*all_passes
, *all_small_ipa_passes
, *all_lowering_passes
,
446 *all_regular_ipa_passes
, *all_late_ipa_passes
, *all_lto_gen_passes
;
448 /* This is used by plugins, and should also be used in register_pass. */
449 #define DEF_PASS_LIST(LIST) &LIST,
450 struct opt_pass
**gcc_pass_lists
[] = { GCC_PASS_LISTS NULL
};
453 /* A map from static pass id to optimization pass. */
454 struct opt_pass
**passes_by_id
;
455 int passes_by_id_size
;
457 /* Set the static pass number of pass PASS to ID and record that
458 in the mapping from static pass number to pass. */
461 set_pass_for_id (int id
, struct opt_pass
*pass
)
463 pass
->static_pass_number
= id
;
464 if (passes_by_id_size
<= id
)
466 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
467 memset (passes_by_id
+ passes_by_id_size
, 0,
468 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
469 passes_by_id_size
= id
+ 1;
471 passes_by_id
[id
] = pass
;
474 /* Return the pass with the static pass number ID. */
477 get_pass_for_id (int id
)
479 if (id
>= passes_by_id_size
)
481 return passes_by_id
[id
];
484 /* Iterate over the pass tree allocating dump file numbers. We want
485 to do this depth first, and independent of whether the pass is
489 register_one_dump_file (struct opt_pass
*pass
)
491 char *dot_name
, *flag_name
, *glob_name
;
492 const char *name
, *full_name
, *prefix
;
495 int optgroup_flags
= OPTGROUP_NONE
;
497 /* See below in next_pass_1. */
499 if (pass
->static_pass_number
!= -1)
500 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
501 ? 1 : pass
->static_pass_number
));
503 /* The name is both used to identify the pass for the purposes of plugins,
504 and to specify dump file name and option.
505 The latter two might want something short which is not quite unique; for
506 that reason, we may have a disambiguating prefix, followed by a space
507 to mark the start of the following dump file name / option string. */
508 name
= strchr (pass
->name
, ' ');
509 name
= name
? name
+ 1 : pass
->name
;
510 dot_name
= concat (".", name
, num
, NULL
);
511 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
515 optgroup_flags
|= OPTGROUP_IPA
;
517 else if (pass
->type
== GIMPLE_PASS
)
528 flag_name
= concat (prefix
, name
, num
, NULL
);
529 glob_name
= concat (prefix
, name
, NULL
);
530 optgroup_flags
|= pass
->optinfo_flags
;
531 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
, optgroup_flags
);
532 set_pass_for_id (id
, pass
);
533 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
534 register_pass_name (pass
, full_name
);
535 free (CONST_CAST (char *, full_name
));
538 /* Recursive worker function for register_dump_files. */
541 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
545 int new_properties
= (properties
| pass
->properties_provided
)
546 & ~pass
->properties_destroyed
;
548 if (pass
->name
&& pass
->name
[0] != '*')
549 register_one_dump_file (pass
);
552 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
554 /* If we have a gate, combine the properties that we could have with
555 and without the pass being examined. */
557 properties
&= new_properties
;
559 properties
= new_properties
;
568 /* Register the dump files for the pipeline starting at PASS.
569 PROPERTIES reflects the properties that are guaranteed to be available at
570 the beginning of the pipeline. */
573 register_dump_files (struct opt_pass
*pass
,int properties
)
575 pass
->properties_required
|= properties
;
576 register_dump_files_1 (pass
, properties
);
581 const char* unique_name
;
582 struct opt_pass
*pass
;
585 /* Pass registry hash function. */
588 passr_hash (const void *p
)
590 const struct pass_registry
*const s
= (const struct pass_registry
*const) p
;
591 return htab_hash_string (s
->unique_name
);
594 /* Hash equal function */
597 passr_eq (const void *p1
, const void *p2
)
599 const struct pass_registry
*const s1
= (const struct pass_registry
*const) p1
;
600 const struct pass_registry
*const s2
= (const struct pass_registry
*const) p2
;
602 return !strcmp (s1
->unique_name
, s2
->unique_name
);
605 static htab_t name_to_pass_map
= NULL
;
607 /* Register PASS with NAME. */
610 register_pass_name (struct opt_pass
*pass
, const char *name
)
612 struct pass_registry
**slot
;
613 struct pass_registry pr
;
615 if (!name_to_pass_map
)
616 name_to_pass_map
= htab_create (256, passr_hash
, passr_eq
, NULL
);
618 pr
.unique_name
= name
;
619 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
, &pr
, INSERT
);
622 struct pass_registry
*new_pr
;
624 new_pr
= XCNEW (struct pass_registry
);
625 new_pr
->unique_name
= xstrdup (name
);
630 return; /* Ignore plugin passes. */
633 /* Map from pass id to canonicalized pass name. */
635 typedef const char *char_ptr
;
637 DEF_VEC_ALLOC_P(char_ptr
, heap
);
638 static VEC(char_ptr
, heap
) *pass_tab
= NULL
;
640 /* Callback function for traversing NAME_TO_PASS_MAP. */
643 pass_traverse (void **slot
, void *data ATTRIBUTE_UNUSED
)
645 struct pass_registry
**p
= (struct pass_registry
**)slot
;
646 struct opt_pass
*pass
= (*p
)->pass
;
648 gcc_assert (pass
->static_pass_number
> 0);
649 gcc_assert (pass_tab
);
651 VEC_replace (char_ptr
, pass_tab
, pass
->static_pass_number
,
657 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
658 table for dumping purpose. */
661 create_pass_tab (void)
663 if (!flag_dump_passes
)
666 VEC_safe_grow_cleared (char_ptr
, heap
,
667 pass_tab
, passes_by_id_size
+ 1);
668 htab_traverse (name_to_pass_map
, pass_traverse
, NULL
);
671 static bool override_gate_status (struct opt_pass
*, tree
, bool);
673 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
674 is turned on or not. */
677 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
679 int indent
= 3 * pass_indent
;
681 bool is_on
, is_really_on
;
683 is_on
= (pass
->gate
== NULL
) ? true : pass
->gate();
684 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
686 if (pass
->static_pass_number
<= 0)
689 pn
= VEC_index (char_ptr
, pass_tab
, pass
->static_pass_number
);
691 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
692 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
693 is_on
? " ON" : " OFF",
694 ((!is_on
) == (!is_really_on
) ? ""
695 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
698 /* Dump pass list PASS with indentation INDENT. */
701 dump_pass_list (struct opt_pass
*pass
, int indent
)
705 dump_one_pass (pass
, indent
);
707 dump_pass_list (pass
->sub
, indent
+ 1);
713 /* Dump all optimization passes. */
718 struct cgraph_node
*n
, *node
= NULL
;
722 FOR_EACH_DEFINED_FUNCTION (n
)
723 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
732 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
734 dump_pass_list (all_lowering_passes
, 1);
735 dump_pass_list (all_small_ipa_passes
, 1);
736 dump_pass_list (all_regular_ipa_passes
, 1);
737 dump_pass_list (all_lto_gen_passes
, 1);
738 dump_pass_list (all_late_ipa_passes
, 1);
739 dump_pass_list (all_passes
, 1);
745 /* Returns the pass with NAME. */
747 static struct opt_pass
*
748 get_pass_by_name (const char *name
)
750 struct pass_registry
**slot
, pr
;
752 pr
.unique_name
= name
;
753 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
,
759 return (*slot
)->pass
;
763 /* Range [start, last]. */
769 const char *assem_name
;
770 struct uid_range
*next
;
773 typedef struct uid_range
*uid_range_p
;
775 DEF_VEC_P(uid_range_p
);
776 DEF_VEC_ALLOC_P(uid_range_p
, heap
);
778 static VEC(uid_range_p
, heap
) *enabled_pass_uid_range_tab
= NULL
;
779 static VEC(uid_range_p
, heap
) *disabled_pass_uid_range_tab
= NULL
;
782 /* Parse option string for -fdisable- and -fenable-
783 The syntax of the options:
786 -fdisable-<pass_name>
788 -fenable-<pass_name>=s1:e1,s2:e2,...
789 -fdisable-<pass_name>=s1:e1,s2:e2,...
793 enable_disable_pass (const char *arg
, bool is_enable
)
795 struct opt_pass
*pass
;
796 char *range_str
, *phase_name
;
797 char *argstr
= xstrdup (arg
);
798 VEC(uid_range_p
, heap
) **tab
= 0;
800 range_str
= strchr (argstr
,'=');
811 error ("unrecognized option -fenable");
813 error ("unrecognized option -fdisable");
817 pass
= get_pass_by_name (phase_name
);
818 if (!pass
|| pass
->static_pass_number
== -1)
821 error ("unknown pass %s specified in -fenable", phase_name
);
823 error ("unknown pass %s specified in -fdisable", phase_name
);
829 tab
= &enabled_pass_uid_range_tab
;
831 tab
= &disabled_pass_uid_range_tab
;
833 if ((unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, *tab
))
834 VEC_safe_grow_cleared (uid_range_p
, heap
,
835 *tab
, pass
->static_pass_number
+ 1);
840 uid_range_p new_range
= XCNEW (struct uid_range
);
842 new_range
->start
= 0;
843 new_range
->last
= (unsigned)-1;
845 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
846 new_range
->next
= slot
;
847 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
850 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
851 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
853 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
854 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
858 char *next_range
= NULL
;
859 char *one_range
= range_str
;
860 char *end_val
= NULL
;
865 uid_range_p new_range
;
866 char *invalid
= NULL
;
868 char *func_name
= NULL
;
870 next_range
= strchr (one_range
, ',');
877 end_val
= strchr (one_range
, ':');
883 start
= strtol (one_range
, &invalid
, 10);
884 if (*invalid
|| start
< 0)
886 if (end_val
|| (one_range
[0] >= '0'
887 && one_range
[0] <= '9'))
889 error ("Invalid range %s in option %s",
891 is_enable
? "-fenable" : "-fdisable");
895 func_name
= one_range
;
899 new_range
= XCNEW (struct uid_range
);
902 new_range
->start
= (unsigned) start
;
903 new_range
->last
= (unsigned) start
;
907 new_range
->start
= (unsigned) -1;
908 new_range
->last
= (unsigned) -1;
909 new_range
->assem_name
= xstrdup (func_name
);
914 long last
= strtol (end_val
, &invalid
, 10);
915 if (*invalid
|| last
< start
)
917 error ("Invalid range %s in option %s",
919 is_enable
? "-fenable" : "-fdisable");
923 new_range
= XCNEW (struct uid_range
);
924 new_range
->start
= (unsigned) start
;
925 new_range
->last
= (unsigned) last
;
928 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
929 new_range
->next
= slot
;
930 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
934 if (new_range
->assem_name
)
935 inform (UNKNOWN_LOCATION
,
936 "enable pass %s for function %s",
937 phase_name
, new_range
->assem_name
);
939 inform (UNKNOWN_LOCATION
,
940 "enable pass %s for functions in the range of [%u, %u]",
941 phase_name
, new_range
->start
, new_range
->last
);
945 if (new_range
->assem_name
)
946 inform (UNKNOWN_LOCATION
,
947 "disable pass %s for function %s",
948 phase_name
, new_range
->assem_name
);
950 inform (UNKNOWN_LOCATION
,
951 "disable pass %s for functions in the range of [%u, %u]",
952 phase_name
, new_range
->start
, new_range
->last
);
955 one_range
= next_range
;
956 } while (next_range
);
962 /* Enable pass specified by ARG. */
965 enable_pass (const char *arg
)
967 enable_disable_pass (arg
, true);
970 /* Disable pass specified by ARG. */
973 disable_pass (const char *arg
)
975 enable_disable_pass (arg
, false);
978 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
981 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
983 VEC(uid_range_p
, heap
) *tab
)
985 uid_range_p slot
, range
;
987 const char *aname
= NULL
;
990 || (unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, tab
)
991 || pass
->static_pass_number
== -1)
994 slot
= VEC_index (uid_range_p
, tab
, pass
->static_pass_number
);
998 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
999 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
1000 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
1005 if ((unsigned) cgraph_uid
>= range
->start
1006 && (unsigned) cgraph_uid
<= range
->last
)
1008 if (range
->assem_name
&& aname
1009 && !strcmp (range
->assem_name
, aname
))
1011 range
= range
->next
;
1017 /* Look at the static_pass_number and duplicate the pass
1018 if it is already added to a list. */
1020 static struct opt_pass
*
1021 make_pass_instance (struct opt_pass
*pass
, bool track_duplicates
)
1023 /* A nonzero static_pass_number indicates that the
1024 pass is already in the list. */
1025 if (pass
->static_pass_number
)
1027 struct opt_pass
*new_pass
;
1029 if (pass
->type
== GIMPLE_PASS
1030 || pass
->type
== RTL_PASS
1031 || pass
->type
== SIMPLE_IPA_PASS
)
1033 new_pass
= XNEW (struct opt_pass
);
1034 memcpy (new_pass
, pass
, sizeof (struct opt_pass
));
1036 else if (pass
->type
== IPA_PASS
)
1038 new_pass
= (struct opt_pass
*)XNEW (struct ipa_opt_pass_d
);
1039 memcpy (new_pass
, pass
, sizeof (struct ipa_opt_pass_d
));
1044 new_pass
->next
= NULL
;
1046 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1048 /* Indicate to register_dump_files that this pass has duplicates,
1049 and so it should rename the dump file. The first instance will
1050 be -1, and be number of duplicates = -static_pass_number - 1.
1051 Subsequent instances will be > 0 and just the duplicate number. */
1052 if ((pass
->name
&& pass
->name
[0] != '*') || track_duplicates
)
1054 pass
->static_pass_number
-= 1;
1055 new_pass
->static_pass_number
= -pass
->static_pass_number
;
1061 pass
->todo_flags_start
|= TODO_mark_first_instance
;
1062 pass
->static_pass_number
= -1;
1064 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, pass
);
1069 /* Add a pass to the pass list. Duplicate the pass if it's already
1072 static struct opt_pass
**
1073 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
)
1075 /* Every pass should have a name so that plugins can refer to them. */
1076 gcc_assert (pass
->name
!= NULL
);
1078 *list
= make_pass_instance (pass
, false);
1080 return &(*list
)->next
;
1083 /* List node for an inserted pass instance. We need to keep track of all
1084 the newly-added pass instances (with 'added_pass_nodes' defined below)
1085 so that we can register their dump files after pass-positioning is finished.
1086 Registering dumping files needs to be post-processed or the
1087 static_pass_number of the opt_pass object would be modified and mess up
1088 the dump file names of future pass instances to be added. */
1090 struct pass_list_node
1092 struct opt_pass
*pass
;
1093 struct pass_list_node
*next
;
1096 static struct pass_list_node
*added_pass_nodes
= NULL
;
1097 static struct pass_list_node
*prev_added_pass_node
;
1099 /* Insert the pass at the proper position. Return true if the pass
1100 is successfully added.
1102 NEW_PASS_INFO - new pass to be inserted
1103 PASS_LIST - root of the pass list to insert the new pass to */
1106 position_pass (struct register_pass_info
*new_pass_info
,
1107 struct opt_pass
**pass_list
)
1109 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1110 bool success
= false;
1112 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1114 /* Check if the current pass is of the same type as the new pass and
1115 matches the name and the instance number of the reference pass. */
1116 if (pass
->type
== new_pass_info
->pass
->type
1118 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1119 && ((new_pass_info
->ref_pass_instance_number
== 0)
1120 || (new_pass_info
->ref_pass_instance_number
==
1121 pass
->static_pass_number
)
1122 || (new_pass_info
->ref_pass_instance_number
== 1
1123 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1125 struct opt_pass
*new_pass
;
1126 struct pass_list_node
*new_pass_node
;
1128 new_pass
= make_pass_instance (new_pass_info
->pass
, true);
1130 /* Insert the new pass instance based on the positioning op. */
1131 switch (new_pass_info
->pos_op
)
1133 case PASS_POS_INSERT_AFTER
:
1134 new_pass
->next
= pass
->next
;
1135 pass
->next
= new_pass
;
1137 /* Skip newly inserted pass to avoid repeated
1138 insertions in the case where the new pass and the
1139 existing one have the same name. */
1142 case PASS_POS_INSERT_BEFORE
:
1143 new_pass
->next
= pass
;
1145 prev_pass
->next
= new_pass
;
1147 *pass_list
= new_pass
;
1149 case PASS_POS_REPLACE
:
1150 new_pass
->next
= pass
->next
;
1152 prev_pass
->next
= new_pass
;
1154 *pass_list
= new_pass
;
1155 new_pass
->sub
= pass
->sub
;
1156 new_pass
->tv_id
= pass
->tv_id
;
1160 error ("invalid pass positioning operation");
1164 /* Save the newly added pass (instance) in the added_pass_nodes
1165 list so that we can register its dump file later. Note that
1166 we cannot register the dump file now because doing so will modify
1167 the static_pass_number of the opt_pass object and therefore
1168 mess up the dump file name of future instances. */
1169 new_pass_node
= XCNEW (struct pass_list_node
);
1170 new_pass_node
->pass
= new_pass
;
1171 if (!added_pass_nodes
)
1172 added_pass_nodes
= new_pass_node
;
1174 prev_added_pass_node
->next
= new_pass_node
;
1175 prev_added_pass_node
= new_pass_node
;
1180 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1187 /* Hooks a new pass into the pass lists.
1189 PASS_INFO - pass information that specifies the opt_pass object,
1190 reference pass, instance number, and how to position
1194 register_pass (struct register_pass_info
*pass_info
)
1196 bool all_instances
, success
;
1198 /* The checks below could fail in buggy plugins. Existing GCC
1199 passes should never fail these checks, so we mention plugin in
1201 if (!pass_info
->pass
)
1202 fatal_error ("plugin cannot register a missing pass");
1204 if (!pass_info
->pass
->name
)
1205 fatal_error ("plugin cannot register an unnamed pass");
1207 if (!pass_info
->reference_pass_name
)
1209 ("plugin cannot register pass %qs without reference pass name",
1210 pass_info
->pass
->name
);
1212 /* Try to insert the new pass to the pass lists. We need to check
1213 all five lists as the reference pass could be in one (or all) of
1215 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1216 success
= position_pass (pass_info
, &all_lowering_passes
);
1217 if (!success
|| all_instances
)
1218 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1219 if (!success
|| all_instances
)
1220 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1221 if (!success
|| all_instances
)
1222 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1223 if (!success
|| all_instances
)
1224 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1225 if (!success
|| all_instances
)
1226 success
|= position_pass (pass_info
, &all_passes
);
1229 ("pass %qs not found but is referenced by new pass %qs",
1230 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1232 /* OK, we have successfully inserted the new pass. We need to register
1233 the dump files for the newly added pass and its duplicates (if any).
1234 Because the registration of plugin/backend passes happens after the
1235 command-line options are parsed, the options that specify single
1236 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1237 passes. Therefore we currently can only enable dumping of
1238 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1239 are specified. While doing so, we also delete the pass_list_node
1240 objects created during pass positioning. */
1241 while (added_pass_nodes
)
1243 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1244 enum tree_dump_index tdi
;
1245 register_one_dump_file (added_pass_nodes
->pass
);
1246 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1247 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1249 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1253 /* Check if dump-all flag is specified. */
1254 if (get_dump_file_info (tdi
)->pstate
)
1255 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1256 ->pstate
= get_dump_file_info (tdi
)->pstate
;
1257 XDELETE (added_pass_nodes
);
1258 added_pass_nodes
= next_node
;
1262 /* Construct the pass tree. The sequencing of passes is driven by
1263 the cgraph routines:
1265 finalize_compilation_unit ()
1266 for each node N in the cgraph
1267 cgraph_analyze_function (N)
1268 cgraph_lower_function (N) -> all_lowering_passes
1270 If we are optimizing, compile is then invoked:
1273 ipa_passes () -> all_small_ipa_passes
1274 -> Analysis of all_regular_ipa_passes
1275 * possible LTO streaming at copmilation time *
1276 -> Execution of all_regular_ipa_passes
1277 * possible LTO streaming at link time *
1278 -> all_late_ipa_passes
1279 expand_all_functions ()
1280 for each node N in the cgraph
1281 expand_function (N) -> Transformation of all_regular_ipa_passes
1286 init_optimization_passes (void)
1288 struct opt_pass
**p
;
1290 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1292 /* All passes needed to lower the function into shape optimizers can
1293 operate on. These passes are always run first on the function, but
1294 backend might produce already lowered functions that are not processed
1296 p
= &all_lowering_passes
;
1297 NEXT_PASS (pass_warn_unused_result
);
1298 NEXT_PASS (pass_diagnose_omp_blocks
);
1299 NEXT_PASS (pass_diagnose_tm_blocks
);
1300 NEXT_PASS (pass_mudflap_1
);
1301 NEXT_PASS (pass_lower_omp
);
1302 NEXT_PASS (pass_lower_cf
);
1303 NEXT_PASS (pass_lower_tm
);
1304 NEXT_PASS (pass_refactor_eh
);
1305 NEXT_PASS (pass_lower_eh
);
1306 NEXT_PASS (pass_build_cfg
);
1307 NEXT_PASS (pass_warn_function_return
);
1308 NEXT_PASS (pass_build_cgraph_edges
);
1311 /* Interprocedural optimization passes. */
1312 p
= &all_small_ipa_passes
;
1313 NEXT_PASS (pass_ipa_free_lang_data
);
1314 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
1315 NEXT_PASS (pass_early_local_passes
);
1317 struct opt_pass
**p
= &pass_early_local_passes
.pass
.sub
;
1318 NEXT_PASS (pass_fixup_cfg
);
1319 NEXT_PASS (pass_init_datastructures
);
1320 NEXT_PASS (pass_expand_omp
);
1322 NEXT_PASS (pass_build_ssa
);
1323 NEXT_PASS (pass_lower_vector
);
1324 NEXT_PASS (pass_early_warn_uninitialized
);
1325 NEXT_PASS (pass_rebuild_cgraph_edges
);
1326 NEXT_PASS (pass_inline_parameters
);
1327 NEXT_PASS (pass_early_inline
);
1328 NEXT_PASS (pass_all_early_optimizations
);
1330 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1331 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1332 NEXT_PASS (pass_rename_ssa_copies
);
1333 NEXT_PASS (pass_ccp
);
1334 /* After CCP we rewrite no longer addressed locals into SSA
1335 form if possible. */
1336 NEXT_PASS (pass_forwprop
);
1337 /* pass_build_ealias is a dummy pass that ensures that we
1338 execute TODO_rebuild_alias at this point. */
1339 NEXT_PASS (pass_build_ealias
);
1340 NEXT_PASS (pass_sra_early
);
1341 NEXT_PASS (pass_fre
);
1342 NEXT_PASS (pass_copy_prop
);
1343 NEXT_PASS (pass_merge_phi
);
1344 NEXT_PASS (pass_cd_dce
);
1345 NEXT_PASS (pass_early_ipa_sra
);
1346 NEXT_PASS (pass_tail_recursion
);
1347 NEXT_PASS (pass_convert_switch
);
1348 NEXT_PASS (pass_cleanup_eh
);
1349 NEXT_PASS (pass_profile
);
1350 NEXT_PASS (pass_local_pure_const
);
1351 /* Split functions creates parts that are not run through
1352 early optimizations again. It is thus good idea to do this
1354 NEXT_PASS (pass_split_functions
);
1356 NEXT_PASS (pass_release_ssa_names
);
1357 NEXT_PASS (pass_rebuild_cgraph_edges
);
1358 NEXT_PASS (pass_inline_parameters
);
1360 NEXT_PASS (pass_ipa_free_inline_summary
);
1361 NEXT_PASS (pass_ipa_tree_profile
);
1363 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1364 NEXT_PASS (pass_feedback_split_functions
);
1366 NEXT_PASS (pass_ipa_increase_alignment
);
1367 NEXT_PASS (pass_ipa_tm
);
1368 NEXT_PASS (pass_ipa_lower_emutls
);
1371 p
= &all_regular_ipa_passes
;
1372 NEXT_PASS (pass_ipa_whole_program_visibility
);
1373 NEXT_PASS (pass_ipa_profile
);
1374 NEXT_PASS (pass_ipa_cp
);
1375 NEXT_PASS (pass_ipa_cdtor_merge
);
1376 NEXT_PASS (pass_ipa_inline
);
1377 NEXT_PASS (pass_ipa_pure_const
);
1378 NEXT_PASS (pass_ipa_reference
);
1381 p
= &all_lto_gen_passes
;
1382 NEXT_PASS (pass_ipa_lto_gimple_out
);
1383 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1386 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1387 passes are executed after partitioning and thus see just parts of the
1389 p
= &all_late_ipa_passes
;
1390 NEXT_PASS (pass_ipa_pta
);
1393 /* These passes are run after IPA passes on every function that is being
1394 output to the assembler file. */
1396 NEXT_PASS (pass_fixup_cfg
);
1397 NEXT_PASS (pass_lower_eh_dispatch
);
1398 NEXT_PASS (pass_all_optimizations
);
1400 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1401 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1402 /* Initial scalar cleanups before alias computation.
1403 They ensure memory accesses are not indirect wherever possible. */
1404 NEXT_PASS (pass_strip_predict_hints
);
1405 NEXT_PASS (pass_rename_ssa_copies
);
1406 NEXT_PASS (pass_complete_unrolli
);
1407 NEXT_PASS (pass_ccp
);
1408 /* After CCP we rewrite no longer addressed locals into SSA
1409 form if possible. */
1410 NEXT_PASS (pass_forwprop
);
1411 /* pass_build_alias is a dummy pass that ensures that we
1412 execute TODO_rebuild_alias at this point. */
1413 NEXT_PASS (pass_build_alias
);
1414 NEXT_PASS (pass_return_slot
);
1415 NEXT_PASS (pass_phiprop
);
1416 NEXT_PASS (pass_fre
);
1417 NEXT_PASS (pass_copy_prop
);
1418 NEXT_PASS (pass_merge_phi
);
1419 NEXT_PASS (pass_vrp
);
1420 NEXT_PASS (pass_dce
);
1421 NEXT_PASS (pass_call_cdce
);
1422 NEXT_PASS (pass_cselim
);
1423 NEXT_PASS (pass_tree_ifcombine
);
1424 NEXT_PASS (pass_phiopt
);
1425 NEXT_PASS (pass_tail_recursion
);
1426 NEXT_PASS (pass_ch
);
1427 NEXT_PASS (pass_stdarg
);
1428 NEXT_PASS (pass_lower_complex
);
1429 NEXT_PASS (pass_sra
);
1430 NEXT_PASS (pass_rename_ssa_copies
);
1431 /* The dom pass will also resolve all __builtin_constant_p calls
1432 that are still there to 0. This has to be done after some
1433 propagations have already run, but before some more dead code
1434 is removed, and this place fits nicely. Remember this when
1435 trying to move or duplicate pass_dominator somewhere earlier. */
1436 NEXT_PASS (pass_dominator
);
1437 /* The only const/copy propagation opportunities left after
1438 DOM should be due to degenerate PHI nodes. So rather than
1439 run the full propagators, run a specialized pass which
1440 only examines PHIs to discover const/copy propagation
1442 NEXT_PASS (pass_phi_only_cprop
);
1443 NEXT_PASS (pass_dse
);
1444 NEXT_PASS (pass_reassoc
);
1445 NEXT_PASS (pass_dce
);
1446 NEXT_PASS (pass_forwprop
);
1447 NEXT_PASS (pass_phiopt
);
1448 NEXT_PASS (pass_object_sizes
);
1449 NEXT_PASS (pass_strlen
);
1450 NEXT_PASS (pass_ccp
);
1451 /* After CCP we rewrite no longer addressed locals into SSA
1452 form if possible. */
1453 NEXT_PASS (pass_copy_prop
);
1454 NEXT_PASS (pass_cse_sincos
);
1455 NEXT_PASS (pass_optimize_bswap
);
1456 NEXT_PASS (pass_split_crit_edges
);
1457 NEXT_PASS (pass_pre
);
1458 NEXT_PASS (pass_sink_code
);
1459 NEXT_PASS (pass_tree_loop
);
1461 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1462 NEXT_PASS (pass_tree_loop_init
);
1463 NEXT_PASS (pass_lim
);
1464 NEXT_PASS (pass_copy_prop
);
1465 NEXT_PASS (pass_dce_loop
);
1466 NEXT_PASS (pass_tree_unswitch
);
1467 NEXT_PASS (pass_scev_cprop
);
1468 NEXT_PASS (pass_record_bounds
);
1469 NEXT_PASS (pass_check_data_deps
);
1470 NEXT_PASS (pass_loop_distribution
);
1471 NEXT_PASS (pass_copy_prop
);
1472 NEXT_PASS (pass_graphite
);
1474 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1475 NEXT_PASS (pass_graphite_transforms
);
1476 NEXT_PASS (pass_lim
);
1477 NEXT_PASS (pass_copy_prop
);
1478 NEXT_PASS (pass_dce_loop
);
1480 NEXT_PASS (pass_iv_canon
);
1481 NEXT_PASS (pass_if_conversion
);
1482 NEXT_PASS (pass_vectorize
);
1484 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1485 NEXT_PASS (pass_dce_loop
);
1487 NEXT_PASS (pass_predcom
);
1488 NEXT_PASS (pass_complete_unroll
);
1489 NEXT_PASS (pass_slp_vectorize
);
1490 NEXT_PASS (pass_parallelize_loops
);
1491 NEXT_PASS (pass_loop_prefetch
);
1492 NEXT_PASS (pass_iv_optimize
);
1493 NEXT_PASS (pass_lim
);
1494 NEXT_PASS (pass_tree_loop_done
);
1496 NEXT_PASS (pass_lower_vector_ssa
);
1497 NEXT_PASS (pass_cse_reciprocals
);
1498 NEXT_PASS (pass_reassoc
);
1499 NEXT_PASS (pass_vrp
);
1500 NEXT_PASS (pass_strength_reduction
);
1501 NEXT_PASS (pass_dominator
);
1502 /* The only const/copy propagation opportunities left after
1503 DOM should be due to degenerate PHI nodes. So rather than
1504 run the full propagators, run a specialized pass which
1505 only examines PHIs to discover const/copy propagation
1507 NEXT_PASS (pass_phi_only_cprop
);
1508 NEXT_PASS (pass_cd_dce
);
1509 NEXT_PASS (pass_tracer
);
1511 /* FIXME: If DCE is not run before checking for uninitialized uses,
1512 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1513 However, this also causes us to misdiagnose cases that should be
1514 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1516 To fix the false positives in uninit-5.c, we would have to
1517 account for the predicates protecting the set and the use of each
1518 variable. Using a representation like Gated Single Assignment
1520 NEXT_PASS (pass_late_warn_uninitialized
);
1521 NEXT_PASS (pass_dse
);
1522 NEXT_PASS (pass_forwprop
);
1523 NEXT_PASS (pass_phiopt
);
1524 NEXT_PASS (pass_fold_builtins
);
1525 NEXT_PASS (pass_optimize_widening_mul
);
1526 NEXT_PASS (pass_tail_calls
);
1527 NEXT_PASS (pass_rename_ssa_copies
);
1528 NEXT_PASS (pass_uncprop
);
1529 NEXT_PASS (pass_local_pure_const
);
1531 NEXT_PASS (pass_all_optimizations_g
);
1533 struct opt_pass
**p
= &pass_all_optimizations_g
.pass
.sub
;
1534 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1535 NEXT_PASS (pass_strip_predict_hints
);
1536 /* Lower remaining pieces of GIMPLE. */
1537 NEXT_PASS (pass_lower_complex
);
1538 NEXT_PASS (pass_lower_vector_ssa
);
1539 /* Perform simple scalar cleanup which is constant/copy propagation. */
1540 NEXT_PASS (pass_ccp
);
1541 NEXT_PASS (pass_object_sizes
);
1542 /* Copy propagation also copy-propagates constants, this is necessary
1543 to forward object-size results properly. */
1544 NEXT_PASS (pass_copy_prop
);
1545 NEXT_PASS (pass_rename_ssa_copies
);
1546 NEXT_PASS (pass_dce
);
1547 /* Fold remaining builtins. */
1548 NEXT_PASS (pass_fold_builtins
);
1549 /* ??? We do want some kind of loop invariant motion, but we possibly
1550 need to adjust LIM to be more friendly towards preserving accurate
1551 debug information here. */
1552 NEXT_PASS (pass_late_warn_uninitialized
);
1553 NEXT_PASS (pass_uncprop
);
1554 NEXT_PASS (pass_local_pure_const
);
1556 NEXT_PASS (pass_tm_init
);
1558 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1559 NEXT_PASS (pass_tm_mark
);
1560 NEXT_PASS (pass_tm_memopt
);
1561 NEXT_PASS (pass_tm_edges
);
1563 NEXT_PASS (pass_lower_complex_O0
);
1564 NEXT_PASS (pass_cleanup_eh
);
1565 NEXT_PASS (pass_lower_resx
);
1566 NEXT_PASS (pass_nrv
);
1567 NEXT_PASS (pass_mudflap_2
);
1568 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
1569 NEXT_PASS (pass_warn_function_noreturn
);
1571 NEXT_PASS (pass_expand
);
1573 NEXT_PASS (pass_rest_of_compilation
);
1575 struct opt_pass
**p
= &pass_rest_of_compilation
.pass
.sub
;
1576 NEXT_PASS (pass_instantiate_virtual_regs
);
1577 NEXT_PASS (pass_into_cfg_layout_mode
);
1578 NEXT_PASS (pass_jump
);
1579 NEXT_PASS (pass_lower_subreg
);
1580 NEXT_PASS (pass_df_initialize_opt
);
1581 NEXT_PASS (pass_cse
);
1582 NEXT_PASS (pass_rtl_fwprop
);
1583 NEXT_PASS (pass_rtl_cprop
);
1584 NEXT_PASS (pass_rtl_pre
);
1585 NEXT_PASS (pass_rtl_hoist
);
1586 NEXT_PASS (pass_rtl_cprop
);
1587 NEXT_PASS (pass_rtl_store_motion
);
1588 NEXT_PASS (pass_cse_after_global_opts
);
1589 NEXT_PASS (pass_rtl_ifcvt
);
1590 NEXT_PASS (pass_reginfo_init
);
1591 /* Perform loop optimizations. It might be better to do them a bit
1592 sooner, but we want the profile feedback to work more
1594 NEXT_PASS (pass_loop2
);
1596 struct opt_pass
**p
= &pass_loop2
.pass
.sub
;
1597 NEXT_PASS (pass_rtl_loop_init
);
1598 NEXT_PASS (pass_rtl_move_loop_invariants
);
1599 NEXT_PASS (pass_rtl_unswitch
);
1600 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
1601 NEXT_PASS (pass_rtl_doloop
);
1602 NEXT_PASS (pass_rtl_loop_done
);
1605 NEXT_PASS (pass_web
);
1606 NEXT_PASS (pass_rtl_cprop
);
1607 NEXT_PASS (pass_cse2
);
1608 NEXT_PASS (pass_rtl_dse1
);
1609 NEXT_PASS (pass_rtl_fwprop_addr
);
1610 NEXT_PASS (pass_inc_dec
);
1611 NEXT_PASS (pass_initialize_regs
);
1612 NEXT_PASS (pass_ud_rtl_dce
);
1613 NEXT_PASS (pass_combine
);
1614 NEXT_PASS (pass_if_after_combine
);
1615 NEXT_PASS (pass_partition_blocks
);
1616 NEXT_PASS (pass_regmove
);
1617 NEXT_PASS (pass_outof_cfg_layout_mode
);
1618 NEXT_PASS (pass_split_all_insns
);
1619 NEXT_PASS (pass_lower_subreg2
);
1620 NEXT_PASS (pass_df_initialize_no_opt
);
1621 NEXT_PASS (pass_stack_ptr_mod
);
1622 NEXT_PASS (pass_mode_switching
);
1623 NEXT_PASS (pass_match_asm_constraints
);
1624 NEXT_PASS (pass_sms
);
1625 NEXT_PASS (pass_sched
);
1626 NEXT_PASS (pass_ira
);
1627 NEXT_PASS (pass_reload
);
1628 NEXT_PASS (pass_postreload
);
1630 struct opt_pass
**p
= &pass_postreload
.pass
.sub
;
1631 NEXT_PASS (pass_postreload_cse
);
1632 NEXT_PASS (pass_gcse2
);
1633 NEXT_PASS (pass_split_after_reload
);
1634 NEXT_PASS (pass_ree
);
1635 NEXT_PASS (pass_compare_elim_after_reload
);
1636 NEXT_PASS (pass_branch_target_load_optimize1
);
1637 NEXT_PASS (pass_thread_prologue_and_epilogue
);
1638 NEXT_PASS (pass_rtl_dse2
);
1639 NEXT_PASS (pass_stack_adjustments
);
1640 NEXT_PASS (pass_jump2
);
1641 NEXT_PASS (pass_peephole2
);
1642 NEXT_PASS (pass_if_after_reload
);
1643 NEXT_PASS (pass_regrename
);
1644 NEXT_PASS (pass_cprop_hardreg
);
1645 NEXT_PASS (pass_fast_rtl_dce
);
1646 NEXT_PASS (pass_reorder_blocks
);
1647 NEXT_PASS (pass_branch_target_load_optimize2
);
1648 NEXT_PASS (pass_leaf_regs
);
1649 NEXT_PASS (pass_split_before_sched2
);
1650 NEXT_PASS (pass_sched2
);
1651 NEXT_PASS (pass_stack_regs
);
1653 struct opt_pass
**p
= &pass_stack_regs
.pass
.sub
;
1654 NEXT_PASS (pass_split_before_regstack
);
1655 NEXT_PASS (pass_stack_regs_run
);
1657 NEXT_PASS (pass_compute_alignments
);
1658 NEXT_PASS (pass_duplicate_computed_gotos
);
1659 NEXT_PASS (pass_variable_tracking
);
1660 NEXT_PASS (pass_free_cfg
);
1661 NEXT_PASS (pass_machine_reorg
);
1662 NEXT_PASS (pass_cleanup_barriers
);
1663 NEXT_PASS (pass_delay_slots
);
1664 NEXT_PASS (pass_split_for_shorten_branches
);
1665 NEXT_PASS (pass_convert_to_eh_region_ranges
);
1666 NEXT_PASS (pass_shorten_branches
);
1667 NEXT_PASS (pass_set_nothrow_function_flags
);
1668 NEXT_PASS (pass_dwarf2_frame
);
1669 NEXT_PASS (pass_final
);
1671 NEXT_PASS (pass_df_finish
);
1673 NEXT_PASS (pass_clean_state
);
1678 /* Register the passes with the tree dump code. */
1679 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1680 register_dump_files (all_small_ipa_passes
,
1681 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1683 register_dump_files (all_regular_ipa_passes
,
1684 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1686 register_dump_files (all_lto_gen_passes
,
1687 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1689 register_dump_files (all_late_ipa_passes
,
1690 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1692 register_dump_files (all_passes
,
1693 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1697 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1698 function CALLBACK for every function in the call graph. Otherwise,
1699 call CALLBACK on the current function. */
1702 do_per_function (void (*callback
) (void *data
), void *data
)
1704 if (current_function_decl
)
1708 struct cgraph_node
*node
;
1709 FOR_EACH_DEFINED_FUNCTION (node
)
1710 if (gimple_has_body_p (node
->symbol
.decl
)
1711 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1713 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1717 free_dominance_info (CDI_DOMINATORS
);
1718 free_dominance_info (CDI_POST_DOMINATORS
);
1726 /* Because inlining might remove no-longer reachable nodes, we need to
1727 keep the array visible to garbage collector to avoid reading collected
1730 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1732 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1733 function CALLBACK for every function in the call graph. Otherwise,
1734 call CALLBACK on the current function.
1735 This function is global so that plugins can use it. */
1737 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1741 if (current_function_decl
)
1745 gcc_assert (!order
);
1746 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1747 nnodes
= ipa_reverse_postorder (order
);
1748 for (i
= nnodes
- 1; i
>= 0; i
--)
1749 order
[i
]->process
= 1;
1750 for (i
= nnodes
- 1; i
>= 0; i
--)
1752 struct cgraph_node
*node
= order
[i
];
1754 /* Allow possibly removed nodes to be garbage collected. */
1757 if (cgraph_function_with_gimple_body_p (node
))
1759 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1761 free_dominance_info (CDI_DOMINATORS
);
1762 free_dominance_info (CDI_POST_DOMINATORS
);
1773 /* Helper function to perform function body dump. */
1776 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1778 if (dump_file
&& current_function_decl
)
1780 if (cfun
->curr_properties
& PROP_trees
)
1781 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1784 print_rtl_with_bb (dump_file
, get_insns (), dump_flags
);
1786 if ((cfun
->curr_properties
& PROP_cfg
)
1787 && graph_dump_format
!= no_graph
1788 && (dump_flags
& TDF_GRAPH
))
1789 print_rtl_graph_with_bb (dump_file_name
, get_insns ());
1792 /* Flush the file. If verification fails, we won't be able to
1793 close the file before aborting. */
1798 static struct profile_record
*profile_record
;
1800 /* Do profile consistency book-keeping for the pass with static number INDEX.
1801 If SUBPASS is zero, we run _before_ the pass, and if SUBPASS is one, then
1802 we run _after_ the pass. RUN is true if the pass really runs, or FALSE
1803 if we are only book-keeping on passes that may have selectively disabled
1804 themselves on a given function. */
1806 check_profile_consistency (int index
, int subpass
, bool run
)
1810 if (!profile_record
)
1811 profile_record
= XCNEWVEC (struct profile_record
,
1813 gcc_assert (index
< passes_by_id_size
&& index
>= 0);
1814 gcc_assert (subpass
< 2);
1815 profile_record
[index
].run
|= run
;
1816 account_profile_record (&profile_record
[index
], subpass
);
1819 /* Output profile consistency. */
1822 dump_profile_report (void)
1825 int last_freq_in
= 0, last_count_in
= 0, last_freq_out
= 0, last_count_out
= 0;
1826 gcov_type last_time
= 0, last_size
= 0;
1827 double rel_time_change
, rel_size_change
;
1828 int last_reported
= 0;
1830 if (!profile_record
)
1832 fprintf (stderr
, "\nProfile consistency report:\n\n");
1833 fprintf (stderr
, "Pass name |mismatch in |mismated out|Overall\n");
1834 fprintf (stderr
, " |freq count |freq count |size time\n");
1836 for (i
= 0; i
< passes_by_id_size
; i
++)
1837 for (j
= 0 ; j
< 2; j
++)
1838 if (profile_record
[i
].run
)
1841 rel_time_change
= (profile_record
[i
].time
[j
]
1842 - (double)last_time
) * 100 / (double)last_time
;
1844 rel_time_change
= 0;
1846 rel_size_change
= (profile_record
[i
].size
[j
]
1847 - (double)last_size
) * 100 / (double)last_size
;
1849 rel_size_change
= 0;
1851 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
1852 || profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
1853 || profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
1854 || profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
1855 || rel_time_change
|| rel_size_change
)
1858 fprintf (stderr
, "%-20s %s",
1859 passes_by_id
[i
]->name
,
1860 j
? "(after TODO)" : " ");
1861 if (profile_record
[i
].num_mismatched_freq_in
[j
] != last_freq_in
)
1862 fprintf (stderr
, "| %+5i",
1863 profile_record
[i
].num_mismatched_freq_in
[j
]
1866 fprintf (stderr
, "| ");
1867 if (profile_record
[i
].num_mismatched_count_in
[j
] != last_count_in
)
1868 fprintf (stderr
, " %+5i",
1869 profile_record
[i
].num_mismatched_count_in
[j
]
1872 fprintf (stderr
, " ");
1873 if (profile_record
[i
].num_mismatched_freq_out
[j
] != last_freq_out
)
1874 fprintf (stderr
, "| %+5i",
1875 profile_record
[i
].num_mismatched_freq_out
[j
]
1878 fprintf (stderr
, "| ");
1879 if (profile_record
[i
].num_mismatched_count_out
[j
] != last_count_out
)
1880 fprintf (stderr
, " %+5i",
1881 profile_record
[i
].num_mismatched_count_out
[j
]
1884 fprintf (stderr
, " ");
1886 /* Size/time units change across gimple and RTL. */
1887 if (i
== pass_expand
.pass
.static_pass_number
)
1888 fprintf (stderr
, "|----------");
1891 if (rel_size_change
)
1892 fprintf (stderr
, "| %+8.4f%%", rel_size_change
);
1894 fprintf (stderr
, "| ");
1895 if (rel_time_change
)
1896 fprintf (stderr
, " %+8.4f%%", rel_time_change
);
1898 fprintf (stderr
, "\n");
1899 last_freq_in
= profile_record
[i
].num_mismatched_freq_in
[j
];
1900 last_freq_out
= profile_record
[i
].num_mismatched_freq_out
[j
];
1901 last_count_in
= profile_record
[i
].num_mismatched_count_in
[j
];
1902 last_count_out
= profile_record
[i
].num_mismatched_count_out
[j
];
1904 else if (j
&& last_reported
!= i
)
1907 fprintf (stderr
, "%-20s ------------| | |\n",
1908 passes_by_id
[i
]->name
);
1910 last_time
= profile_record
[i
].time
[j
];
1911 last_size
= profile_record
[i
].size
[j
];
1915 /* Perform all TODO actions that ought to be done on each function. */
1918 execute_function_todo (void *data
)
1920 unsigned int flags
= (size_t)data
;
1921 flags
&= ~cfun
->last_verified
;
1925 /* Always cleanup the CFG before trying to update SSA. */
1926 if (flags
& TODO_cleanup_cfg
)
1928 bool cleanup
= cleanup_tree_cfg ();
1930 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
1931 flags
|= TODO_remove_unused_locals
;
1933 /* When cleanup_tree_cfg merges consecutive blocks, it may
1934 perform some simplistic propagation when removing single
1935 valued PHI nodes. This propagation may, in turn, cause the
1936 SSA form to become out-of-date (see PR 22037). So, even
1937 if the parent pass had not scheduled an SSA update, we may
1938 still need to do one. */
1939 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1940 flags
|= TODO_update_ssa
;
1943 if (flags
& TODO_update_ssa_any
)
1945 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1946 update_ssa (update_flags
);
1947 cfun
->last_verified
&= ~TODO_verify_ssa
;
1950 if (flag_tree_pta
&& (flags
& TODO_rebuild_alias
))
1951 compute_may_aliases ();
1953 if (optimize
&& (flags
& TODO_update_address_taken
))
1954 execute_update_addresses_taken ();
1956 if (flags
& TODO_remove_unused_locals
)
1957 remove_unused_locals ();
1959 if (flags
& TODO_rebuild_frequencies
)
1960 rebuild_frequencies ();
1962 if (flags
& TODO_rebuild_cgraph_edges
)
1963 rebuild_cgraph_edges ();
1965 /* If we've seen errors do not bother running any verifiers. */
1969 #if defined ENABLE_CHECKING
1970 if (flags
& TODO_verify_ssa
1971 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1973 verify_gimple_in_cfg (cfun
);
1976 else if (flags
& TODO_verify_stmts
)
1977 verify_gimple_in_cfg (cfun
);
1978 if (flags
& TODO_verify_flow
)
1979 verify_flow_info ();
1980 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1981 verify_loop_closed_ssa (false);
1982 if (flags
& TODO_verify_rtl_sharing
)
1983 verify_rtl_sharing ();
1986 cfun
->last_verified
= flags
& TODO_verify_all
;
1989 /* Perform all TODO actions. */
1991 execute_todo (unsigned int flags
)
1993 #if defined ENABLE_CHECKING
1995 && need_ssa_update_p (cfun
))
1996 gcc_assert (flags
& TODO_update_ssa_any
);
1999 timevar_push (TV_TODO
);
2001 /* Inform the pass whether it is the first time it is run. */
2002 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
2004 statistics_fini_pass ();
2006 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
2008 /* Always remove functions just as before inlining: IPA passes might be
2009 interested to see bodies of extern inline functions that are not inlined
2010 to analyze side effects. The full removal is done just at the end
2011 of IPA pass queue. */
2012 if (flags
& TODO_remove_functions
)
2015 symtab_remove_unreachable_nodes (true, dump_file
);
2018 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
2021 dump_symtab (dump_file
);
2022 /* Flush the file. If verification fails, we won't be able to
2023 close the file before aborting. */
2027 if (flags
& TODO_ggc_collect
)
2030 /* Now that the dumping has been done, we can get rid of the optional
2032 if (flags
& TODO_df_finish
)
2033 df_finish_pass ((flags
& TODO_df_verify
) != 0);
2035 timevar_pop (TV_TODO
);
2038 /* Verify invariants that should hold between passes. This is a place
2039 to put simple sanity checks. */
2042 verify_interpass_invariants (void)
2044 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
2047 /* Clear the last verified flag. */
2050 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
2052 cfun
->last_verified
= 0;
2055 /* Helper function. Verify that the properties has been turn into the
2056 properties expected by the pass. */
2058 #ifdef ENABLE_CHECKING
2060 verify_curr_properties (void *data
)
2062 unsigned int props
= (size_t)data
;
2063 gcc_assert ((cfun
->curr_properties
& props
) == props
);
2067 /* Initialize pass dump file. */
2068 /* This is non-static so that the plugins can use it. */
2071 pass_init_dump_file (struct opt_pass
*pass
)
2073 /* If a dump file name is present, open it if enabled. */
2074 if (pass
->static_pass_number
!= -1)
2076 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
2077 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
2078 dump_start (pass
->static_pass_number
, &dump_flags
);
2079 if (dump_file
&& current_function_decl
)
2080 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
2081 return initializing_dump
;
2087 /* Flush PASS dump file. */
2088 /* This is non-static so that plugins can use it. */
2091 pass_fini_dump_file (struct opt_pass
*pass
)
2093 /* Flush and close dump file. */
2096 free (CONST_CAST (char *, dump_file_name
));
2097 dump_file_name
= NULL
;
2100 dump_finish (pass
->static_pass_number
);
2103 /* After executing the pass, apply expected changes to the function
2107 update_properties_after_pass (void *data
)
2109 struct opt_pass
*pass
= (struct opt_pass
*) data
;
2110 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
2111 & ~pass
->properties_destroyed
;
2114 /* Execute summary generation for all of the passes in IPA_PASS. */
2117 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
2121 struct opt_pass
*pass
= &ipa_pass
->pass
;
2123 /* Execute all of the IPA_PASSes in the list. */
2124 if (ipa_pass
->pass
.type
== IPA_PASS
2125 && (!pass
->gate
|| pass
->gate ())
2126 && ipa_pass
->generate_summary
)
2128 pass_init_dump_file (pass
);
2130 /* If a timevar is present, start it. */
2132 timevar_push (pass
->tv_id
);
2134 ipa_pass
->generate_summary ();
2138 timevar_pop (pass
->tv_id
);
2140 pass_fini_dump_file (pass
);
2142 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->pass
.next
;
2146 /* Execute IPA_PASS function transform on NODE. */
2149 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2150 struct ipa_opt_pass_d
*ipa_pass
)
2152 struct opt_pass
*pass
= &ipa_pass
->pass
;
2153 unsigned int todo_after
= 0;
2155 current_pass
= pass
;
2156 if (!ipa_pass
->function_transform
)
2159 /* Note that the folders should only create gimple expressions.
2160 This is a hack until the new folder is ready. */
2161 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2163 pass_init_dump_file (pass
);
2165 /* Run pre-pass verification. */
2166 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2168 /* If a timevar is present, start it. */
2169 if (pass
->tv_id
!= TV_NONE
)
2170 timevar_push (pass
->tv_id
);
2173 todo_after
= ipa_pass
->function_transform (node
);
2176 if (pass
->tv_id
!= TV_NONE
)
2177 timevar_pop (pass
->tv_id
);
2179 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2180 check_profile_consistency (pass
->static_pass_number
, 0, true);
2182 /* Run post-pass cleanup and verification. */
2183 execute_todo (todo_after
);
2184 verify_interpass_invariants ();
2185 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2186 check_profile_consistency (pass
->static_pass_number
, 1, true);
2188 do_per_function (execute_function_dump
, NULL
);
2189 pass_fini_dump_file (pass
);
2191 current_pass
= NULL
;
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
)
2208 for (i
= 0; i
< VEC_length (ipa_opt_pass
, node
->ipa_transforms_to_apply
);
2210 execute_one_ipa_transform_pass (node
,
2211 VEC_index (ipa_opt_pass
,
2212 node
->ipa_transforms_to_apply
,
2214 VEC_free (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
);
2215 node
->ipa_transforms_to_apply
= NULL
;
2219 /* Callback for do_per_function to apply all IPA transforms. */
2222 apply_ipa_transforms (void *data
)
2224 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2225 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
)
2227 *(bool *)data
= true;
2228 execute_all_ipa_transforms();
2229 rebuild_cgraph_edges ();
2233 /* Check if PASS is explicitly disabled or enabled and return
2234 the gate status. FUNC is the function to be processed, and
2235 GATE_STATUS is the gate status determined by pass manager by
2239 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2241 bool explicitly_enabled
= false;
2242 bool explicitly_disabled
= false;
2245 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2246 enabled_pass_uid_range_tab
);
2248 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2249 disabled_pass_uid_range_tab
);
2251 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2260 execute_one_pass (struct opt_pass
*pass
)
2262 bool initializing_dump
;
2263 unsigned int todo_after
= 0;
2267 /* IPA passes are executed on whole program, so cfun should be NULL.
2268 Other passes need function context set. */
2269 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2270 gcc_assert (!cfun
&& !current_function_decl
);
2272 gcc_assert (cfun
&& current_function_decl
);
2274 current_pass
= pass
;
2276 /* Check whether gate check should be avoided.
2277 User controls the value of the gate through the parameter "gate_status". */
2278 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2279 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2281 /* Override gate with plugin. */
2282 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2286 /* Run so passes selectively disabling themselves on a given function
2287 are not miscounted. */
2288 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2290 check_profile_consistency (pass
->static_pass_number
, 0, false);
2291 check_profile_consistency (pass
->static_pass_number
, 1, false);
2293 current_pass
= NULL
;
2297 /* Pass execution event trigger: useful to identify passes being
2299 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2301 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2302 Apply all trnasforms first. */
2303 if (pass
->type
== SIMPLE_IPA_PASS
)
2305 bool applied
= false;
2306 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2308 symtab_remove_unreachable_nodes (true, dump_file
);
2309 /* Restore current_pass. */
2310 current_pass
= pass
;
2313 if (!quiet_flag
&& !cfun
)
2314 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2316 /* Note that the folders should only create gimple expressions.
2317 This is a hack until the new folder is ready. */
2318 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2320 initializing_dump
= pass_init_dump_file (pass
);
2322 /* Run pre-pass verification. */
2323 execute_todo (pass
->todo_flags_start
);
2325 #ifdef ENABLE_CHECKING
2326 do_per_function (verify_curr_properties
,
2327 (void *)(size_t)pass
->properties_required
);
2330 /* If a timevar is present, start it. */
2331 if (pass
->tv_id
!= TV_NONE
)
2332 timevar_push (pass
->tv_id
);
2337 todo_after
= pass
->execute ();
2338 do_per_function (clear_last_verified
, NULL
);
2342 if (pass
->tv_id
!= TV_NONE
)
2343 timevar_pop (pass
->tv_id
);
2345 do_per_function (update_properties_after_pass
, pass
);
2347 if (initializing_dump
2349 && graph_dump_format
!= no_graph
2351 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
2352 == (PROP_cfg
| PROP_rtl
))
2354 get_dump_file_info (pass
->static_pass_number
)->pflags
|= TDF_GRAPH
;
2355 dump_flags
|= TDF_GRAPH
;
2356 clean_graph_dump_file (dump_file_name
);
2359 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2360 check_profile_consistency (pass
->static_pass_number
, 0, true);
2362 /* Run post-pass cleanup and verification. */
2363 execute_todo (todo_after
| pass
->todo_flags_finish
);
2364 if (profile_report
&& cfun
&& (cfun
->curr_properties
& PROP_cfg
))
2365 check_profile_consistency (pass
->static_pass_number
, 1, true);
2367 verify_interpass_invariants ();
2368 do_per_function (execute_function_dump
, NULL
);
2369 if (pass
->type
== IPA_PASS
)
2371 struct cgraph_node
*node
;
2372 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2373 VEC_safe_push (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
,
2374 (struct ipa_opt_pass_d
*)pass
);
2377 if (!current_function_decl
)
2378 cgraph_process_new_functions ();
2380 pass_fini_dump_file (pass
);
2382 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2383 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2384 || pass
->type
!= RTL_PASS
);
2386 current_pass
= NULL
;
2392 execute_pass_list (struct opt_pass
*pass
)
2396 gcc_assert (pass
->type
== GIMPLE_PASS
2397 || pass
->type
== RTL_PASS
);
2398 if (execute_one_pass (pass
) && pass
->sub
)
2399 execute_pass_list (pass
->sub
);
2405 /* Same as execute_pass_list but assume that subpasses of IPA passes
2406 are local passes. If SET is not NULL, write out summaries of only
2407 those node in SET. */
2410 ipa_write_summaries_2 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2414 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2415 gcc_assert (!current_function_decl
);
2417 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2418 if (pass
->type
== IPA_PASS
2419 && ipa_pass
->write_summary
2420 && (!pass
->gate
|| pass
->gate ()))
2422 /* If a timevar is present, start it. */
2424 timevar_push (pass
->tv_id
);
2426 pass_init_dump_file (pass
);
2428 ipa_pass
->write_summary ();
2430 pass_fini_dump_file (pass
);
2432 /* If a timevar is present, start it. */
2434 timevar_pop (pass
->tv_id
);
2437 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2438 ipa_write_summaries_2 (pass
->sub
, state
);
2444 /* Helper function of ipa_write_summaries. Creates and destroys the
2445 decl state and calls ipa_write_summaries_2 for all passes that have
2446 summaries. SET is the set of nodes to be written. */
2449 ipa_write_summaries_1 (lto_symtab_encoder_t encoder
)
2451 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2452 state
->symtab_node_encoder
= encoder
;
2454 lto_push_out_decl_state (state
);
2456 gcc_assert (!flag_wpa
);
2457 ipa_write_summaries_2 (all_regular_ipa_passes
, state
);
2458 ipa_write_summaries_2 (all_lto_gen_passes
, state
);
2460 gcc_assert (lto_get_out_decl_state () == state
);
2461 lto_pop_out_decl_state ();
2462 lto_delete_out_decl_state (state
);
2465 /* Write out summaries for all the nodes in the callgraph. */
2468 ipa_write_summaries (void)
2470 lto_symtab_encoder_t encoder
;
2472 struct varpool_node
*vnode
;
2473 struct cgraph_node
**order
;
2475 if (!flag_generate_lto
|| seen_error ())
2478 encoder
= lto_symtab_encoder_new (false);
2480 /* Create the callgraph set in the same order used in
2481 cgraph_expand_all_functions. This mostly facilitates debugging,
2482 since it causes the gimple file to be processed in the same order
2483 as the source code. */
2484 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2485 order_pos
= ipa_reverse_postorder (order
);
2486 gcc_assert (order_pos
== cgraph_n_nodes
);
2488 for (i
= order_pos
- 1; i
>= 0; i
--)
2490 struct cgraph_node
*node
= order
[i
];
2492 if (cgraph_function_with_gimple_body_p (node
))
2494 /* When streaming out references to statements as part of some IPA
2495 pass summary, the statements need to have uids assigned and the
2496 following does that for all the IPA passes here. Naturally, this
2497 ordering then matches the one IPA-passes get in their stmt_fixup
2500 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2501 renumber_gimple_stmt_uids ();
2505 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
2508 FOR_EACH_DEFINED_VARIABLE (vnode
)
2509 if ((!vnode
->alias
|| vnode
->alias_of
))
2510 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
2512 ipa_write_summaries_1 (compute_ltrans_boundary (encoder
));
2517 /* Same as execute_pass_list but assume that subpasses of IPA passes
2518 are local passes. If SET is not NULL, write out optimization summaries of
2519 only those node in SET. */
2522 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, struct lto_out_decl_state
*state
)
2526 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2527 gcc_assert (!current_function_decl
);
2529 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2530 if (pass
->type
== IPA_PASS
2531 && ipa_pass
->write_optimization_summary
2532 && (!pass
->gate
|| pass
->gate ()))
2534 /* If a timevar is present, start it. */
2536 timevar_push (pass
->tv_id
);
2538 pass_init_dump_file (pass
);
2540 ipa_pass
->write_optimization_summary ();
2542 pass_fini_dump_file (pass
);
2544 /* If a timevar is present, start it. */
2546 timevar_pop (pass
->tv_id
);
2549 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2550 ipa_write_optimization_summaries_1 (pass
->sub
, state
);
2556 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2557 NULL, write out all summaries of all nodes. */
2560 ipa_write_optimization_summaries (lto_symtab_encoder_t encoder
)
2562 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2563 lto_symtab_encoder_iterator lsei
;
2564 state
->symtab_node_encoder
= encoder
;
2566 lto_push_out_decl_state (state
);
2567 for (lsei
= lsei_start_function_in_partition (encoder
);
2568 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
2570 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
2571 /* When streaming out references to statements as part of some IPA
2572 pass summary, the statements need to have uids assigned.
2574 For functions newly born at WPA stage we need to initialize
2577 && gimple_has_body_p (node
->symbol
.decl
))
2579 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2580 renumber_gimple_stmt_uids ();
2585 gcc_assert (flag_wpa
);
2586 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, state
);
2587 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, state
);
2589 gcc_assert (lto_get_out_decl_state () == state
);
2590 lto_pop_out_decl_state ();
2591 lto_delete_out_decl_state (state
);
2594 /* Same as execute_pass_list but assume that subpasses of IPA passes
2595 are local passes. */
2598 ipa_read_summaries_1 (struct opt_pass
*pass
)
2602 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2604 gcc_assert (!current_function_decl
);
2606 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2608 if (pass
->gate
== NULL
|| pass
->gate ())
2610 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2612 /* If a timevar is present, start it. */
2614 timevar_push (pass
->tv_id
);
2616 pass_init_dump_file (pass
);
2618 ipa_pass
->read_summary ();
2620 pass_fini_dump_file (pass
);
2624 timevar_pop (pass
->tv_id
);
2627 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2628 ipa_read_summaries_1 (pass
->sub
);
2635 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2638 ipa_read_summaries (void)
2640 ipa_read_summaries_1 (all_regular_ipa_passes
);
2641 ipa_read_summaries_1 (all_lto_gen_passes
);
2644 /* Same as execute_pass_list but assume that subpasses of IPA passes
2645 are local passes. */
2648 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2652 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2654 gcc_assert (!current_function_decl
);
2656 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2658 if (pass
->gate
== NULL
|| pass
->gate ())
2660 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2662 /* If a timevar is present, start it. */
2664 timevar_push (pass
->tv_id
);
2666 pass_init_dump_file (pass
);
2668 ipa_pass
->read_optimization_summary ();
2670 pass_fini_dump_file (pass
);
2674 timevar_pop (pass
->tv_id
);
2677 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2678 ipa_read_optimization_summaries_1 (pass
->sub
);
2684 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2687 ipa_read_optimization_summaries (void)
2689 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2690 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2693 /* Same as execute_pass_list but assume that subpasses of IPA passes
2694 are local passes. */
2696 execute_ipa_pass_list (struct opt_pass
*pass
)
2700 gcc_assert (!current_function_decl
);
2702 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2703 if (execute_one_pass (pass
) && pass
->sub
)
2705 if (pass
->sub
->type
== GIMPLE_PASS
)
2707 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2708 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2710 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2712 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2713 || pass
->sub
->type
== IPA_PASS
)
2714 execute_ipa_pass_list (pass
->sub
);
2718 gcc_assert (!current_function_decl
);
2719 cgraph_process_new_functions ();
2725 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2728 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2729 struct cgraph_node
*node
, gimple
*stmts
)
2733 /* Execute all of the IPA_PASSes in the list. */
2734 if (pass
->type
== IPA_PASS
2735 && (!pass
->gate
|| pass
->gate ()))
2737 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2739 if (ipa_pass
->stmt_fixup
)
2741 pass_init_dump_file (pass
);
2742 /* If a timevar is present, start it. */
2744 timevar_push (pass
->tv_id
);
2746 ipa_pass
->stmt_fixup (node
, stmts
);
2750 timevar_pop (pass
->tv_id
);
2751 pass_fini_dump_file (pass
);
2754 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2760 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2763 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2765 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2769 extern void debug_properties (unsigned int);
2770 extern void dump_properties (FILE *, unsigned int);
2773 dump_properties (FILE *dump
, unsigned int props
)
2775 fprintf (dump
, "Properties:\n");
2776 if (props
& PROP_gimple_any
)
2777 fprintf (dump
, "PROP_gimple_any\n");
2778 if (props
& PROP_gimple_lcf
)
2779 fprintf (dump
, "PROP_gimple_lcf\n");
2780 if (props
& PROP_gimple_leh
)
2781 fprintf (dump
, "PROP_gimple_leh\n");
2782 if (props
& PROP_cfg
)
2783 fprintf (dump
, "PROP_cfg\n");
2784 if (props
& PROP_ssa
)
2785 fprintf (dump
, "PROP_ssa\n");
2786 if (props
& PROP_no_crit_edges
)
2787 fprintf (dump
, "PROP_no_crit_edges\n");
2788 if (props
& PROP_rtl
)
2789 fprintf (dump
, "PROP_rtl\n");
2790 if (props
& PROP_gimple_lomp
)
2791 fprintf (dump
, "PROP_gimple_lomp\n");
2792 if (props
& PROP_gimple_lcx
)
2793 fprintf (dump
, "PROP_gimple_lcx\n");
2794 if (props
& PROP_cfglayout
)
2795 fprintf (dump
, "PROP_cfglayout\n");
2799 debug_properties (unsigned int props
)
2801 dump_properties (stderr
, props
);
2804 /* Called by local passes to see if function is called by already processed nodes.
2805 Because we process nodes in topological order, this means that function is
2806 in recursive cycle or we introduced new direct calls. */
2808 function_called_by_processed_nodes_p (void)
2810 struct cgraph_edge
*e
;
2811 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2815 if (e
->caller
->symbol
.decl
== current_function_decl
)
2817 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2819 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2821 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2826 fprintf (dump_file
, "Already processed call to:\n");
2827 dump_cgraph_node (dump_file
, e
->caller
);
2832 #include "gt-passes.h"