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"
53 #include "diagnostic-core.h"
58 #include "langhooks.h"
60 #include "hosthooks.h"
64 #include "value-prof.h"
65 #include "tree-inline.h"
66 #include "tree-flow.h"
67 #include "tree-pass.h"
68 #include "tree-dump.h"
71 #include "lto-streamer.h"
73 #include "ipa-utils.h"
74 #include "tree-pretty-print.h" /* for dump_function_header */
76 /* This is used for debugging. It allows the current pass to printed
77 from anywhere in compilation.
78 The variable current_pass is also used for statistics and plugins. */
79 struct opt_pass
*current_pass
;
81 static void register_pass_name (struct opt_pass
*, const char *);
83 /* Call from anywhere to find out what pass this is. Useful for
84 printing out debugging information deep inside an service
87 print_current_pass (FILE *file
)
90 fprintf (file
, "current pass = %s (%d)\n",
91 current_pass
->name
, current_pass
->static_pass_number
);
93 fprintf (file
, "no current pass.\n");
97 /* Call from the debugger to get the current pass name. */
101 print_current_pass (stderr
);
106 /* Global variables used to communicate with passes. */
109 bool first_pass_instance
;
112 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
115 This does nothing for local (non-static) variables, unless the
116 variable is a register variable with DECL_ASSEMBLER_NAME set. In
117 that case, or if the variable is not an automatic, it sets up the
118 RTL and outputs any assembler code (label definition, storage
119 allocation and initialization).
121 DECL is the declaration. TOP_LEVEL is nonzero
122 if this declaration is not within a function. */
125 rest_of_decl_compilation (tree decl
,
129 /* We deferred calling assemble_alias so that we could collect
130 other attributes such as visibility. Emit the alias now. */
134 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
137 alias
= TREE_VALUE (TREE_VALUE (alias
));
138 alias
= get_identifier (TREE_STRING_POINTER (alias
));
139 /* A quirk of the initial implementation of aliases required that the
140 user add "extern" to all of them. Which is silly, but now
141 historical. Do note that the symbol is in fact locally defined. */
142 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
143 DECL_EXTERNAL (decl
) = 0;
144 assemble_alias (decl
, alias
);
148 /* Can't defer this, because it needs to happen before any
149 later function definitions are processed. */
150 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
151 make_decl_rtl (decl
);
153 /* Forward declarations for nested functions are not "external",
154 but we need to treat them as if they were. */
155 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
156 || TREE_CODE (decl
) == FUNCTION_DECL
)
158 timevar_push (TV_VARCONST
);
160 /* Don't output anything when a tentative file-scope definition
161 is seen. But at end of compilation, do output code for them.
163 We do output all variables and rely on
164 callgraph code to defer them except for forward declarations
165 (see gcc.c-torture/compile/920624-1.c) */
167 || !DECL_DEFER_OUTPUT (decl
)
168 || DECL_INITIAL (decl
))
169 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
170 && !DECL_EXTERNAL (decl
))
172 /* When reading LTO unit, we also read varpool, so do not
174 if (in_lto_p
&& !at_end
)
176 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
177 varpool_finalize_decl (decl
);
180 #ifdef ASM_FINISH_DECLARE_OBJECT
181 if (decl
== last_assemble_variable_decl
)
183 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
188 timevar_pop (TV_VARCONST
);
190 else if (TREE_CODE (decl
) == TYPE_DECL
191 /* Like in rest_of_type_compilation, avoid confusing the debug
192 information machinery when there are errors. */
195 timevar_push (TV_SYMOUT
);
196 debug_hooks
->type_decl (decl
, !top_level
);
197 timevar_pop (TV_SYMOUT
);
200 /* Let cgraph know about the existence of variables. */
201 if (in_lto_p
&& !at_end
)
203 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
204 && TREE_STATIC (decl
))
208 /* Called after finishing a record, union or enumeral type. */
211 rest_of_type_compilation (tree type
, int toplev
)
213 /* Avoid confusing the debug information machinery when there are
218 timevar_push (TV_SYMOUT
);
219 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
220 timevar_pop (TV_SYMOUT
);
226 finish_optimization_passes (void)
229 struct dump_file_info
*dfi
;
232 timevar_push (TV_DUMP
);
233 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
235 dump_file
= dump_begin (pass_profile
.pass
.static_pass_number
, NULL
);
238 dump_end (pass_profile
.pass
.static_pass_number
, dump_file
);
243 dump_file
= dump_begin (pass_combine
.pass
.static_pass_number
, NULL
);
246 dump_combine_total_stats (dump_file
);
247 dump_end (pass_combine
.pass
.static_pass_number
, dump_file
);
251 /* Do whatever is necessary to finish printing the graphs. */
252 if (graph_dump_format
!= no_graph
)
253 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
254 if (dump_initialized_p (i
)
255 && (dfi
->flags
& TDF_GRAPH
) != 0
256 && (name
= get_dump_file_name (i
)) != NULL
)
258 finish_graph_dump_file (name
);
262 timevar_pop (TV_DUMP
);
266 execute_all_early_local_passes (void)
268 /* Once this pass (and its sub-passes) are complete, all functions
269 will be in SSA form. Technically this state change is happening
270 a tad early, since the sub-passes have not yet run, but since
271 none of the sub-passes are IPA passes and do not create new
272 functions, this is ok. We're setting this value for the benefit
273 of IPA passes that follow. */
274 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
275 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
279 /* Gate: execute, or not, all of the non-trivial optimizations. */
282 gate_all_early_local_passes (void)
284 /* Don't bother doing anything if the program has errors. */
285 return (!seen_error () && !in_lto_p
);
288 struct simple_ipa_opt_pass pass_early_local_passes
=
292 "early_local_cleanups", /* name */
293 gate_all_early_local_passes
, /* gate */
294 execute_all_early_local_passes
, /* execute */
297 0, /* static_pass_number */
298 TV_EARLY_LOCAL
, /* tv_id */
299 0, /* properties_required */
300 0, /* properties_provided */
301 0, /* properties_destroyed */
302 0, /* todo_flags_start */
303 TODO_remove_functions
/* todo_flags_finish */
307 /* Gate: execute, or not, all of the non-trivial optimizations. */
310 gate_all_early_optimizations (void)
312 return (optimize
>= 1
313 /* Don't bother doing anything if the program has errors. */
317 static struct gimple_opt_pass pass_all_early_optimizations
=
321 "early_optimizations", /* name */
322 gate_all_early_optimizations
, /* gate */
326 0, /* static_pass_number */
328 0, /* properties_required */
329 0, /* properties_provided */
330 0, /* properties_destroyed */
331 0, /* todo_flags_start */
332 0 /* todo_flags_finish */
336 /* Gate: execute, or not, all of the non-trivial optimizations. */
339 gate_all_optimizations (void)
341 return (optimize
>= 1
342 /* Don't bother doing anything if the program has errors.
343 We have to pass down the queue if we already went into SSA */
344 && (!seen_error () || gimple_in_ssa_p (cfun
)));
347 static struct gimple_opt_pass pass_all_optimizations
=
351 "*all_optimizations", /* name */
352 gate_all_optimizations
, /* gate */
356 0, /* static_pass_number */
357 TV_OPTIMIZE
, /* tv_id */
358 0, /* properties_required */
359 0, /* properties_provided */
360 0, /* properties_destroyed */
361 0, /* todo_flags_start */
362 0 /* todo_flags_finish */
367 gate_rest_of_compilation (void)
369 /* Early return if there were errors. We can run afoul of our
370 consistency checks, and there's not really much point in fixing them. */
371 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
374 static struct rtl_opt_pass pass_rest_of_compilation
=
378 "*rest_of_compilation", /* name */
379 gate_rest_of_compilation
, /* gate */
383 0, /* static_pass_number */
384 TV_REST_OF_COMPILATION
, /* tv_id */
385 PROP_rtl
, /* properties_required */
386 0, /* properties_provided */
387 0, /* properties_destroyed */
388 0, /* todo_flags_start */
389 TODO_ggc_collect
/* todo_flags_finish */
394 gate_postreload (void)
396 return reload_completed
;
399 static struct rtl_opt_pass pass_postreload
=
403 "*all-postreload", /* name */
404 gate_postreload
, /* gate */
408 0, /* static_pass_number */
409 TV_POSTRELOAD
, /* tv_id */
410 PROP_rtl
, /* properties_required */
411 0, /* properties_provided */
412 0, /* properties_destroyed */
413 0, /* todo_flags_start */
414 TODO_ggc_collect
| TODO_verify_rtl_sharing
/* todo_flags_finish */
420 /* The root of the compilation pass tree, once constructed. */
421 struct opt_pass
*all_passes
, *all_small_ipa_passes
, *all_lowering_passes
,
422 *all_regular_ipa_passes
, *all_late_ipa_passes
, *all_lto_gen_passes
;
424 /* This is used by plugins, and should also be used in register_pass. */
425 #define DEF_PASS_LIST(LIST) &LIST,
426 struct opt_pass
**gcc_pass_lists
[] = { GCC_PASS_LISTS NULL
};
429 /* A map from static pass id to optimization pass. */
430 struct opt_pass
**passes_by_id
;
431 int passes_by_id_size
;
433 /* Set the static pass number of pass PASS to ID and record that
434 in the mapping from static pass number to pass. */
437 set_pass_for_id (int id
, struct opt_pass
*pass
)
439 pass
->static_pass_number
= id
;
440 if (passes_by_id_size
<= id
)
442 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
443 memset (passes_by_id
+ passes_by_id_size
, 0,
444 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
445 passes_by_id_size
= id
+ 1;
447 passes_by_id
[id
] = pass
;
450 /* Return the pass with the static pass number ID. */
453 get_pass_for_id (int id
)
455 if (id
>= passes_by_id_size
)
457 return passes_by_id
[id
];
460 /* Iterate over the pass tree allocating dump file numbers. We want
461 to do this depth first, and independent of whether the pass is
465 register_one_dump_file (struct opt_pass
*pass
)
467 char *dot_name
, *flag_name
, *glob_name
;
468 const char *name
, *full_name
, *prefix
;
472 /* See below in next_pass_1. */
474 if (pass
->static_pass_number
!= -1)
475 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
476 ? 1 : pass
->static_pass_number
));
478 /* The name is both used to identify the pass for the purposes of plugins,
479 and to specify dump file name and option.
480 The latter two might want something short which is not quite unique; for
481 that reason, we may have a disambiguating prefix, followed by a space
482 to mark the start of the following dump file name / option string. */
483 name
= strchr (pass
->name
, ' ');
484 name
= name
? name
+ 1 : pass
->name
;
485 dot_name
= concat (".", name
, num
, NULL
);
486 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
487 prefix
= "ipa-", flags
= TDF_IPA
;
488 else if (pass
->type
== GIMPLE_PASS
)
489 prefix
= "tree-", flags
= TDF_TREE
;
491 prefix
= "rtl-", flags
= TDF_RTL
;
493 flag_name
= concat (prefix
, name
, num
, NULL
);
494 glob_name
= concat (prefix
, name
, NULL
);
495 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
);
496 set_pass_for_id (id
, pass
);
497 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
498 register_pass_name (pass
, full_name
);
499 free (CONST_CAST (char *, full_name
));
502 /* Recursive worker function for register_dump_files. */
505 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
509 int new_properties
= (properties
| pass
->properties_provided
)
510 & ~pass
->properties_destroyed
;
512 if (pass
->name
&& pass
->name
[0] != '*')
513 register_one_dump_file (pass
);
516 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
518 /* If we have a gate, combine the properties that we could have with
519 and without the pass being examined. */
521 properties
&= new_properties
;
523 properties
= new_properties
;
532 /* Register the dump files for the pipeline starting at PASS.
533 PROPERTIES reflects the properties that are guaranteed to be available at
534 the beginning of the pipeline. */
537 register_dump_files (struct opt_pass
*pass
,int properties
)
539 pass
->properties_required
|= properties
;
540 register_dump_files_1 (pass
, properties
);
545 const char* unique_name
;
546 struct opt_pass
*pass
;
549 /* Pass registry hash function. */
552 passr_hash (const void *p
)
554 const struct pass_registry
*const s
= (const struct pass_registry
*const) p
;
555 return htab_hash_string (s
->unique_name
);
558 /* Hash equal function */
561 passr_eq (const void *p1
, const void *p2
)
563 const struct pass_registry
*const s1
= (const struct pass_registry
*const) p1
;
564 const struct pass_registry
*const s2
= (const struct pass_registry
*const) p2
;
566 return !strcmp (s1
->unique_name
, s2
->unique_name
);
569 static htab_t name_to_pass_map
= NULL
;
571 /* Register PASS with NAME. */
574 register_pass_name (struct opt_pass
*pass
, const char *name
)
576 struct pass_registry
**slot
;
577 struct pass_registry pr
;
579 if (!name_to_pass_map
)
580 name_to_pass_map
= htab_create (256, passr_hash
, passr_eq
, NULL
);
582 pr
.unique_name
= name
;
583 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
, &pr
, INSERT
);
586 struct pass_registry
*new_pr
;
588 new_pr
= XCNEW (struct pass_registry
);
589 new_pr
->unique_name
= xstrdup (name
);
594 return; /* Ignore plugin passes. */
597 /* Map from pass id to canonicalized pass name. */
599 typedef const char *char_ptr
;
601 DEF_VEC_ALLOC_P(char_ptr
, heap
);
602 static VEC(char_ptr
, heap
) *pass_tab
= NULL
;
604 /* Callback function for traversing NAME_TO_PASS_MAP. */
607 pass_traverse (void **slot
, void *data ATTRIBUTE_UNUSED
)
609 struct pass_registry
**p
= (struct pass_registry
**)slot
;
610 struct opt_pass
*pass
= (*p
)->pass
;
612 gcc_assert (pass
->static_pass_number
> 0);
613 gcc_assert (pass_tab
);
615 VEC_replace (char_ptr
, pass_tab
, pass
->static_pass_number
,
621 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
622 table for dumping purpose. */
625 create_pass_tab (void)
627 if (!flag_dump_passes
)
630 VEC_safe_grow_cleared (char_ptr
, heap
,
631 pass_tab
, passes_by_id_size
+ 1);
632 htab_traverse (name_to_pass_map
, pass_traverse
, NULL
);
635 static bool override_gate_status (struct opt_pass
*, tree
, bool);
637 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
638 is turned on or not. */
641 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
643 int indent
= 3 * pass_indent
;
645 bool is_on
, is_really_on
;
647 is_on
= (pass
->gate
== NULL
) ? true : pass
->gate();
648 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
650 if (pass
->static_pass_number
<= 0)
653 pn
= VEC_index (char_ptr
, pass_tab
, pass
->static_pass_number
);
655 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
656 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
657 is_on
? " ON" : " OFF",
658 ((!is_on
) == (!is_really_on
) ? ""
659 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
662 /* Dump pass list PASS with indentation INDENT. */
665 dump_pass_list (struct opt_pass
*pass
, int indent
)
669 dump_one_pass (pass
, indent
);
671 dump_pass_list (pass
->sub
, indent
+ 1);
677 /* Dump all optimization passes. */
682 struct cgraph_node
*n
, *node
= NULL
;
683 tree save_fndecl
= current_function_decl
;
687 FOR_EACH_DEFINED_FUNCTION (n
)
688 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
697 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
698 current_function_decl
= node
->symbol
.decl
;
700 dump_pass_list (all_lowering_passes
, 1);
701 dump_pass_list (all_small_ipa_passes
, 1);
702 dump_pass_list (all_regular_ipa_passes
, 1);
703 dump_pass_list (all_lto_gen_passes
, 1);
704 dump_pass_list (all_late_ipa_passes
, 1);
705 dump_pass_list (all_passes
, 1);
708 current_function_decl
= save_fndecl
;
712 /* Returns the pass with NAME. */
714 static struct opt_pass
*
715 get_pass_by_name (const char *name
)
717 struct pass_registry
**slot
, pr
;
719 pr
.unique_name
= name
;
720 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
,
726 return (*slot
)->pass
;
730 /* Range [start, last]. */
736 const char *assem_name
;
737 struct uid_range
*next
;
740 typedef struct uid_range
*uid_range_p
;
742 DEF_VEC_P(uid_range_p
);
743 DEF_VEC_ALLOC_P(uid_range_p
, heap
);
745 static VEC(uid_range_p
, heap
) *enabled_pass_uid_range_tab
= NULL
;
746 static VEC(uid_range_p
, heap
) *disabled_pass_uid_range_tab
= NULL
;
749 /* Parse option string for -fdisable- and -fenable-
750 The syntax of the options:
753 -fdisable-<pass_name>
755 -fenable-<pass_name>=s1:e1,s2:e2,...
756 -fdisable-<pass_name>=s1:e1,s2:e2,...
760 enable_disable_pass (const char *arg
, bool is_enable
)
762 struct opt_pass
*pass
;
763 char *range_str
, *phase_name
;
764 char *argstr
= xstrdup (arg
);
765 VEC(uid_range_p
, heap
) **tab
= 0;
767 range_str
= strchr (argstr
,'=');
778 error ("unrecognized option -fenable");
780 error ("unrecognized option -fdisable");
784 pass
= get_pass_by_name (phase_name
);
785 if (!pass
|| pass
->static_pass_number
== -1)
788 error ("unknown pass %s specified in -fenable", phase_name
);
790 error ("unknown pass %s specified in -fdisable", phase_name
);
796 tab
= &enabled_pass_uid_range_tab
;
798 tab
= &disabled_pass_uid_range_tab
;
800 if ((unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, *tab
))
801 VEC_safe_grow_cleared (uid_range_p
, heap
,
802 *tab
, pass
->static_pass_number
+ 1);
807 uid_range_p new_range
= XCNEW (struct uid_range
);
809 new_range
->start
= 0;
810 new_range
->last
= (unsigned)-1;
812 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
813 new_range
->next
= slot
;
814 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
817 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
818 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
820 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
821 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
825 char *next_range
= NULL
;
826 char *one_range
= range_str
;
827 char *end_val
= NULL
;
832 uid_range_p new_range
;
833 char *invalid
= NULL
;
835 char *func_name
= NULL
;
837 next_range
= strchr (one_range
, ',');
844 end_val
= strchr (one_range
, ':');
850 start
= strtol (one_range
, &invalid
, 10);
851 if (*invalid
|| start
< 0)
853 if (end_val
|| (one_range
[0] >= '0'
854 && one_range
[0] <= '9'))
856 error ("Invalid range %s in option %s",
858 is_enable
? "-fenable" : "-fdisable");
862 func_name
= one_range
;
866 new_range
= XCNEW (struct uid_range
);
869 new_range
->start
= (unsigned) start
;
870 new_range
->last
= (unsigned) start
;
874 new_range
->start
= (unsigned) -1;
875 new_range
->last
= (unsigned) -1;
876 new_range
->assem_name
= xstrdup (func_name
);
881 long last
= strtol (end_val
, &invalid
, 10);
882 if (*invalid
|| last
< start
)
884 error ("Invalid range %s in option %s",
886 is_enable
? "-fenable" : "-fdisable");
890 new_range
= XCNEW (struct uid_range
);
891 new_range
->start
= (unsigned) start
;
892 new_range
->last
= (unsigned) last
;
895 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
896 new_range
->next
= slot
;
897 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
901 if (new_range
->assem_name
)
902 inform (UNKNOWN_LOCATION
,
903 "enable pass %s for function %s",
904 phase_name
, new_range
->assem_name
);
906 inform (UNKNOWN_LOCATION
,
907 "enable pass %s for functions in the range of [%u, %u]",
908 phase_name
, new_range
->start
, new_range
->last
);
912 if (new_range
->assem_name
)
913 inform (UNKNOWN_LOCATION
,
914 "disable pass %s for function %s",
915 phase_name
, new_range
->assem_name
);
917 inform (UNKNOWN_LOCATION
,
918 "disable pass %s for functions in the range of [%u, %u]",
919 phase_name
, new_range
->start
, new_range
->last
);
922 one_range
= next_range
;
923 } while (next_range
);
929 /* Enable pass specified by ARG. */
932 enable_pass (const char *arg
)
934 enable_disable_pass (arg
, true);
937 /* Disable pass specified by ARG. */
940 disable_pass (const char *arg
)
942 enable_disable_pass (arg
, false);
945 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
948 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
950 VEC(uid_range_p
, heap
) *tab
)
952 uid_range_p slot
, range
;
954 const char *aname
= NULL
;
957 || (unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, tab
)
958 || pass
->static_pass_number
== -1)
961 slot
= VEC_index (uid_range_p
, tab
, pass
->static_pass_number
);
965 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
966 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
967 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
972 if ((unsigned) cgraph_uid
>= range
->start
973 && (unsigned) cgraph_uid
<= range
->last
)
975 if (range
->assem_name
&& aname
976 && !strcmp (range
->assem_name
, aname
))
984 /* Look at the static_pass_number and duplicate the pass
985 if it is already added to a list. */
987 static struct opt_pass
*
988 make_pass_instance (struct opt_pass
*pass
, bool track_duplicates
)
990 /* A nonzero static_pass_number indicates that the
991 pass is already in the list. */
992 if (pass
->static_pass_number
)
994 struct opt_pass
*new_pass
;
996 if (pass
->type
== GIMPLE_PASS
997 || pass
->type
== RTL_PASS
998 || pass
->type
== SIMPLE_IPA_PASS
)
1000 new_pass
= XNEW (struct opt_pass
);
1001 memcpy (new_pass
, pass
, sizeof (struct opt_pass
));
1003 else if (pass
->type
== IPA_PASS
)
1005 new_pass
= (struct opt_pass
*)XNEW (struct ipa_opt_pass_d
);
1006 memcpy (new_pass
, pass
, sizeof (struct ipa_opt_pass_d
));
1011 new_pass
->next
= NULL
;
1013 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1015 /* Indicate to register_dump_files that this pass has duplicates,
1016 and so it should rename the dump file. The first instance will
1017 be -1, and be number of duplicates = -static_pass_number - 1.
1018 Subsequent instances will be > 0 and just the duplicate number. */
1019 if ((pass
->name
&& pass
->name
[0] != '*') || track_duplicates
)
1021 pass
->static_pass_number
-= 1;
1022 new_pass
->static_pass_number
= -pass
->static_pass_number
;
1028 pass
->todo_flags_start
|= TODO_mark_first_instance
;
1029 pass
->static_pass_number
= -1;
1031 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, pass
);
1036 /* Add a pass to the pass list. Duplicate the pass if it's already
1039 static struct opt_pass
**
1040 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
)
1042 /* Every pass should have a name so that plugins can refer to them. */
1043 gcc_assert (pass
->name
!= NULL
);
1045 *list
= make_pass_instance (pass
, false);
1047 return &(*list
)->next
;
1050 /* List node for an inserted pass instance. We need to keep track of all
1051 the newly-added pass instances (with 'added_pass_nodes' defined below)
1052 so that we can register their dump files after pass-positioning is finished.
1053 Registering dumping files needs to be post-processed or the
1054 static_pass_number of the opt_pass object would be modified and mess up
1055 the dump file names of future pass instances to be added. */
1057 struct pass_list_node
1059 struct opt_pass
*pass
;
1060 struct pass_list_node
*next
;
1063 static struct pass_list_node
*added_pass_nodes
= NULL
;
1064 static struct pass_list_node
*prev_added_pass_node
;
1066 /* Insert the pass at the proper position. Return true if the pass
1067 is successfully added.
1069 NEW_PASS_INFO - new pass to be inserted
1070 PASS_LIST - root of the pass list to insert the new pass to */
1073 position_pass (struct register_pass_info
*new_pass_info
,
1074 struct opt_pass
**pass_list
)
1076 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1077 bool success
= false;
1079 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1081 /* Check if the current pass is of the same type as the new pass and
1082 matches the name and the instance number of the reference pass. */
1083 if (pass
->type
== new_pass_info
->pass
->type
1085 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1086 && ((new_pass_info
->ref_pass_instance_number
== 0)
1087 || (new_pass_info
->ref_pass_instance_number
==
1088 pass
->static_pass_number
)
1089 || (new_pass_info
->ref_pass_instance_number
== 1
1090 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1092 struct opt_pass
*new_pass
;
1093 struct pass_list_node
*new_pass_node
;
1095 new_pass
= make_pass_instance (new_pass_info
->pass
, true);
1097 /* Insert the new pass instance based on the positioning op. */
1098 switch (new_pass_info
->pos_op
)
1100 case PASS_POS_INSERT_AFTER
:
1101 new_pass
->next
= pass
->next
;
1102 pass
->next
= new_pass
;
1104 /* Skip newly inserted pass to avoid repeated
1105 insertions in the case where the new pass and the
1106 existing one have the same name. */
1109 case PASS_POS_INSERT_BEFORE
:
1110 new_pass
->next
= pass
;
1112 prev_pass
->next
= new_pass
;
1114 *pass_list
= new_pass
;
1116 case PASS_POS_REPLACE
:
1117 new_pass
->next
= pass
->next
;
1119 prev_pass
->next
= new_pass
;
1121 *pass_list
= new_pass
;
1122 new_pass
->sub
= pass
->sub
;
1123 new_pass
->tv_id
= pass
->tv_id
;
1127 error ("invalid pass positioning operation");
1131 /* Save the newly added pass (instance) in the added_pass_nodes
1132 list so that we can register its dump file later. Note that
1133 we cannot register the dump file now because doing so will modify
1134 the static_pass_number of the opt_pass object and therefore
1135 mess up the dump file name of future instances. */
1136 new_pass_node
= XCNEW (struct pass_list_node
);
1137 new_pass_node
->pass
= new_pass
;
1138 if (!added_pass_nodes
)
1139 added_pass_nodes
= new_pass_node
;
1141 prev_added_pass_node
->next
= new_pass_node
;
1142 prev_added_pass_node
= new_pass_node
;
1147 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1154 /* Hooks a new pass into the pass lists.
1156 PASS_INFO - pass information that specifies the opt_pass object,
1157 reference pass, instance number, and how to position
1161 register_pass (struct register_pass_info
*pass_info
)
1163 bool all_instances
, success
;
1165 /* The checks below could fail in buggy plugins. Existing GCC
1166 passes should never fail these checks, so we mention plugin in
1168 if (!pass_info
->pass
)
1169 fatal_error ("plugin cannot register a missing pass");
1171 if (!pass_info
->pass
->name
)
1172 fatal_error ("plugin cannot register an unnamed pass");
1174 if (!pass_info
->reference_pass_name
)
1176 ("plugin cannot register pass %qs without reference pass name",
1177 pass_info
->pass
->name
);
1179 /* Try to insert the new pass to the pass lists. We need to check
1180 all five lists as the reference pass could be in one (or all) of
1182 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1183 success
= position_pass (pass_info
, &all_lowering_passes
);
1184 if (!success
|| all_instances
)
1185 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1186 if (!success
|| all_instances
)
1187 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1188 if (!success
|| all_instances
)
1189 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1190 if (!success
|| all_instances
)
1191 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1192 if (!success
|| all_instances
)
1193 success
|= position_pass (pass_info
, &all_passes
);
1196 ("pass %qs not found but is referenced by new pass %qs",
1197 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1199 /* OK, we have successfully inserted the new pass. We need to register
1200 the dump files for the newly added pass and its duplicates (if any).
1201 Because the registration of plugin/backend passes happens after the
1202 command-line options are parsed, the options that specify single
1203 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1204 passes. Therefore we currently can only enable dumping of
1205 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1206 are specified. While doing so, we also delete the pass_list_node
1207 objects created during pass positioning. */
1208 while (added_pass_nodes
)
1210 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1211 enum tree_dump_index tdi
;
1212 register_one_dump_file (added_pass_nodes
->pass
);
1213 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1214 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1216 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1220 /* Check if dump-all flag is specified. */
1221 if (get_dump_file_info (tdi
)->state
)
1222 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1223 ->state
= get_dump_file_info (tdi
)->state
;
1224 XDELETE (added_pass_nodes
);
1225 added_pass_nodes
= next_node
;
1229 /* Construct the pass tree. The sequencing of passes is driven by
1230 the cgraph routines:
1232 finalize_compilation_unit ()
1233 for each node N in the cgraph
1234 cgraph_analyze_function (N)
1235 cgraph_lower_function (N) -> all_lowering_passes
1237 If we are optimizing, compile is then invoked:
1240 ipa_passes () -> all_small_ipa_passes
1241 -> Analysis of all_regular_ipa_passes
1242 * possible LTO streaming at copmilation time *
1243 -> Execution of all_regular_ipa_passes
1244 * possible LTO streaming at link time *
1245 -> all_late_ipa_passes
1246 expand_all_functions ()
1247 for each node N in the cgraph
1248 expand_function (N) -> Transformation of all_regular_ipa_passes
1253 init_optimization_passes (void)
1255 struct opt_pass
**p
;
1257 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1259 /* All passes needed to lower the function into shape optimizers can
1260 operate on. These passes are always run first on the function, but
1261 backend might produce already lowered functions that are not processed
1263 p
= &all_lowering_passes
;
1264 NEXT_PASS (pass_warn_unused_result
);
1265 NEXT_PASS (pass_diagnose_omp_blocks
);
1266 NEXT_PASS (pass_diagnose_tm_blocks
);
1267 NEXT_PASS (pass_mudflap_1
);
1268 NEXT_PASS (pass_lower_omp
);
1269 NEXT_PASS (pass_lower_cf
);
1270 NEXT_PASS (pass_lower_tm
);
1271 NEXT_PASS (pass_refactor_eh
);
1272 NEXT_PASS (pass_lower_eh
);
1273 NEXT_PASS (pass_build_cfg
);
1274 NEXT_PASS (pass_warn_function_return
);
1275 NEXT_PASS (pass_build_cgraph_edges
);
1278 /* Interprocedural optimization passes. */
1279 p
= &all_small_ipa_passes
;
1280 NEXT_PASS (pass_ipa_free_lang_data
);
1281 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
1282 NEXT_PASS (pass_early_local_passes
);
1284 struct opt_pass
**p
= &pass_early_local_passes
.pass
.sub
;
1285 NEXT_PASS (pass_fixup_cfg
);
1286 NEXT_PASS (pass_init_datastructures
);
1287 NEXT_PASS (pass_expand_omp
);
1289 NEXT_PASS (pass_referenced_vars
);
1290 NEXT_PASS (pass_build_ssa
);
1291 NEXT_PASS (pass_lower_vector
);
1292 NEXT_PASS (pass_early_warn_uninitialized
);
1293 NEXT_PASS (pass_rebuild_cgraph_edges
);
1294 NEXT_PASS (pass_inline_parameters
);
1295 NEXT_PASS (pass_early_inline
);
1296 NEXT_PASS (pass_all_early_optimizations
);
1298 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1299 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1300 NEXT_PASS (pass_rename_ssa_copies
);
1301 NEXT_PASS (pass_ccp
);
1302 NEXT_PASS (pass_forwprop
);
1303 /* pass_build_ealias is a dummy pass that ensures that we
1304 execute TODO_rebuild_alias at this point. Re-building
1305 alias information also rewrites no longer addressed
1306 locals into SSA form if possible. */
1307 NEXT_PASS (pass_build_ealias
);
1308 NEXT_PASS (pass_sra_early
);
1309 NEXT_PASS (pass_fre
);
1310 NEXT_PASS (pass_copy_prop
);
1311 NEXT_PASS (pass_merge_phi
);
1312 NEXT_PASS (pass_cd_dce
);
1313 NEXT_PASS (pass_early_ipa_sra
);
1314 NEXT_PASS (pass_tail_recursion
);
1315 NEXT_PASS (pass_convert_switch
);
1316 NEXT_PASS (pass_cleanup_eh
);
1317 NEXT_PASS (pass_profile
);
1318 NEXT_PASS (pass_local_pure_const
);
1319 /* Split functions creates parts that are not run through
1320 early optimizations again. It is thus good idea to do this
1322 NEXT_PASS (pass_split_functions
);
1324 NEXT_PASS (pass_release_ssa_names
);
1325 NEXT_PASS (pass_rebuild_cgraph_edges
);
1326 NEXT_PASS (pass_inline_parameters
);
1328 NEXT_PASS (pass_ipa_tree_profile
);
1330 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1331 NEXT_PASS (pass_feedback_split_functions
);
1333 NEXT_PASS (pass_ipa_increase_alignment
);
1334 NEXT_PASS (pass_ipa_matrix_reorg
);
1335 NEXT_PASS (pass_ipa_tm
);
1336 NEXT_PASS (pass_ipa_lower_emutls
);
1339 p
= &all_regular_ipa_passes
;
1340 NEXT_PASS (pass_ipa_whole_program_visibility
);
1341 NEXT_PASS (pass_ipa_profile
);
1342 NEXT_PASS (pass_ipa_cp
);
1343 NEXT_PASS (pass_ipa_cdtor_merge
);
1344 NEXT_PASS (pass_ipa_inline
);
1345 NEXT_PASS (pass_ipa_pure_const
);
1346 NEXT_PASS (pass_ipa_reference
);
1349 p
= &all_lto_gen_passes
;
1350 NEXT_PASS (pass_ipa_lto_gimple_out
);
1351 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1354 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1355 passes are executed after partitioning and thus see just parts of the
1357 p
= &all_late_ipa_passes
;
1358 NEXT_PASS (pass_ipa_pta
);
1361 /* These passes are run after IPA passes on every function that is being
1362 output to the assembler file. */
1364 NEXT_PASS (pass_fixup_cfg
);
1365 NEXT_PASS (pass_lower_eh_dispatch
);
1366 NEXT_PASS (pass_all_optimizations
);
1368 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1369 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1370 /* Initial scalar cleanups before alias computation.
1371 They ensure memory accesses are not indirect wherever possible. */
1372 NEXT_PASS (pass_strip_predict_hints
);
1373 NEXT_PASS (pass_rename_ssa_copies
);
1374 NEXT_PASS (pass_complete_unrolli
);
1375 NEXT_PASS (pass_ccp
);
1376 NEXT_PASS (pass_forwprop
);
1377 /* pass_build_alias is a dummy pass that ensures that we
1378 execute TODO_rebuild_alias at this point. Re-building
1379 alias information also rewrites no longer addressed
1380 locals into SSA form if possible. */
1381 NEXT_PASS (pass_build_alias
);
1382 NEXT_PASS (pass_return_slot
);
1383 NEXT_PASS (pass_phiprop
);
1384 NEXT_PASS (pass_fre
);
1385 NEXT_PASS (pass_copy_prop
);
1386 NEXT_PASS (pass_merge_phi
);
1387 NEXT_PASS (pass_vrp
);
1388 NEXT_PASS (pass_dce
);
1389 NEXT_PASS (pass_call_cdce
);
1390 NEXT_PASS (pass_cselim
);
1391 NEXT_PASS (pass_tree_ifcombine
);
1392 NEXT_PASS (pass_phiopt
);
1393 NEXT_PASS (pass_tail_recursion
);
1394 NEXT_PASS (pass_ch
);
1395 NEXT_PASS (pass_stdarg
);
1396 NEXT_PASS (pass_lower_complex
);
1397 NEXT_PASS (pass_sra
);
1398 NEXT_PASS (pass_rename_ssa_copies
);
1399 /* The dom pass will also resolve all __builtin_constant_p calls
1400 that are still there to 0. This has to be done after some
1401 propagations have already run, but before some more dead code
1402 is removed, and this place fits nicely. Remember this when
1403 trying to move or duplicate pass_dominator somewhere earlier. */
1404 NEXT_PASS (pass_dominator
);
1405 /* The only const/copy propagation opportunities left after
1406 DOM should be due to degenerate PHI nodes. So rather than
1407 run the full propagators, run a specialized pass which
1408 only examines PHIs to discover const/copy propagation
1410 NEXT_PASS (pass_phi_only_cprop
);
1411 NEXT_PASS (pass_dse
);
1412 NEXT_PASS (pass_reassoc
);
1413 NEXT_PASS (pass_dce
);
1414 NEXT_PASS (pass_forwprop
);
1415 NEXT_PASS (pass_phiopt
);
1416 NEXT_PASS (pass_object_sizes
);
1417 NEXT_PASS (pass_strlen
);
1418 NEXT_PASS (pass_ccp
);
1419 NEXT_PASS (pass_copy_prop
);
1420 NEXT_PASS (pass_cse_sincos
);
1421 NEXT_PASS (pass_optimize_bswap
);
1422 NEXT_PASS (pass_split_crit_edges
);
1423 NEXT_PASS (pass_pre
);
1424 NEXT_PASS (pass_sink_code
);
1425 NEXT_PASS (pass_tree_loop
);
1427 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1428 NEXT_PASS (pass_tree_loop_init
);
1429 NEXT_PASS (pass_lim
);
1430 NEXT_PASS (pass_copy_prop
);
1431 NEXT_PASS (pass_dce_loop
);
1432 NEXT_PASS (pass_tree_unswitch
);
1433 NEXT_PASS (pass_scev_cprop
);
1434 NEXT_PASS (pass_record_bounds
);
1435 NEXT_PASS (pass_check_data_deps
);
1436 NEXT_PASS (pass_loop_distribution
);
1437 NEXT_PASS (pass_copy_prop
);
1438 NEXT_PASS (pass_graphite
);
1440 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1441 NEXT_PASS (pass_graphite_transforms
);
1442 NEXT_PASS (pass_lim
);
1443 NEXT_PASS (pass_copy_prop
);
1444 NEXT_PASS (pass_dce_loop
);
1446 NEXT_PASS (pass_iv_canon
);
1447 NEXT_PASS (pass_if_conversion
);
1448 NEXT_PASS (pass_vectorize
);
1450 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1451 NEXT_PASS (pass_dce_loop
);
1453 NEXT_PASS (pass_predcom
);
1454 NEXT_PASS (pass_complete_unroll
);
1455 NEXT_PASS (pass_slp_vectorize
);
1456 NEXT_PASS (pass_parallelize_loops
);
1457 NEXT_PASS (pass_loop_prefetch
);
1458 NEXT_PASS (pass_iv_optimize
);
1459 NEXT_PASS (pass_lim
);
1460 NEXT_PASS (pass_tree_loop_done
);
1462 NEXT_PASS (pass_lower_vector_ssa
);
1463 NEXT_PASS (pass_cse_reciprocals
);
1464 NEXT_PASS (pass_reassoc
);
1465 NEXT_PASS (pass_vrp
);
1466 NEXT_PASS (pass_strength_reduction
);
1467 NEXT_PASS (pass_dominator
);
1468 /* The only const/copy propagation opportunities left after
1469 DOM should be due to degenerate PHI nodes. So rather than
1470 run the full propagators, run a specialized pass which
1471 only examines PHIs to discover const/copy propagation
1473 NEXT_PASS (pass_phi_only_cprop
);
1474 NEXT_PASS (pass_cd_dce
);
1475 NEXT_PASS (pass_tracer
);
1477 /* FIXME: If DCE is not run before checking for uninitialized uses,
1478 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1479 However, this also causes us to misdiagnose cases that should be
1480 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1482 To fix the false positives in uninit-5.c, we would have to
1483 account for the predicates protecting the set and the use of each
1484 variable. Using a representation like Gated Single Assignment
1486 NEXT_PASS (pass_late_warn_uninitialized
);
1487 NEXT_PASS (pass_dse
);
1488 NEXT_PASS (pass_forwprop
);
1489 NEXT_PASS (pass_phiopt
);
1490 NEXT_PASS (pass_fold_builtins
);
1491 NEXT_PASS (pass_optimize_widening_mul
);
1492 NEXT_PASS (pass_tail_calls
);
1493 NEXT_PASS (pass_rename_ssa_copies
);
1494 NEXT_PASS (pass_uncprop
);
1495 NEXT_PASS (pass_local_pure_const
);
1497 NEXT_PASS (pass_tm_init
);
1499 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1500 NEXT_PASS (pass_tm_mark
);
1501 NEXT_PASS (pass_tm_memopt
);
1502 NEXT_PASS (pass_tm_edges
);
1504 NEXT_PASS (pass_lower_complex_O0
);
1505 NEXT_PASS (pass_cleanup_eh
);
1506 NEXT_PASS (pass_lower_resx
);
1507 NEXT_PASS (pass_nrv
);
1508 NEXT_PASS (pass_mudflap_2
);
1509 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
1510 NEXT_PASS (pass_warn_function_noreturn
);
1512 NEXT_PASS (pass_expand
);
1514 NEXT_PASS (pass_rest_of_compilation
);
1516 struct opt_pass
**p
= &pass_rest_of_compilation
.pass
.sub
;
1517 NEXT_PASS (pass_instantiate_virtual_regs
);
1518 NEXT_PASS (pass_into_cfg_layout_mode
);
1519 NEXT_PASS (pass_jump
);
1520 NEXT_PASS (pass_lower_subreg
);
1521 NEXT_PASS (pass_df_initialize_opt
);
1522 NEXT_PASS (pass_cse
);
1523 NEXT_PASS (pass_rtl_fwprop
);
1524 NEXT_PASS (pass_rtl_cprop
);
1525 NEXT_PASS (pass_rtl_pre
);
1526 NEXT_PASS (pass_rtl_hoist
);
1527 NEXT_PASS (pass_rtl_cprop
);
1528 NEXT_PASS (pass_rtl_store_motion
);
1529 NEXT_PASS (pass_cse_after_global_opts
);
1530 NEXT_PASS (pass_rtl_ifcvt
);
1531 NEXT_PASS (pass_reginfo_init
);
1532 /* Perform loop optimizations. It might be better to do them a bit
1533 sooner, but we want the profile feedback to work more
1535 NEXT_PASS (pass_loop2
);
1537 struct opt_pass
**p
= &pass_loop2
.pass
.sub
;
1538 NEXT_PASS (pass_rtl_loop_init
);
1539 NEXT_PASS (pass_rtl_move_loop_invariants
);
1540 NEXT_PASS (pass_rtl_unswitch
);
1541 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
1542 NEXT_PASS (pass_rtl_doloop
);
1543 NEXT_PASS (pass_rtl_loop_done
);
1546 NEXT_PASS (pass_web
);
1547 NEXT_PASS (pass_rtl_cprop
);
1548 NEXT_PASS (pass_cse2
);
1549 NEXT_PASS (pass_rtl_dse1
);
1550 NEXT_PASS (pass_rtl_fwprop_addr
);
1551 NEXT_PASS (pass_inc_dec
);
1552 NEXT_PASS (pass_initialize_regs
);
1553 NEXT_PASS (pass_ud_rtl_dce
);
1554 NEXT_PASS (pass_combine
);
1555 NEXT_PASS (pass_if_after_combine
);
1556 NEXT_PASS (pass_partition_blocks
);
1557 NEXT_PASS (pass_regmove
);
1558 NEXT_PASS (pass_outof_cfg_layout_mode
);
1559 NEXT_PASS (pass_split_all_insns
);
1560 NEXT_PASS (pass_lower_subreg2
);
1561 NEXT_PASS (pass_df_initialize_no_opt
);
1562 NEXT_PASS (pass_stack_ptr_mod
);
1563 NEXT_PASS (pass_mode_switching
);
1564 NEXT_PASS (pass_match_asm_constraints
);
1565 NEXT_PASS (pass_sms
);
1566 NEXT_PASS (pass_sched
);
1567 NEXT_PASS (pass_ira
);
1568 NEXT_PASS (pass_reload
);
1569 NEXT_PASS (pass_postreload
);
1571 struct opt_pass
**p
= &pass_postreload
.pass
.sub
;
1572 NEXT_PASS (pass_postreload_cse
);
1573 NEXT_PASS (pass_gcse2
);
1574 NEXT_PASS (pass_split_after_reload
);
1575 NEXT_PASS (pass_ree
);
1576 NEXT_PASS (pass_compare_elim_after_reload
);
1577 NEXT_PASS (pass_branch_target_load_optimize1
);
1578 NEXT_PASS (pass_thread_prologue_and_epilogue
);
1579 NEXT_PASS (pass_rtl_dse2
);
1580 NEXT_PASS (pass_stack_adjustments
);
1581 NEXT_PASS (pass_jump2
);
1582 NEXT_PASS (pass_peephole2
);
1583 NEXT_PASS (pass_if_after_reload
);
1584 NEXT_PASS (pass_regrename
);
1585 NEXT_PASS (pass_cprop_hardreg
);
1586 NEXT_PASS (pass_fast_rtl_dce
);
1587 NEXT_PASS (pass_reorder_blocks
);
1588 NEXT_PASS (pass_branch_target_load_optimize2
);
1589 NEXT_PASS (pass_leaf_regs
);
1590 NEXT_PASS (pass_split_before_sched2
);
1591 NEXT_PASS (pass_sched2
);
1592 NEXT_PASS (pass_stack_regs
);
1594 struct opt_pass
**p
= &pass_stack_regs
.pass
.sub
;
1595 NEXT_PASS (pass_split_before_regstack
);
1596 NEXT_PASS (pass_stack_regs_run
);
1598 NEXT_PASS (pass_compute_alignments
);
1599 NEXT_PASS (pass_duplicate_computed_gotos
);
1600 NEXT_PASS (pass_variable_tracking
);
1601 NEXT_PASS (pass_free_cfg
);
1602 NEXT_PASS (pass_machine_reorg
);
1603 NEXT_PASS (pass_cleanup_barriers
);
1604 NEXT_PASS (pass_delay_slots
);
1605 NEXT_PASS (pass_split_for_shorten_branches
);
1606 NEXT_PASS (pass_convert_to_eh_region_ranges
);
1607 NEXT_PASS (pass_shorten_branches
);
1608 NEXT_PASS (pass_set_nothrow_function_flags
);
1609 NEXT_PASS (pass_dwarf2_frame
);
1610 NEXT_PASS (pass_final
);
1612 NEXT_PASS (pass_df_finish
);
1614 NEXT_PASS (pass_clean_state
);
1619 /* Register the passes with the tree dump code. */
1620 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1621 register_dump_files (all_small_ipa_passes
,
1622 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1624 register_dump_files (all_regular_ipa_passes
,
1625 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1627 register_dump_files (all_lto_gen_passes
,
1628 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1630 register_dump_files (all_late_ipa_passes
,
1631 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1633 register_dump_files (all_passes
,
1634 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1638 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1639 function CALLBACK for every function in the call graph. Otherwise,
1640 call CALLBACK on the current function. */
1643 do_per_function (void (*callback
) (void *data
), void *data
)
1645 if (current_function_decl
)
1649 struct cgraph_node
*node
;
1650 FOR_EACH_DEFINED_FUNCTION (node
)
1651 if (gimple_has_body_p (node
->symbol
.decl
)
1652 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1654 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1655 current_function_decl
= node
->symbol
.decl
;
1659 free_dominance_info (CDI_DOMINATORS
);
1660 free_dominance_info (CDI_POST_DOMINATORS
);
1662 current_function_decl
= NULL
;
1669 /* Because inlining might remove no-longer reachable nodes, we need to
1670 keep the array visible to garbage collector to avoid reading collected
1673 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1675 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1676 function CALLBACK for every function in the call graph. Otherwise,
1677 call CALLBACK on the current function.
1678 This function is global so that plugins can use it. */
1680 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1684 if (current_function_decl
)
1688 gcc_assert (!order
);
1689 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1690 nnodes
= ipa_reverse_postorder (order
);
1691 for (i
= nnodes
- 1; i
>= 0; i
--)
1692 order
[i
]->process
= 1;
1693 for (i
= nnodes
- 1; i
>= 0; i
--)
1695 struct cgraph_node
*node
= order
[i
];
1697 /* Allow possibly removed nodes to be garbage collected. */
1700 if (cgraph_function_with_gimple_body_p (node
))
1702 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1703 current_function_decl
= node
->symbol
.decl
;
1705 free_dominance_info (CDI_DOMINATORS
);
1706 free_dominance_info (CDI_POST_DOMINATORS
);
1707 current_function_decl
= NULL
;
1718 /* Helper function to perform function body dump. */
1721 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1723 if (dump_file
&& current_function_decl
)
1725 if (cfun
->curr_properties
& PROP_trees
)
1726 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1729 if (dump_flags
& TDF_SLIM
)
1730 print_rtl_slim_with_bb (dump_file
, get_insns (), dump_flags
);
1731 else if ((cfun
->curr_properties
& PROP_cfg
)
1732 && (dump_flags
& TDF_BLOCKS
))
1733 print_rtl_with_bb (dump_file
, get_insns ());
1735 print_rtl (dump_file
, get_insns ());
1737 if ((cfun
->curr_properties
& PROP_cfg
)
1738 && graph_dump_format
!= no_graph
1739 && (dump_flags
& TDF_GRAPH
))
1740 print_rtl_graph_with_bb (dump_file_name
, get_insns ());
1743 /* Flush the file. If verification fails, we won't be able to
1744 close the file before aborting. */
1749 /* Perform all TODO actions that ought to be done on each function. */
1752 execute_function_todo (void *data
)
1754 unsigned int flags
= (size_t)data
;
1755 flags
&= ~cfun
->last_verified
;
1759 /* Always cleanup the CFG before trying to update SSA. */
1760 if (flags
& TODO_cleanup_cfg
)
1762 bool cleanup
= cleanup_tree_cfg ();
1764 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
1765 flags
|= TODO_remove_unused_locals
;
1767 /* When cleanup_tree_cfg merges consecutive blocks, it may
1768 perform some simplistic propagation when removing single
1769 valued PHI nodes. This propagation may, in turn, cause the
1770 SSA form to become out-of-date (see PR 22037). So, even
1771 if the parent pass had not scheduled an SSA update, we may
1772 still need to do one. */
1773 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1774 flags
|= TODO_update_ssa
;
1777 if (flags
& TODO_update_ssa_any
)
1779 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1780 update_ssa (update_flags
);
1781 cfun
->last_verified
&= ~TODO_verify_ssa
;
1784 if (flags
& TODO_rebuild_alias
)
1786 execute_update_addresses_taken ();
1787 compute_may_aliases ();
1789 else if (optimize
&& (flags
& TODO_update_address_taken
))
1790 execute_update_addresses_taken ();
1792 if (flags
& TODO_remove_unused_locals
)
1793 remove_unused_locals ();
1795 if (flags
& TODO_rebuild_frequencies
)
1796 rebuild_frequencies ();
1798 if (flags
& TODO_rebuild_cgraph_edges
)
1799 rebuild_cgraph_edges ();
1801 /* If we've seen errors do not bother running any verifiers. */
1805 #if defined ENABLE_CHECKING
1806 if (flags
& TODO_verify_ssa
1807 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1809 verify_gimple_in_cfg (cfun
);
1812 else if (flags
& TODO_verify_stmts
)
1813 verify_gimple_in_cfg (cfun
);
1814 if (flags
& TODO_verify_flow
)
1815 verify_flow_info ();
1816 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1817 verify_loop_closed_ssa (false);
1818 if (flags
& TODO_verify_rtl_sharing
)
1819 verify_rtl_sharing ();
1822 cfun
->last_verified
= flags
& TODO_verify_all
;
1825 /* Perform all TODO actions. */
1827 execute_todo (unsigned int flags
)
1829 #if defined ENABLE_CHECKING
1831 && need_ssa_update_p (cfun
))
1832 gcc_assert (flags
& TODO_update_ssa_any
);
1835 timevar_push (TV_TODO
);
1837 /* Inform the pass whether it is the first time it is run. */
1838 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1840 statistics_fini_pass ();
1842 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1844 /* Always remove functions just as before inlining: IPA passes might be
1845 interested to see bodies of extern inline functions that are not inlined
1846 to analyze side effects. The full removal is done just at the end
1847 of IPA pass queue. */
1848 if (flags
& TODO_remove_functions
)
1851 symtab_remove_unreachable_nodes (true, dump_file
);
1854 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1857 dump_symtab (dump_file
);
1858 /* Flush the file. If verification fails, we won't be able to
1859 close the file before aborting. */
1863 if (flags
& TODO_ggc_collect
)
1866 /* Now that the dumping has been done, we can get rid of the optional
1868 if (flags
& TODO_df_finish
)
1869 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1871 timevar_pop (TV_TODO
);
1874 /* Verify invariants that should hold between passes. This is a place
1875 to put simple sanity checks. */
1878 verify_interpass_invariants (void)
1880 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1883 /* Clear the last verified flag. */
1886 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
1888 cfun
->last_verified
= 0;
1891 /* Helper function. Verify that the properties has been turn into the
1892 properties expected by the pass. */
1894 #ifdef ENABLE_CHECKING
1896 verify_curr_properties (void *data
)
1898 unsigned int props
= (size_t)data
;
1899 gcc_assert ((cfun
->curr_properties
& props
) == props
);
1903 /* Initialize pass dump file. */
1904 /* This is non-static so that the plugins can use it. */
1907 pass_init_dump_file (struct opt_pass
*pass
)
1909 /* If a dump file name is present, open it if enabled. */
1910 if (pass
->static_pass_number
!= -1)
1912 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
1913 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
1914 dump_file
= dump_begin (pass
->static_pass_number
, &dump_flags
);
1915 if (dump_file
&& current_function_decl
)
1916 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1917 return initializing_dump
;
1923 /* Flush PASS dump file. */
1924 /* This is non-static so that plugins can use it. */
1927 pass_fini_dump_file (struct opt_pass
*pass
)
1929 /* Flush and close dump file. */
1932 free (CONST_CAST (char *, dump_file_name
));
1933 dump_file_name
= NULL
;
1938 dump_end (pass
->static_pass_number
, dump_file
);
1943 /* After executing the pass, apply expected changes to the function
1947 update_properties_after_pass (void *data
)
1949 struct opt_pass
*pass
= (struct opt_pass
*) data
;
1950 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
1951 & ~pass
->properties_destroyed
;
1954 /* Execute summary generation for all of the passes in IPA_PASS. */
1957 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
1961 struct opt_pass
*pass
= &ipa_pass
->pass
;
1963 /* Execute all of the IPA_PASSes in the list. */
1964 if (ipa_pass
->pass
.type
== IPA_PASS
1965 && (!pass
->gate
|| pass
->gate ())
1966 && ipa_pass
->generate_summary
)
1968 pass_init_dump_file (pass
);
1970 /* If a timevar is present, start it. */
1972 timevar_push (pass
->tv_id
);
1974 ipa_pass
->generate_summary ();
1978 timevar_pop (pass
->tv_id
);
1980 pass_fini_dump_file (pass
);
1982 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->pass
.next
;
1986 /* Execute IPA_PASS function transform on NODE. */
1989 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
1990 struct ipa_opt_pass_d
*ipa_pass
)
1992 struct opt_pass
*pass
= &ipa_pass
->pass
;
1993 unsigned int todo_after
= 0;
1995 current_pass
= pass
;
1996 if (!ipa_pass
->function_transform
)
1999 /* Note that the folders should only create gimple expressions.
2000 This is a hack until the new folder is ready. */
2001 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2003 pass_init_dump_file (pass
);
2005 /* Run pre-pass verification. */
2006 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2008 /* If a timevar is present, start it. */
2009 if (pass
->tv_id
!= TV_NONE
)
2010 timevar_push (pass
->tv_id
);
2013 todo_after
= ipa_pass
->function_transform (node
);
2016 if (pass
->tv_id
!= TV_NONE
)
2017 timevar_pop (pass
->tv_id
);
2019 /* Run post-pass cleanup and verification. */
2020 execute_todo (todo_after
);
2021 verify_interpass_invariants ();
2023 do_per_function (execute_function_dump
, NULL
);
2024 pass_fini_dump_file (pass
);
2026 current_pass
= NULL
;
2029 /* For the current function, execute all ipa transforms. */
2032 execute_all_ipa_transforms (void)
2034 struct cgraph_node
*node
;
2037 node
= cgraph_get_node (current_function_decl
);
2039 if (node
->ipa_transforms_to_apply
)
2043 for (i
= 0; i
< VEC_length (ipa_opt_pass
, node
->ipa_transforms_to_apply
);
2045 execute_one_ipa_transform_pass (node
,
2046 VEC_index (ipa_opt_pass
,
2047 node
->ipa_transforms_to_apply
,
2049 VEC_free (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
);
2050 node
->ipa_transforms_to_apply
= NULL
;
2054 /* Callback for do_per_function to apply all IPA transforms. */
2057 apply_ipa_transforms (void *data
)
2059 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2060 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
)
2062 *(bool *)data
= true;
2063 execute_all_ipa_transforms();
2064 rebuild_cgraph_edges ();
2068 /* Check if PASS is explicitly disabled or enabled and return
2069 the gate status. FUNC is the function to be processed, and
2070 GATE_STATUS is the gate status determined by pass manager by
2074 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2076 bool explicitly_enabled
= false;
2077 bool explicitly_disabled
= false;
2080 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2081 enabled_pass_uid_range_tab
);
2083 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2084 disabled_pass_uid_range_tab
);
2086 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2095 execute_one_pass (struct opt_pass
*pass
)
2097 bool initializing_dump
;
2098 unsigned int todo_after
= 0;
2102 /* IPA passes are executed on whole program, so cfun should be NULL.
2103 Other passes need function context set. */
2104 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2105 gcc_assert (!cfun
&& !current_function_decl
);
2107 gcc_assert (cfun
&& current_function_decl
);
2109 current_pass
= pass
;
2111 /* Check whether gate check should be avoided.
2112 User controls the value of the gate through the parameter "gate_status". */
2113 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2114 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2116 /* Override gate with plugin. */
2117 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2121 current_pass
= NULL
;
2125 /* Pass execution event trigger: useful to identify passes being
2127 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2129 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2130 Apply all trnasforms first. */
2131 if (pass
->type
== SIMPLE_IPA_PASS
)
2133 bool applied
= false;
2134 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2136 symtab_remove_unreachable_nodes (true, dump_file
);
2137 /* Restore current_pass. */
2138 current_pass
= pass
;
2141 if (!quiet_flag
&& !cfun
)
2142 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2144 /* Note that the folders should only create gimple expressions.
2145 This is a hack until the new folder is ready. */
2146 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2148 initializing_dump
= pass_init_dump_file (pass
);
2150 /* Run pre-pass verification. */
2151 execute_todo (pass
->todo_flags_start
);
2153 #ifdef ENABLE_CHECKING
2154 do_per_function (verify_curr_properties
,
2155 (void *)(size_t)pass
->properties_required
);
2158 /* If a timevar is present, start it. */
2159 if (pass
->tv_id
!= TV_NONE
)
2160 timevar_push (pass
->tv_id
);
2165 todo_after
= pass
->execute ();
2166 do_per_function (clear_last_verified
, NULL
);
2170 if (pass
->tv_id
!= TV_NONE
)
2171 timevar_pop (pass
->tv_id
);
2173 do_per_function (update_properties_after_pass
, pass
);
2175 if (initializing_dump
2177 && graph_dump_format
!= no_graph
2179 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
2180 == (PROP_cfg
| PROP_rtl
))
2182 get_dump_file_info (pass
->static_pass_number
)->flags
|= TDF_GRAPH
;
2183 dump_flags
|= TDF_GRAPH
;
2184 clean_graph_dump_file (dump_file_name
);
2187 /* Run post-pass cleanup and verification. */
2188 execute_todo (todo_after
| pass
->todo_flags_finish
);
2189 verify_interpass_invariants ();
2190 do_per_function (execute_function_dump
, NULL
);
2191 if (pass
->type
== IPA_PASS
)
2193 struct cgraph_node
*node
;
2194 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2195 VEC_safe_push (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
,
2196 (struct ipa_opt_pass_d
*)pass
);
2199 if (!current_function_decl
)
2200 cgraph_process_new_functions ();
2202 pass_fini_dump_file (pass
);
2204 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2205 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2206 || pass
->type
!= RTL_PASS
);
2208 current_pass
= NULL
;
2214 execute_pass_list (struct opt_pass
*pass
)
2218 gcc_assert (pass
->type
== GIMPLE_PASS
2219 || pass
->type
== RTL_PASS
);
2220 if (execute_one_pass (pass
) && pass
->sub
)
2221 execute_pass_list (pass
->sub
);
2227 /* Same as execute_pass_list but assume that subpasses of IPA passes
2228 are local passes. If SET is not NULL, write out summaries of only
2229 those node in SET. */
2232 ipa_write_summaries_2 (struct opt_pass
*pass
, cgraph_node_set set
,
2233 varpool_node_set vset
,
2234 struct lto_out_decl_state
*state
)
2238 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2239 gcc_assert (!current_function_decl
);
2241 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2242 if (pass
->type
== IPA_PASS
2243 && ipa_pass
->write_summary
2244 && (!pass
->gate
|| pass
->gate ()))
2246 /* If a timevar is present, start it. */
2248 timevar_push (pass
->tv_id
);
2250 pass_init_dump_file (pass
);
2252 ipa_pass
->write_summary (set
,vset
);
2254 pass_fini_dump_file (pass
);
2256 /* If a timevar is present, start it. */
2258 timevar_pop (pass
->tv_id
);
2261 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2262 ipa_write_summaries_2 (pass
->sub
, set
, vset
, state
);
2268 /* Helper function of ipa_write_summaries. Creates and destroys the
2269 decl state and calls ipa_write_summaries_2 for all passes that have
2270 summaries. SET is the set of nodes to be written. */
2273 ipa_write_summaries_1 (cgraph_node_set set
, varpool_node_set vset
)
2275 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2276 compute_ltrans_boundary (state
, set
, vset
);
2278 lto_push_out_decl_state (state
);
2280 gcc_assert (!flag_wpa
);
2281 ipa_write_summaries_2 (all_regular_ipa_passes
, set
, vset
, state
);
2282 ipa_write_summaries_2 (all_lto_gen_passes
, set
, vset
, state
);
2284 gcc_assert (lto_get_out_decl_state () == state
);
2285 lto_pop_out_decl_state ();
2286 lto_delete_out_decl_state (state
);
2289 /* Write out summaries for all the nodes in the callgraph. */
2292 ipa_write_summaries (void)
2294 cgraph_node_set set
;
2295 varpool_node_set vset
;
2296 struct cgraph_node
**order
;
2297 struct varpool_node
*vnode
;
2300 if (!flag_generate_lto
|| seen_error ())
2303 set
= cgraph_node_set_new ();
2305 /* Create the callgraph set in the same order used in
2306 cgraph_expand_all_functions. This mostly facilitates debugging,
2307 since it causes the gimple file to be processed in the same order
2308 as the source code. */
2309 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2310 order_pos
= ipa_reverse_postorder (order
);
2311 gcc_assert (order_pos
== cgraph_n_nodes
);
2313 for (i
= order_pos
- 1; i
>= 0; i
--)
2315 struct cgraph_node
*node
= order
[i
];
2317 if (cgraph_function_with_gimple_body_p (node
))
2319 /* When streaming out references to statements as part of some IPA
2320 pass summary, the statements need to have uids assigned and the
2321 following does that for all the IPA passes here. Naturally, this
2322 ordering then matches the one IPA-passes get in their stmt_fixup
2325 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2326 renumber_gimple_stmt_uids ();
2330 cgraph_node_set_add (set
, node
);
2332 vset
= varpool_node_set_new ();
2334 FOR_EACH_DEFINED_VARIABLE (vnode
)
2335 if ((!vnode
->alias
|| vnode
->alias_of
))
2336 varpool_node_set_add (vset
, vnode
);
2338 ipa_write_summaries_1 (set
, vset
);
2341 free_cgraph_node_set (set
);
2342 free_varpool_node_set (vset
);
2345 /* Same as execute_pass_list but assume that subpasses of IPA passes
2346 are local passes. If SET is not NULL, write out optimization summaries of
2347 only those node in SET. */
2350 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, cgraph_node_set set
,
2351 varpool_node_set vset
,
2352 struct lto_out_decl_state
*state
)
2356 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2357 gcc_assert (!current_function_decl
);
2359 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2360 if (pass
->type
== IPA_PASS
2361 && ipa_pass
->write_optimization_summary
2362 && (!pass
->gate
|| pass
->gate ()))
2364 /* If a timevar is present, start it. */
2366 timevar_push (pass
->tv_id
);
2368 pass_init_dump_file (pass
);
2370 ipa_pass
->write_optimization_summary (set
, vset
);
2372 pass_fini_dump_file (pass
);
2374 /* If a timevar is present, start it. */
2376 timevar_pop (pass
->tv_id
);
2379 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2380 ipa_write_optimization_summaries_1 (pass
->sub
, set
, vset
, state
);
2386 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2387 NULL, write out all summaries of all nodes. */
2390 ipa_write_optimization_summaries (cgraph_node_set set
, varpool_node_set vset
)
2392 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2393 cgraph_node_set_iterator csi
;
2394 compute_ltrans_boundary (state
, set
, vset
);
2396 lto_push_out_decl_state (state
);
2397 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
2399 struct cgraph_node
*node
= csi_node (csi
);
2400 /* When streaming out references to statements as part of some IPA
2401 pass summary, the statements need to have uids assigned.
2403 For functions newly born at WPA stage we need to initialize
2406 && gimple_has_body_p (node
->symbol
.decl
))
2408 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2409 renumber_gimple_stmt_uids ();
2414 gcc_assert (flag_wpa
);
2415 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, set
, vset
, state
);
2416 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, set
, vset
, state
);
2418 gcc_assert (lto_get_out_decl_state () == state
);
2419 lto_pop_out_decl_state ();
2420 lto_delete_out_decl_state (state
);
2423 /* Same as execute_pass_list but assume that subpasses of IPA passes
2424 are local passes. */
2427 ipa_read_summaries_1 (struct opt_pass
*pass
)
2431 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2433 gcc_assert (!current_function_decl
);
2435 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2437 if (pass
->gate
== NULL
|| pass
->gate ())
2439 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2441 /* If a timevar is present, start it. */
2443 timevar_push (pass
->tv_id
);
2445 pass_init_dump_file (pass
);
2447 ipa_pass
->read_summary ();
2449 pass_fini_dump_file (pass
);
2453 timevar_pop (pass
->tv_id
);
2456 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2457 ipa_read_summaries_1 (pass
->sub
);
2464 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2467 ipa_read_summaries (void)
2469 ipa_read_summaries_1 (all_regular_ipa_passes
);
2470 ipa_read_summaries_1 (all_lto_gen_passes
);
2473 /* Same as execute_pass_list but assume that subpasses of IPA passes
2474 are local passes. */
2477 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2481 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2483 gcc_assert (!current_function_decl
);
2485 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2487 if (pass
->gate
== NULL
|| pass
->gate ())
2489 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2491 /* If a timevar is present, start it. */
2493 timevar_push (pass
->tv_id
);
2495 pass_init_dump_file (pass
);
2497 ipa_pass
->read_optimization_summary ();
2499 pass_fini_dump_file (pass
);
2503 timevar_pop (pass
->tv_id
);
2506 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2507 ipa_read_optimization_summaries_1 (pass
->sub
);
2513 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2516 ipa_read_optimization_summaries (void)
2518 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2519 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2522 /* Same as execute_pass_list but assume that subpasses of IPA passes
2523 are local passes. */
2525 execute_ipa_pass_list (struct opt_pass
*pass
)
2529 gcc_assert (!current_function_decl
);
2531 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2532 if (execute_one_pass (pass
) && pass
->sub
)
2534 if (pass
->sub
->type
== GIMPLE_PASS
)
2536 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2537 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2539 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2541 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2542 || pass
->sub
->type
== IPA_PASS
)
2543 execute_ipa_pass_list (pass
->sub
);
2547 gcc_assert (!current_function_decl
);
2548 cgraph_process_new_functions ();
2554 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2557 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2558 struct cgraph_node
*node
, gimple
*stmts
)
2562 /* Execute all of the IPA_PASSes in the list. */
2563 if (pass
->type
== IPA_PASS
2564 && (!pass
->gate
|| pass
->gate ()))
2566 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2568 if (ipa_pass
->stmt_fixup
)
2570 pass_init_dump_file (pass
);
2571 /* If a timevar is present, start it. */
2573 timevar_push (pass
->tv_id
);
2575 ipa_pass
->stmt_fixup (node
, stmts
);
2579 timevar_pop (pass
->tv_id
);
2580 pass_fini_dump_file (pass
);
2583 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2589 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2592 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2594 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2598 extern void debug_properties (unsigned int);
2599 extern void dump_properties (FILE *, unsigned int);
2602 dump_properties (FILE *dump
, unsigned int props
)
2604 fprintf (dump
, "Properties:\n");
2605 if (props
& PROP_gimple_any
)
2606 fprintf (dump
, "PROP_gimple_any\n");
2607 if (props
& PROP_gimple_lcf
)
2608 fprintf (dump
, "PROP_gimple_lcf\n");
2609 if (props
& PROP_gimple_leh
)
2610 fprintf (dump
, "PROP_gimple_leh\n");
2611 if (props
& PROP_cfg
)
2612 fprintf (dump
, "PROP_cfg\n");
2613 if (props
& PROP_referenced_vars
)
2614 fprintf (dump
, "PROP_referenced_vars\n");
2615 if (props
& PROP_ssa
)
2616 fprintf (dump
, "PROP_ssa\n");
2617 if (props
& PROP_no_crit_edges
)
2618 fprintf (dump
, "PROP_no_crit_edges\n");
2619 if (props
& PROP_rtl
)
2620 fprintf (dump
, "PROP_rtl\n");
2621 if (props
& PROP_gimple_lomp
)
2622 fprintf (dump
, "PROP_gimple_lomp\n");
2623 if (props
& PROP_gimple_lcx
)
2624 fprintf (dump
, "PROP_gimple_lcx\n");
2625 if (props
& PROP_cfglayout
)
2626 fprintf (dump
, "PROP_cfglayout\n");
2630 debug_properties (unsigned int props
)
2632 dump_properties (stderr
, props
);
2635 /* Called by local passes to see if function is called by already processed nodes.
2636 Because we process nodes in topological order, this means that function is
2637 in recursive cycle or we introduced new direct calls. */
2639 function_called_by_processed_nodes_p (void)
2641 struct cgraph_edge
*e
;
2642 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2646 if (e
->caller
->symbol
.decl
== current_function_decl
)
2648 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2650 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2652 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2657 fprintf (dump_file
, "Already processed call to:\n");
2658 dump_cgraph_node (dump_file
, e
->caller
);
2663 #include "gt-passes.h"