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"
56 #include "dwarf2asm.h"
57 #include "integrate.h"
60 #include "langhooks.h"
61 #include "cfglayout.h"
63 #include "hosthooks.h"
67 #include "value-prof.h"
68 #include "tree-inline.h"
69 #include "tree-flow.h"
70 #include "tree-pass.h"
71 #include "tree-dump.h"
74 #include "lto-streamer.h"
76 #include "ipa-utils.h"
77 #include "tree-pretty-print.h"
79 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
80 #include "dwarf2out.h"
83 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
87 #ifdef SDB_DEBUGGING_INFO
91 #ifdef XCOFF_DEBUGGING_INFO
92 #include "xcoffout.h" /* Needed for external data
93 declarations for e.g. AIX 4.x. */
96 /* This is used for debugging. It allows the current pass to printed
97 from anywhere in compilation.
98 The variable current_pass is also used for statistics and plugins. */
99 struct opt_pass
*current_pass
;
101 static void register_pass_name (struct opt_pass
*, const char *);
103 /* Call from anywhere to find out what pass this is. Useful for
104 printing out debugging information deep inside an service
107 print_current_pass (FILE *file
)
110 fprintf (file
, "current pass = %s (%d)\n",
111 current_pass
->name
, current_pass
->static_pass_number
);
113 fprintf (file
, "no current pass.\n");
117 /* Call from the debugger to get the current pass name. */
121 print_current_pass (stderr
);
126 /* Global variables used to communicate with passes. */
129 bool first_pass_instance
;
132 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
135 This does nothing for local (non-static) variables, unless the
136 variable is a register variable with DECL_ASSEMBLER_NAME set. In
137 that case, or if the variable is not an automatic, it sets up the
138 RTL and outputs any assembler code (label definition, storage
139 allocation and initialization).
141 DECL is the declaration. TOP_LEVEL is nonzero
142 if this declaration is not within a function. */
145 rest_of_decl_compilation (tree decl
,
149 /* We deferred calling assemble_alias so that we could collect
150 other attributes such as visibility. Emit the alias now. */
154 alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
157 alias
= TREE_VALUE (TREE_VALUE (alias
));
158 alias
= get_identifier (TREE_STRING_POINTER (alias
));
159 /* A quirk of the initial implementation of aliases required that the
160 user add "extern" to all of them. Which is silly, but now
161 historical. Do note that the symbol is in fact locally defined. */
162 if (!lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
163 DECL_EXTERNAL (decl
) = 0;
164 assemble_alias (decl
, alias
);
168 /* Can't defer this, because it needs to happen before any
169 later function definitions are processed. */
170 if (DECL_ASSEMBLER_NAME_SET_P (decl
) && DECL_REGISTER (decl
))
171 make_decl_rtl (decl
);
173 /* Forward declarations for nested functions are not "external",
174 but we need to treat them as if they were. */
175 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
176 || TREE_CODE (decl
) == FUNCTION_DECL
)
178 timevar_push (TV_VARCONST
);
180 /* Don't output anything when a tentative file-scope definition
181 is seen. But at end of compilation, do output code for them.
183 We do output all variables and rely on
184 callgraph code to defer them except for forward declarations
185 (see gcc.c-torture/compile/920624-1.c) */
187 || !DECL_DEFER_OUTPUT (decl
)
188 || DECL_INITIAL (decl
))
189 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
))
190 && !DECL_EXTERNAL (decl
))
192 /* When reading LTO unit, we also read varpool, so do not
194 if (in_lto_p
&& !at_end
)
196 else if (TREE_CODE (decl
) != FUNCTION_DECL
)
197 varpool_finalize_decl (decl
);
200 #ifdef ASM_FINISH_DECLARE_OBJECT
201 if (decl
== last_assemble_variable_decl
)
203 ASM_FINISH_DECLARE_OBJECT (asm_out_file
, decl
,
208 timevar_pop (TV_VARCONST
);
210 else if (TREE_CODE (decl
) == TYPE_DECL
211 /* Like in rest_of_type_compilation, avoid confusing the debug
212 information machinery when there are errors. */
215 timevar_push (TV_SYMOUT
);
216 debug_hooks
->type_decl (decl
, !top_level
);
217 timevar_pop (TV_SYMOUT
);
220 /* Let cgraph know about the existence of variables. */
221 if (in_lto_p
&& !at_end
)
223 else if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
)
224 && TREE_STATIC (decl
))
228 /* Called after finishing a record, union or enumeral type. */
231 rest_of_type_compilation (tree type
, int toplev
)
233 /* Avoid confusing the debug information machinery when there are
238 timevar_push (TV_SYMOUT
);
239 debug_hooks
->type_decl (TYPE_STUB_DECL (type
), !toplev
);
240 timevar_pop (TV_SYMOUT
);
246 finish_optimization_passes (void)
249 struct dump_file_info
*dfi
;
252 timevar_push (TV_DUMP
);
253 if (profile_arc_flag
|| flag_test_coverage
|| flag_branch_probabilities
)
255 dump_file
= dump_begin (pass_profile
.pass
.static_pass_number
, NULL
);
258 dump_end (pass_profile
.pass
.static_pass_number
, dump_file
);
263 dump_file
= dump_begin (pass_combine
.pass
.static_pass_number
, NULL
);
266 dump_combine_total_stats (dump_file
);
267 dump_end (pass_combine
.pass
.static_pass_number
, dump_file
);
271 /* Do whatever is necessary to finish printing the graphs. */
272 if (graph_dump_format
!= no_graph
)
273 for (i
= TDI_end
; (dfi
= get_dump_file_info (i
)) != NULL
; ++i
)
274 if (dump_initialized_p (i
)
275 && (dfi
->flags
& TDF_GRAPH
) != 0
276 && (name
= get_dump_file_name (i
)) != NULL
)
278 finish_graph_dump_file (name
);
282 timevar_pop (TV_DUMP
);
286 execute_all_early_local_passes (void)
288 /* Once this pass (and its sub-passes) are complete, all functions
289 will be in SSA form. Technically this state change is happening
290 a tad early, since the sub-passes have not yet run, but since
291 none of the sub-passes are IPA passes and do not create new
292 functions, this is ok. We're setting this value for the benefit
293 of IPA passes that follow. */
294 if (cgraph_state
< CGRAPH_STATE_IPA_SSA
)
295 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
299 /* Gate: execute, or not, all of the non-trivial optimizations. */
302 gate_all_early_local_passes (void)
304 /* Don't bother doing anything if the program has errors. */
305 return (!seen_error () && !in_lto_p
);
308 struct simple_ipa_opt_pass pass_early_local_passes
=
312 "early_local_cleanups", /* name */
313 gate_all_early_local_passes
, /* gate */
314 execute_all_early_local_passes
, /* execute */
317 0, /* static_pass_number */
318 TV_EARLY_LOCAL
, /* tv_id */
319 0, /* properties_required */
320 0, /* properties_provided */
321 0, /* properties_destroyed */
322 0, /* todo_flags_start */
323 TODO_remove_functions
/* todo_flags_finish */
327 /* Gate: execute, or not, all of the non-trivial optimizations. */
330 gate_all_early_optimizations (void)
332 return (optimize
>= 1
333 /* Don't bother doing anything if the program has errors. */
337 static struct gimple_opt_pass pass_all_early_optimizations
=
341 "early_optimizations", /* name */
342 gate_all_early_optimizations
, /* gate */
346 0, /* static_pass_number */
348 0, /* properties_required */
349 0, /* properties_provided */
350 0, /* properties_destroyed */
351 0, /* todo_flags_start */
352 0 /* todo_flags_finish */
356 /* Gate: execute, or not, all of the non-trivial optimizations. */
359 gate_all_optimizations (void)
361 return (optimize
>= 1
362 /* Don't bother doing anything if the program has errors.
363 We have to pass down the queue if we already went into SSA */
364 && (!seen_error () || gimple_in_ssa_p (cfun
)));
367 static struct gimple_opt_pass pass_all_optimizations
=
371 "*all_optimizations", /* name */
372 gate_all_optimizations
, /* gate */
376 0, /* static_pass_number */
377 TV_OPTIMIZE
, /* tv_id */
378 0, /* properties_required */
379 0, /* properties_provided */
380 0, /* properties_destroyed */
381 0, /* todo_flags_start */
382 0 /* todo_flags_finish */
387 gate_rest_of_compilation (void)
389 /* Early return if there were errors. We can run afoul of our
390 consistency checks, and there's not really much point in fixing them. */
391 return !(rtl_dump_and_exit
|| flag_syntax_only
|| seen_error ());
394 static struct rtl_opt_pass pass_rest_of_compilation
=
398 "*rest_of_compilation", /* name */
399 gate_rest_of_compilation
, /* gate */
403 0, /* static_pass_number */
404 TV_REST_OF_COMPILATION
, /* tv_id */
405 PROP_rtl
, /* properties_required */
406 0, /* properties_provided */
407 0, /* properties_destroyed */
408 0, /* todo_flags_start */
409 TODO_ggc_collect
/* todo_flags_finish */
414 gate_postreload (void)
416 return reload_completed
;
419 static struct rtl_opt_pass pass_postreload
=
423 "*all-postreload", /* name */
424 gate_postreload
, /* gate */
428 0, /* static_pass_number */
429 TV_POSTRELOAD
, /* tv_id */
430 PROP_rtl
, /* properties_required */
431 0, /* properties_provided */
432 0, /* properties_destroyed */
433 0, /* todo_flags_start */
434 TODO_ggc_collect
| TODO_verify_rtl_sharing
/* todo_flags_finish */
440 /* The root of the compilation pass tree, once constructed. */
441 struct opt_pass
*all_passes
, *all_small_ipa_passes
, *all_lowering_passes
,
442 *all_regular_ipa_passes
, *all_late_ipa_passes
, *all_lto_gen_passes
;
444 /* This is used by plugins, and should also be used in register_pass. */
445 #define DEF_PASS_LIST(LIST) &LIST,
446 struct opt_pass
**gcc_pass_lists
[] = { GCC_PASS_LISTS NULL
};
449 /* A map from static pass id to optimization pass. */
450 struct opt_pass
**passes_by_id
;
451 int passes_by_id_size
;
453 /* Set the static pass number of pass PASS to ID and record that
454 in the mapping from static pass number to pass. */
457 set_pass_for_id (int id
, struct opt_pass
*pass
)
459 pass
->static_pass_number
= id
;
460 if (passes_by_id_size
<= id
)
462 passes_by_id
= XRESIZEVEC (struct opt_pass
*, passes_by_id
, id
+ 1);
463 memset (passes_by_id
+ passes_by_id_size
, 0,
464 (id
+ 1 - passes_by_id_size
) * sizeof (void *));
465 passes_by_id_size
= id
+ 1;
467 passes_by_id
[id
] = pass
;
470 /* Return the pass with the static pass number ID. */
473 get_pass_for_id (int id
)
475 if (id
>= passes_by_id_size
)
477 return passes_by_id
[id
];
480 /* Iterate over the pass tree allocating dump file numbers. We want
481 to do this depth first, and independent of whether the pass is
485 register_one_dump_file (struct opt_pass
*pass
)
487 char *dot_name
, *flag_name
, *glob_name
;
488 const char *name
, *full_name
, *prefix
;
492 /* See below in next_pass_1. */
494 if (pass
->static_pass_number
!= -1)
495 sprintf (num
, "%d", ((int) pass
->static_pass_number
< 0
496 ? 1 : pass
->static_pass_number
));
498 /* The name is both used to identify the pass for the purposes of plugins,
499 and to specify dump file name and option.
500 The latter two might want something short which is not quite unique; for
501 that reason, we may have a disambiguating prefix, followed by a space
502 to mark the start of the following dump file name / option string. */
503 name
= strchr (pass
->name
, ' ');
504 name
= name
? name
+ 1 : pass
->name
;
505 dot_name
= concat (".", name
, num
, NULL
);
506 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
507 prefix
= "ipa-", flags
= TDF_IPA
;
508 else if (pass
->type
== GIMPLE_PASS
)
509 prefix
= "tree-", flags
= TDF_TREE
;
511 prefix
= "rtl-", flags
= TDF_RTL
;
513 flag_name
= concat (prefix
, name
, num
, NULL
);
514 glob_name
= concat (prefix
, name
, NULL
);
515 id
= dump_register (dot_name
, flag_name
, glob_name
, flags
);
516 set_pass_for_id (id
, pass
);
517 full_name
= concat (prefix
, pass
->name
, num
, NULL
);
518 register_pass_name (pass
, full_name
);
519 free (CONST_CAST (char *, full_name
));
522 /* Recursive worker function for register_dump_files. */
525 register_dump_files_1 (struct opt_pass
*pass
, int properties
)
529 int new_properties
= (properties
| pass
->properties_provided
)
530 & ~pass
->properties_destroyed
;
532 if (pass
->name
&& pass
->name
[0] != '*')
533 register_one_dump_file (pass
);
536 new_properties
= register_dump_files_1 (pass
->sub
, new_properties
);
538 /* If we have a gate, combine the properties that we could have with
539 and without the pass being examined. */
541 properties
&= new_properties
;
543 properties
= new_properties
;
552 /* Register the dump files for the pipeline starting at PASS.
553 PROPERTIES reflects the properties that are guaranteed to be available at
554 the beginning of the pipeline. */
557 register_dump_files (struct opt_pass
*pass
,int properties
)
559 pass
->properties_required
|= properties
;
560 register_dump_files_1 (pass
, properties
);
565 const char* unique_name
;
566 struct opt_pass
*pass
;
569 /* Pass registry hash function. */
572 passr_hash (const void *p
)
574 const struct pass_registry
*const s
= (const struct pass_registry
*const) p
;
575 return htab_hash_string (s
->unique_name
);
578 /* Hash equal function */
581 passr_eq (const void *p1
, const void *p2
)
583 const struct pass_registry
*const s1
= (const struct pass_registry
*const) p1
;
584 const struct pass_registry
*const s2
= (const struct pass_registry
*const) p2
;
586 return !strcmp (s1
->unique_name
, s2
->unique_name
);
589 static htab_t name_to_pass_map
= NULL
;
591 /* Register PASS with NAME. */
594 register_pass_name (struct opt_pass
*pass
, const char *name
)
596 struct pass_registry
**slot
;
597 struct pass_registry pr
;
599 if (!name_to_pass_map
)
600 name_to_pass_map
= htab_create (256, passr_hash
, passr_eq
, NULL
);
602 pr
.unique_name
= name
;
603 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
, &pr
, INSERT
);
606 struct pass_registry
*new_pr
;
608 new_pr
= XCNEW (struct pass_registry
);
609 new_pr
->unique_name
= xstrdup (name
);
614 return; /* Ignore plugin passes. */
617 /* Map from pass id to canonicalized pass name. */
619 typedef const char *char_ptr
;
621 DEF_VEC_ALLOC_P(char_ptr
, heap
);
622 static VEC(char_ptr
, heap
) *pass_tab
= NULL
;
624 /* Callback function for traversing NAME_TO_PASS_MAP. */
627 pass_traverse (void **slot
, void *data ATTRIBUTE_UNUSED
)
629 struct pass_registry
**p
= (struct pass_registry
**)slot
;
630 struct opt_pass
*pass
= (*p
)->pass
;
632 gcc_assert (pass
->static_pass_number
> 0);
633 gcc_assert (pass_tab
);
635 VEC_replace (char_ptr
, pass_tab
, pass
->static_pass_number
,
641 /* The function traverses NAME_TO_PASS_MAP and creates a pass info
642 table for dumping purpose. */
645 create_pass_tab (void)
647 if (!flag_dump_passes
)
650 VEC_safe_grow_cleared (char_ptr
, heap
,
651 pass_tab
, passes_by_id_size
+ 1);
652 htab_traverse (name_to_pass_map
, pass_traverse
, NULL
);
655 static bool override_gate_status (struct opt_pass
*, tree
, bool);
657 /* Dump the instantiated name for PASS. IS_ON indicates if PASS
658 is turned on or not. */
661 dump_one_pass (struct opt_pass
*pass
, int pass_indent
)
663 int indent
= 3 * pass_indent
;
665 bool is_on
, is_really_on
;
667 is_on
= (pass
->gate
== NULL
) ? true : pass
->gate();
668 is_really_on
= override_gate_status (pass
, current_function_decl
, is_on
);
670 if (pass
->static_pass_number
<= 0)
673 pn
= VEC_index (char_ptr
, pass_tab
, pass
->static_pass_number
);
675 fprintf (stderr
, "%*s%-40s%*s:%s%s\n", indent
, " ", pn
,
676 (15 - indent
< 0 ? 0 : 15 - indent
), " ",
677 is_on
? " ON" : " OFF",
678 ((!is_on
) == (!is_really_on
) ? ""
679 : (is_really_on
? " (FORCED_ON)" : " (FORCED_OFF)")));
682 /* Dump pass list PASS with indentation INDENT. */
685 dump_pass_list (struct opt_pass
*pass
, int indent
)
689 dump_one_pass (pass
, indent
);
691 dump_pass_list (pass
->sub
, indent
+ 1);
697 /* Dump all optimization passes. */
702 struct cgraph_node
*n
, *node
= NULL
;
703 tree save_fndecl
= current_function_decl
;
707 FOR_EACH_DEFINED_FUNCTION (n
)
708 if (DECL_STRUCT_FUNCTION (n
->symbol
.decl
))
717 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
718 current_function_decl
= node
->symbol
.decl
;
720 dump_pass_list (all_lowering_passes
, 1);
721 dump_pass_list (all_small_ipa_passes
, 1);
722 dump_pass_list (all_regular_ipa_passes
, 1);
723 dump_pass_list (all_lto_gen_passes
, 1);
724 dump_pass_list (all_late_ipa_passes
, 1);
725 dump_pass_list (all_passes
, 1);
728 current_function_decl
= save_fndecl
;
732 /* Returns the pass with NAME. */
734 static struct opt_pass
*
735 get_pass_by_name (const char *name
)
737 struct pass_registry
**slot
, pr
;
739 pr
.unique_name
= name
;
740 slot
= (struct pass_registry
**) htab_find_slot (name_to_pass_map
,
746 return (*slot
)->pass
;
750 /* Range [start, last]. */
756 const char *assem_name
;
757 struct uid_range
*next
;
760 typedef struct uid_range
*uid_range_p
;
762 DEF_VEC_P(uid_range_p
);
763 DEF_VEC_ALLOC_P(uid_range_p
, heap
);
765 static VEC(uid_range_p
, heap
) *enabled_pass_uid_range_tab
= NULL
;
766 static VEC(uid_range_p
, heap
) *disabled_pass_uid_range_tab
= NULL
;
769 /* Parse option string for -fdisable- and -fenable-
770 The syntax of the options:
773 -fdisable-<pass_name>
775 -fenable-<pass_name>=s1:e1,s2:e2,...
776 -fdisable-<pass_name>=s1:e1,s2:e2,...
780 enable_disable_pass (const char *arg
, bool is_enable
)
782 struct opt_pass
*pass
;
783 char *range_str
, *phase_name
;
784 char *argstr
= xstrdup (arg
);
785 VEC(uid_range_p
, heap
) **tab
= 0;
787 range_str
= strchr (argstr
,'=');
798 error ("unrecognized option -fenable");
800 error ("unrecognized option -fdisable");
804 pass
= get_pass_by_name (phase_name
);
805 if (!pass
|| pass
->static_pass_number
== -1)
808 error ("unknown pass %s specified in -fenable", phase_name
);
810 error ("unknown pass %s specified in -fdisable", phase_name
);
816 tab
= &enabled_pass_uid_range_tab
;
818 tab
= &disabled_pass_uid_range_tab
;
820 if ((unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, *tab
))
821 VEC_safe_grow_cleared (uid_range_p
, heap
,
822 *tab
, pass
->static_pass_number
+ 1);
827 uid_range_p new_range
= XCNEW (struct uid_range
);
829 new_range
->start
= 0;
830 new_range
->last
= (unsigned)-1;
832 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
833 new_range
->next
= slot
;
834 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
837 inform (UNKNOWN_LOCATION
, "enable pass %s for functions in the range "
838 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
840 inform (UNKNOWN_LOCATION
, "disable pass %s for functions in the range "
841 "of [%u, %u]", phase_name
, new_range
->start
, new_range
->last
);
845 char *next_range
= NULL
;
846 char *one_range
= range_str
;
847 char *end_val
= NULL
;
852 uid_range_p new_range
;
853 char *invalid
= NULL
;
855 char *func_name
= NULL
;
857 next_range
= strchr (one_range
, ',');
864 end_val
= strchr (one_range
, ':');
870 start
= strtol (one_range
, &invalid
, 10);
871 if (*invalid
|| start
< 0)
873 if (end_val
|| (one_range
[0] >= '0'
874 && one_range
[0] <= '9'))
876 error ("Invalid range %s in option %s",
878 is_enable
? "-fenable" : "-fdisable");
882 func_name
= one_range
;
886 new_range
= XCNEW (struct uid_range
);
889 new_range
->start
= (unsigned) start
;
890 new_range
->last
= (unsigned) start
;
894 new_range
->start
= (unsigned) -1;
895 new_range
->last
= (unsigned) -1;
896 new_range
->assem_name
= xstrdup (func_name
);
901 long last
= strtol (end_val
, &invalid
, 10);
902 if (*invalid
|| last
< start
)
904 error ("Invalid range %s in option %s",
906 is_enable
? "-fenable" : "-fdisable");
910 new_range
= XCNEW (struct uid_range
);
911 new_range
->start
= (unsigned) start
;
912 new_range
->last
= (unsigned) last
;
915 slot
= VEC_index (uid_range_p
, *tab
, pass
->static_pass_number
);
916 new_range
->next
= slot
;
917 VEC_replace (uid_range_p
, *tab
, pass
->static_pass_number
,
921 if (new_range
->assem_name
)
922 inform (UNKNOWN_LOCATION
,
923 "enable pass %s for function %s",
924 phase_name
, new_range
->assem_name
);
926 inform (UNKNOWN_LOCATION
,
927 "enable pass %s for functions in the range of [%u, %u]",
928 phase_name
, new_range
->start
, new_range
->last
);
932 if (new_range
->assem_name
)
933 inform (UNKNOWN_LOCATION
,
934 "disable pass %s for function %s",
935 phase_name
, new_range
->assem_name
);
937 inform (UNKNOWN_LOCATION
,
938 "disable pass %s for functions in the range of [%u, %u]",
939 phase_name
, new_range
->start
, new_range
->last
);
942 one_range
= next_range
;
943 } while (next_range
);
949 /* Enable pass specified by ARG. */
952 enable_pass (const char *arg
)
954 enable_disable_pass (arg
, true);
957 /* Disable pass specified by ARG. */
960 disable_pass (const char *arg
)
962 enable_disable_pass (arg
, false);
965 /* Returns true if PASS is explicitly enabled/disabled for FUNC. */
968 is_pass_explicitly_enabled_or_disabled (struct opt_pass
*pass
,
970 VEC(uid_range_p
, heap
) *tab
)
972 uid_range_p slot
, range
;
974 const char *aname
= NULL
;
977 || (unsigned) pass
->static_pass_number
>= VEC_length (uid_range_p
, tab
)
978 || pass
->static_pass_number
== -1)
981 slot
= VEC_index (uid_range_p
, tab
, pass
->static_pass_number
);
985 cgraph_uid
= func
? cgraph_get_node (func
)->uid
: 0;
986 if (func
&& DECL_ASSEMBLER_NAME_SET_P (func
))
987 aname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func
));
992 if ((unsigned) cgraph_uid
>= range
->start
993 && (unsigned) cgraph_uid
<= range
->last
)
995 if (range
->assem_name
&& aname
996 && !strcmp (range
->assem_name
, aname
))
1004 /* Look at the static_pass_number and duplicate the pass
1005 if it is already added to a list. */
1007 static struct opt_pass
*
1008 make_pass_instance (struct opt_pass
*pass
, bool track_duplicates
)
1010 /* A nonzero static_pass_number indicates that the
1011 pass is already in the list. */
1012 if (pass
->static_pass_number
)
1014 struct opt_pass
*new_pass
;
1016 if (pass
->type
== GIMPLE_PASS
1017 || pass
->type
== RTL_PASS
1018 || pass
->type
== SIMPLE_IPA_PASS
)
1020 new_pass
= XNEW (struct opt_pass
);
1021 memcpy (new_pass
, pass
, sizeof (struct opt_pass
));
1023 else if (pass
->type
== IPA_PASS
)
1025 new_pass
= (struct opt_pass
*)XNEW (struct ipa_opt_pass_d
);
1026 memcpy (new_pass
, pass
, sizeof (struct ipa_opt_pass_d
));
1031 new_pass
->next
= NULL
;
1033 new_pass
->todo_flags_start
&= ~TODO_mark_first_instance
;
1035 /* Indicate to register_dump_files that this pass has duplicates,
1036 and so it should rename the dump file. The first instance will
1037 be -1, and be number of duplicates = -static_pass_number - 1.
1038 Subsequent instances will be > 0 and just the duplicate number. */
1039 if ((pass
->name
&& pass
->name
[0] != '*') || track_duplicates
)
1041 pass
->static_pass_number
-= 1;
1042 new_pass
->static_pass_number
= -pass
->static_pass_number
;
1048 pass
->todo_flags_start
|= TODO_mark_first_instance
;
1049 pass
->static_pass_number
= -1;
1051 invoke_plugin_callbacks (PLUGIN_NEW_PASS
, pass
);
1056 /* Add a pass to the pass list. Duplicate the pass if it's already
1059 static struct opt_pass
**
1060 next_pass_1 (struct opt_pass
**list
, struct opt_pass
*pass
)
1062 /* Every pass should have a name so that plugins can refer to them. */
1063 gcc_assert (pass
->name
!= NULL
);
1065 *list
= make_pass_instance (pass
, false);
1067 return &(*list
)->next
;
1070 /* List node for an inserted pass instance. We need to keep track of all
1071 the newly-added pass instances (with 'added_pass_nodes' defined below)
1072 so that we can register their dump files after pass-positioning is finished.
1073 Registering dumping files needs to be post-processed or the
1074 static_pass_number of the opt_pass object would be modified and mess up
1075 the dump file names of future pass instances to be added. */
1077 struct pass_list_node
1079 struct opt_pass
*pass
;
1080 struct pass_list_node
*next
;
1083 static struct pass_list_node
*added_pass_nodes
= NULL
;
1084 static struct pass_list_node
*prev_added_pass_node
;
1086 /* Insert the pass at the proper position. Return true if the pass
1087 is successfully added.
1089 NEW_PASS_INFO - new pass to be inserted
1090 PASS_LIST - root of the pass list to insert the new pass to */
1093 position_pass (struct register_pass_info
*new_pass_info
,
1094 struct opt_pass
**pass_list
)
1096 struct opt_pass
*pass
= *pass_list
, *prev_pass
= NULL
;
1097 bool success
= false;
1099 for ( ; pass
; prev_pass
= pass
, pass
= pass
->next
)
1101 /* Check if the current pass is of the same type as the new pass and
1102 matches the name and the instance number of the reference pass. */
1103 if (pass
->type
== new_pass_info
->pass
->type
1105 && !strcmp (pass
->name
, new_pass_info
->reference_pass_name
)
1106 && ((new_pass_info
->ref_pass_instance_number
== 0)
1107 || (new_pass_info
->ref_pass_instance_number
==
1108 pass
->static_pass_number
)
1109 || (new_pass_info
->ref_pass_instance_number
== 1
1110 && pass
->todo_flags_start
& TODO_mark_first_instance
)))
1112 struct opt_pass
*new_pass
;
1113 struct pass_list_node
*new_pass_node
;
1115 new_pass
= make_pass_instance (new_pass_info
->pass
, true);
1117 /* Insert the new pass instance based on the positioning op. */
1118 switch (new_pass_info
->pos_op
)
1120 case PASS_POS_INSERT_AFTER
:
1121 new_pass
->next
= pass
->next
;
1122 pass
->next
= new_pass
;
1124 /* Skip newly inserted pass to avoid repeated
1125 insertions in the case where the new pass and the
1126 existing one have the same name. */
1129 case PASS_POS_INSERT_BEFORE
:
1130 new_pass
->next
= pass
;
1132 prev_pass
->next
= new_pass
;
1134 *pass_list
= new_pass
;
1136 case PASS_POS_REPLACE
:
1137 new_pass
->next
= pass
->next
;
1139 prev_pass
->next
= new_pass
;
1141 *pass_list
= new_pass
;
1142 new_pass
->sub
= pass
->sub
;
1143 new_pass
->tv_id
= pass
->tv_id
;
1147 error ("invalid pass positioning operation");
1151 /* Save the newly added pass (instance) in the added_pass_nodes
1152 list so that we can register its dump file later. Note that
1153 we cannot register the dump file now because doing so will modify
1154 the static_pass_number of the opt_pass object and therefore
1155 mess up the dump file name of future instances. */
1156 new_pass_node
= XCNEW (struct pass_list_node
);
1157 new_pass_node
->pass
= new_pass
;
1158 if (!added_pass_nodes
)
1159 added_pass_nodes
= new_pass_node
;
1161 prev_added_pass_node
->next
= new_pass_node
;
1162 prev_added_pass_node
= new_pass_node
;
1167 if (pass
->sub
&& position_pass (new_pass_info
, &pass
->sub
))
1174 /* Hooks a new pass into the pass lists.
1176 PASS_INFO - pass information that specifies the opt_pass object,
1177 reference pass, instance number, and how to position
1181 register_pass (struct register_pass_info
*pass_info
)
1183 bool all_instances
, success
;
1185 /* The checks below could fail in buggy plugins. Existing GCC
1186 passes should never fail these checks, so we mention plugin in
1188 if (!pass_info
->pass
)
1189 fatal_error ("plugin cannot register a missing pass");
1191 if (!pass_info
->pass
->name
)
1192 fatal_error ("plugin cannot register an unnamed pass");
1194 if (!pass_info
->reference_pass_name
)
1196 ("plugin cannot register pass %qs without reference pass name",
1197 pass_info
->pass
->name
);
1199 /* Try to insert the new pass to the pass lists. We need to check
1200 all five lists as the reference pass could be in one (or all) of
1202 all_instances
= pass_info
->ref_pass_instance_number
== 0;
1203 success
= position_pass (pass_info
, &all_lowering_passes
);
1204 if (!success
|| all_instances
)
1205 success
|= position_pass (pass_info
, &all_small_ipa_passes
);
1206 if (!success
|| all_instances
)
1207 success
|= position_pass (pass_info
, &all_regular_ipa_passes
);
1208 if (!success
|| all_instances
)
1209 success
|= position_pass (pass_info
, &all_lto_gen_passes
);
1210 if (!success
|| all_instances
)
1211 success
|= position_pass (pass_info
, &all_late_ipa_passes
);
1212 if (!success
|| all_instances
)
1213 success
|= position_pass (pass_info
, &all_passes
);
1216 ("pass %qs not found but is referenced by new pass %qs",
1217 pass_info
->reference_pass_name
, pass_info
->pass
->name
);
1219 /* OK, we have successfully inserted the new pass. We need to register
1220 the dump files for the newly added pass and its duplicates (if any).
1221 Because the registration of plugin/backend passes happens after the
1222 command-line options are parsed, the options that specify single
1223 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1224 passes. Therefore we currently can only enable dumping of
1225 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1226 are specified. While doing so, we also delete the pass_list_node
1227 objects created during pass positioning. */
1228 while (added_pass_nodes
)
1230 struct pass_list_node
*next_node
= added_pass_nodes
->next
;
1231 enum tree_dump_index tdi
;
1232 register_one_dump_file (added_pass_nodes
->pass
);
1233 if (added_pass_nodes
->pass
->type
== SIMPLE_IPA_PASS
1234 || added_pass_nodes
->pass
->type
== IPA_PASS
)
1236 else if (added_pass_nodes
->pass
->type
== GIMPLE_PASS
)
1240 /* Check if dump-all flag is specified. */
1241 if (get_dump_file_info (tdi
)->state
)
1242 get_dump_file_info (added_pass_nodes
->pass
->static_pass_number
)
1243 ->state
= get_dump_file_info (tdi
)->state
;
1244 XDELETE (added_pass_nodes
);
1245 added_pass_nodes
= next_node
;
1249 /* Construct the pass tree. The sequencing of passes is driven by
1250 the cgraph routines:
1252 finalize_compilation_unit ()
1253 for each node N in the cgraph
1254 cgraph_analyze_function (N)
1255 cgraph_lower_function (N) -> all_lowering_passes
1257 If we are optimizing, compile is then invoked:
1260 ipa_passes () -> all_small_ipa_passes
1261 -> Analysis of all_regular_ipa_passes
1262 * possible LTO streaming at copmilation time *
1263 -> Execution of all_regular_ipa_passes
1264 * possible LTO streaming at link time *
1265 -> all_late_ipa_passes
1266 expand_all_functions ()
1267 for each node N in the cgraph
1268 expand_function (N) -> Transformation of all_regular_ipa_passes
1273 init_optimization_passes (void)
1275 struct opt_pass
**p
;
1277 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
1279 /* All passes needed to lower the function into shape optimizers can
1280 operate on. These passes are always run first on the function, but
1281 backend might produce already lowered functions that are not processed
1283 p
= &all_lowering_passes
;
1284 NEXT_PASS (pass_warn_unused_result
);
1285 NEXT_PASS (pass_diagnose_omp_blocks
);
1286 NEXT_PASS (pass_diagnose_tm_blocks
);
1287 NEXT_PASS (pass_mudflap_1
);
1288 NEXT_PASS (pass_lower_omp
);
1289 NEXT_PASS (pass_lower_cf
);
1290 NEXT_PASS (pass_lower_tm
);
1291 NEXT_PASS (pass_refactor_eh
);
1292 NEXT_PASS (pass_lower_eh
);
1293 NEXT_PASS (pass_build_cfg
);
1294 NEXT_PASS (pass_warn_function_return
);
1295 NEXT_PASS (pass_build_cgraph_edges
);
1298 /* Interprocedural optimization passes. */
1299 p
= &all_small_ipa_passes
;
1300 NEXT_PASS (pass_ipa_free_lang_data
);
1301 NEXT_PASS (pass_ipa_function_and_variable_visibility
);
1302 NEXT_PASS (pass_early_local_passes
);
1304 struct opt_pass
**p
= &pass_early_local_passes
.pass
.sub
;
1305 NEXT_PASS (pass_fixup_cfg
);
1306 NEXT_PASS (pass_init_datastructures
);
1307 NEXT_PASS (pass_expand_omp
);
1309 NEXT_PASS (pass_referenced_vars
);
1310 NEXT_PASS (pass_build_ssa
);
1311 NEXT_PASS (pass_lower_vector
);
1312 NEXT_PASS (pass_early_warn_uninitialized
);
1313 NEXT_PASS (pass_rebuild_cgraph_edges
);
1314 NEXT_PASS (pass_inline_parameters
);
1315 NEXT_PASS (pass_early_inline
);
1316 NEXT_PASS (pass_all_early_optimizations
);
1318 struct opt_pass
**p
= &pass_all_early_optimizations
.pass
.sub
;
1319 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1320 NEXT_PASS (pass_rename_ssa_copies
);
1321 NEXT_PASS (pass_ccp
);
1322 NEXT_PASS (pass_forwprop
);
1323 /* pass_build_ealias is a dummy pass that ensures that we
1324 execute TODO_rebuild_alias at this point. Re-building
1325 alias information also rewrites no longer addressed
1326 locals into SSA form if possible. */
1327 NEXT_PASS (pass_build_ealias
);
1328 NEXT_PASS (pass_sra_early
);
1329 NEXT_PASS (pass_fre
);
1330 NEXT_PASS (pass_copy_prop
);
1331 NEXT_PASS (pass_merge_phi
);
1332 NEXT_PASS (pass_cd_dce
);
1333 NEXT_PASS (pass_early_ipa_sra
);
1334 NEXT_PASS (pass_tail_recursion
);
1335 NEXT_PASS (pass_convert_switch
);
1336 NEXT_PASS (pass_cleanup_eh
);
1337 NEXT_PASS (pass_profile
);
1338 NEXT_PASS (pass_local_pure_const
);
1339 /* Split functions creates parts that are not run through
1340 early optimizations again. It is thus good idea to do this
1342 NEXT_PASS (pass_split_functions
);
1344 NEXT_PASS (pass_release_ssa_names
);
1345 NEXT_PASS (pass_rebuild_cgraph_edges
);
1346 NEXT_PASS (pass_inline_parameters
);
1348 NEXT_PASS (pass_ipa_tree_profile
);
1350 struct opt_pass
**p
= &pass_ipa_tree_profile
.pass
.sub
;
1351 NEXT_PASS (pass_feedback_split_functions
);
1353 NEXT_PASS (pass_ipa_increase_alignment
);
1354 NEXT_PASS (pass_ipa_matrix_reorg
);
1355 NEXT_PASS (pass_ipa_tm
);
1356 NEXT_PASS (pass_ipa_lower_emutls
);
1359 p
= &all_regular_ipa_passes
;
1360 NEXT_PASS (pass_ipa_whole_program_visibility
);
1361 NEXT_PASS (pass_ipa_profile
);
1362 NEXT_PASS (pass_ipa_cp
);
1363 NEXT_PASS (pass_ipa_cdtor_merge
);
1364 NEXT_PASS (pass_ipa_inline
);
1365 NEXT_PASS (pass_ipa_pure_const
);
1366 NEXT_PASS (pass_ipa_reference
);
1369 p
= &all_lto_gen_passes
;
1370 NEXT_PASS (pass_ipa_lto_gimple_out
);
1371 NEXT_PASS (pass_ipa_lto_finish_out
); /* This must be the last LTO pass. */
1374 /* Simple IPA passes executed after the regular passes. In WHOPR mode the
1375 passes are executed after partitioning and thus see just parts of the
1377 p
= &all_late_ipa_passes
;
1378 NEXT_PASS (pass_ipa_pta
);
1381 /* These passes are run after IPA passes on every function that is being
1382 output to the assembler file. */
1384 NEXT_PASS (pass_fixup_cfg
);
1385 NEXT_PASS (pass_lower_eh_dispatch
);
1386 NEXT_PASS (pass_all_optimizations
);
1388 struct opt_pass
**p
= &pass_all_optimizations
.pass
.sub
;
1389 NEXT_PASS (pass_remove_cgraph_callee_edges
);
1390 /* Initial scalar cleanups before alias computation.
1391 They ensure memory accesses are not indirect wherever possible. */
1392 NEXT_PASS (pass_strip_predict_hints
);
1393 NEXT_PASS (pass_rename_ssa_copies
);
1394 NEXT_PASS (pass_complete_unrolli
);
1395 NEXT_PASS (pass_ccp
);
1396 NEXT_PASS (pass_forwprop
);
1397 NEXT_PASS (pass_call_cdce
);
1398 /* pass_build_alias is a dummy pass that ensures that we
1399 execute TODO_rebuild_alias at this point. Re-building
1400 alias information also rewrites no longer addressed
1401 locals into SSA form if possible. */
1402 NEXT_PASS (pass_build_alias
);
1403 NEXT_PASS (pass_return_slot
);
1404 NEXT_PASS (pass_phiprop
);
1405 NEXT_PASS (pass_fre
);
1406 NEXT_PASS (pass_copy_prop
);
1407 NEXT_PASS (pass_merge_phi
);
1408 NEXT_PASS (pass_vrp
);
1409 NEXT_PASS (pass_dce
);
1410 NEXT_PASS (pass_cselim
);
1411 NEXT_PASS (pass_tree_ifcombine
);
1412 NEXT_PASS (pass_phiopt
);
1413 NEXT_PASS (pass_tail_recursion
);
1414 NEXT_PASS (pass_ch
);
1415 NEXT_PASS (pass_stdarg
);
1416 NEXT_PASS (pass_lower_complex
);
1417 NEXT_PASS (pass_sra
);
1418 NEXT_PASS (pass_rename_ssa_copies
);
1419 /* The dom pass will also resolve all __builtin_constant_p calls
1420 that are still there to 0. This has to be done after some
1421 propagations have already run, but before some more dead code
1422 is removed, and this place fits nicely. Remember this when
1423 trying to move or duplicate pass_dominator somewhere earlier. */
1424 NEXT_PASS (pass_dominator
);
1425 /* The only const/copy propagation opportunities left after
1426 DOM should be due to degenerate PHI nodes. So rather than
1427 run the full propagators, run a specialized pass which
1428 only examines PHIs to discover const/copy propagation
1430 NEXT_PASS (pass_phi_only_cprop
);
1431 NEXT_PASS (pass_dse
);
1432 NEXT_PASS (pass_reassoc
);
1433 NEXT_PASS (pass_dce
);
1434 NEXT_PASS (pass_forwprop
);
1435 NEXT_PASS (pass_phiopt
);
1436 NEXT_PASS (pass_object_sizes
);
1437 NEXT_PASS (pass_strlen
);
1438 NEXT_PASS (pass_ccp
);
1439 NEXT_PASS (pass_copy_prop
);
1440 NEXT_PASS (pass_cse_sincos
);
1441 NEXT_PASS (pass_optimize_bswap
);
1442 NEXT_PASS (pass_split_crit_edges
);
1443 NEXT_PASS (pass_pre
);
1444 NEXT_PASS (pass_sink_code
);
1445 NEXT_PASS (pass_tree_loop
);
1447 struct opt_pass
**p
= &pass_tree_loop
.pass
.sub
;
1448 NEXT_PASS (pass_tree_loop_init
);
1449 NEXT_PASS (pass_lim
);
1450 NEXT_PASS (pass_copy_prop
);
1451 NEXT_PASS (pass_dce_loop
);
1452 NEXT_PASS (pass_tree_unswitch
);
1453 NEXT_PASS (pass_scev_cprop
);
1454 NEXT_PASS (pass_record_bounds
);
1455 NEXT_PASS (pass_check_data_deps
);
1456 NEXT_PASS (pass_loop_distribution
);
1457 NEXT_PASS (pass_copy_prop
);
1458 NEXT_PASS (pass_graphite
);
1460 struct opt_pass
**p
= &pass_graphite
.pass
.sub
;
1461 NEXT_PASS (pass_graphite_transforms
);
1462 NEXT_PASS (pass_lim
);
1463 NEXT_PASS (pass_copy_prop
);
1464 NEXT_PASS (pass_dce_loop
);
1466 NEXT_PASS (pass_iv_canon
);
1467 NEXT_PASS (pass_if_conversion
);
1468 NEXT_PASS (pass_vectorize
);
1470 struct opt_pass
**p
= &pass_vectorize
.pass
.sub
;
1471 NEXT_PASS (pass_dce_loop
);
1473 NEXT_PASS (pass_predcom
);
1474 NEXT_PASS (pass_complete_unroll
);
1475 NEXT_PASS (pass_slp_vectorize
);
1476 NEXT_PASS (pass_parallelize_loops
);
1477 NEXT_PASS (pass_loop_prefetch
);
1478 NEXT_PASS (pass_iv_optimize
);
1479 NEXT_PASS (pass_lim
);
1480 NEXT_PASS (pass_tree_loop_done
);
1482 NEXT_PASS (pass_lower_vector_ssa
);
1483 NEXT_PASS (pass_cse_reciprocals
);
1484 NEXT_PASS (pass_reassoc
);
1485 NEXT_PASS (pass_vrp
);
1486 NEXT_PASS (pass_dominator
);
1487 /* The only const/copy propagation opportunities left after
1488 DOM should be due to degenerate PHI nodes. So rather than
1489 run the full propagators, run a specialized pass which
1490 only examines PHIs to discover const/copy propagation
1492 NEXT_PASS (pass_phi_only_cprop
);
1493 NEXT_PASS (pass_cd_dce
);
1494 NEXT_PASS (pass_tracer
);
1496 /* FIXME: If DCE is not run before checking for uninitialized uses,
1497 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
1498 However, this also causes us to misdiagnose cases that should be
1499 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
1501 To fix the false positives in uninit-5.c, we would have to
1502 account for the predicates protecting the set and the use of each
1503 variable. Using a representation like Gated Single Assignment
1505 NEXT_PASS (pass_late_warn_uninitialized
);
1506 NEXT_PASS (pass_dse
);
1507 NEXT_PASS (pass_forwprop
);
1508 NEXT_PASS (pass_phiopt
);
1509 NEXT_PASS (pass_fold_builtins
);
1510 NEXT_PASS (pass_optimize_widening_mul
);
1511 NEXT_PASS (pass_tail_calls
);
1512 NEXT_PASS (pass_rename_ssa_copies
);
1513 NEXT_PASS (pass_uncprop
);
1514 NEXT_PASS (pass_local_pure_const
);
1516 NEXT_PASS (pass_tm_init
);
1518 struct opt_pass
**p
= &pass_tm_init
.pass
.sub
;
1519 NEXT_PASS (pass_tm_mark
);
1520 NEXT_PASS (pass_tm_memopt
);
1521 NEXT_PASS (pass_tm_edges
);
1523 NEXT_PASS (pass_lower_complex_O0
);
1524 NEXT_PASS (pass_cleanup_eh
);
1525 NEXT_PASS (pass_lower_resx
);
1526 NEXT_PASS (pass_nrv
);
1527 NEXT_PASS (pass_mudflap_2
);
1528 NEXT_PASS (pass_cleanup_cfg_post_optimizing
);
1529 NEXT_PASS (pass_warn_function_noreturn
);
1531 NEXT_PASS (pass_expand
);
1533 NEXT_PASS (pass_rest_of_compilation
);
1535 struct opt_pass
**p
= &pass_rest_of_compilation
.pass
.sub
;
1536 NEXT_PASS (pass_instantiate_virtual_regs
);
1537 NEXT_PASS (pass_into_cfg_layout_mode
);
1538 NEXT_PASS (pass_jump2
);
1539 NEXT_PASS (pass_lower_subreg
);
1540 NEXT_PASS (pass_df_initialize_opt
);
1541 NEXT_PASS (pass_cse
);
1542 NEXT_PASS (pass_rtl_fwprop
);
1543 NEXT_PASS (pass_rtl_cprop
);
1544 NEXT_PASS (pass_rtl_pre
);
1545 NEXT_PASS (pass_rtl_hoist
);
1546 NEXT_PASS (pass_rtl_cprop
);
1547 NEXT_PASS (pass_rtl_store_motion
);
1548 NEXT_PASS (pass_cse_after_global_opts
);
1549 NEXT_PASS (pass_rtl_ifcvt
);
1550 NEXT_PASS (pass_reginfo_init
);
1551 /* Perform loop optimizations. It might be better to do them a bit
1552 sooner, but we want the profile feedback to work more
1554 NEXT_PASS (pass_loop2
);
1556 struct opt_pass
**p
= &pass_loop2
.pass
.sub
;
1557 NEXT_PASS (pass_rtl_loop_init
);
1558 NEXT_PASS (pass_rtl_move_loop_invariants
);
1559 NEXT_PASS (pass_rtl_unswitch
);
1560 NEXT_PASS (pass_rtl_unroll_and_peel_loops
);
1561 NEXT_PASS (pass_rtl_doloop
);
1562 NEXT_PASS (pass_rtl_loop_done
);
1565 NEXT_PASS (pass_web
);
1566 NEXT_PASS (pass_rtl_cprop
);
1567 NEXT_PASS (pass_cse2
);
1568 NEXT_PASS (pass_rtl_dse1
);
1569 NEXT_PASS (pass_rtl_fwprop_addr
);
1570 NEXT_PASS (pass_inc_dec
);
1571 NEXT_PASS (pass_initialize_regs
);
1572 NEXT_PASS (pass_ud_rtl_dce
);
1573 NEXT_PASS (pass_combine
);
1574 NEXT_PASS (pass_if_after_combine
);
1575 NEXT_PASS (pass_partition_blocks
);
1576 NEXT_PASS (pass_regmove
);
1577 NEXT_PASS (pass_outof_cfg_layout_mode
);
1578 NEXT_PASS (pass_split_all_insns
);
1579 NEXT_PASS (pass_lower_subreg2
);
1580 NEXT_PASS (pass_df_initialize_no_opt
);
1581 NEXT_PASS (pass_stack_ptr_mod
);
1582 NEXT_PASS (pass_mode_switching
);
1583 NEXT_PASS (pass_match_asm_constraints
);
1584 NEXT_PASS (pass_sms
);
1585 NEXT_PASS (pass_sched
);
1586 NEXT_PASS (pass_ira
);
1587 NEXT_PASS (pass_reload
);
1588 NEXT_PASS (pass_postreload
);
1590 struct opt_pass
**p
= &pass_postreload
.pass
.sub
;
1591 NEXT_PASS (pass_postreload_cse
);
1592 NEXT_PASS (pass_gcse2
);
1593 NEXT_PASS (pass_split_after_reload
);
1594 NEXT_PASS (pass_ree
);
1595 NEXT_PASS (pass_compare_elim_after_reload
);
1596 NEXT_PASS (pass_branch_target_load_optimize1
);
1597 NEXT_PASS (pass_thread_prologue_and_epilogue
);
1598 NEXT_PASS (pass_rtl_dse2
);
1599 NEXT_PASS (pass_stack_adjustments
);
1600 NEXT_PASS (pass_peephole2
);
1601 NEXT_PASS (pass_if_after_reload
);
1602 NEXT_PASS (pass_regrename
);
1603 NEXT_PASS (pass_cprop_hardreg
);
1604 NEXT_PASS (pass_fast_rtl_dce
);
1605 NEXT_PASS (pass_reorder_blocks
);
1606 NEXT_PASS (pass_branch_target_load_optimize2
);
1607 NEXT_PASS (pass_leaf_regs
);
1608 NEXT_PASS (pass_split_before_sched2
);
1609 NEXT_PASS (pass_sched2
);
1610 NEXT_PASS (pass_stack_regs
);
1612 struct opt_pass
**p
= &pass_stack_regs
.pass
.sub
;
1613 NEXT_PASS (pass_split_before_regstack
);
1614 NEXT_PASS (pass_stack_regs_run
);
1616 NEXT_PASS (pass_compute_alignments
);
1617 NEXT_PASS (pass_duplicate_computed_gotos
);
1618 NEXT_PASS (pass_variable_tracking
);
1619 NEXT_PASS (pass_free_cfg
);
1620 NEXT_PASS (pass_machine_reorg
);
1621 NEXT_PASS (pass_cleanup_barriers
);
1622 NEXT_PASS (pass_delay_slots
);
1623 NEXT_PASS (pass_split_for_shorten_branches
);
1624 NEXT_PASS (pass_convert_to_eh_region_ranges
);
1625 NEXT_PASS (pass_shorten_branches
);
1626 NEXT_PASS (pass_set_nothrow_function_flags
);
1627 NEXT_PASS (pass_dwarf2_frame
);
1628 NEXT_PASS (pass_final
);
1630 NEXT_PASS (pass_df_finish
);
1632 NEXT_PASS (pass_clean_state
);
1637 /* Register the passes with the tree dump code. */
1638 register_dump_files (all_lowering_passes
, PROP_gimple_any
);
1639 register_dump_files (all_small_ipa_passes
,
1640 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1642 register_dump_files (all_regular_ipa_passes
,
1643 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1645 register_dump_files (all_lto_gen_passes
,
1646 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1648 register_dump_files (all_late_ipa_passes
,
1649 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1651 register_dump_files (all_passes
,
1652 PROP_gimple_any
| PROP_gimple_lcf
| PROP_gimple_leh
1656 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1657 function CALLBACK for every function in the call graph. Otherwise,
1658 call CALLBACK on the current function. */
1661 do_per_function (void (*callback
) (void *data
), void *data
)
1663 if (current_function_decl
)
1667 struct cgraph_node
*node
;
1668 FOR_EACH_DEFINED_FUNCTION (node
)
1669 if (gimple_has_body_p (node
->symbol
.decl
)
1670 && (!node
->clone_of
|| node
->symbol
.decl
!= node
->clone_of
->symbol
.decl
))
1672 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1673 current_function_decl
= node
->symbol
.decl
;
1677 free_dominance_info (CDI_DOMINATORS
);
1678 free_dominance_info (CDI_POST_DOMINATORS
);
1680 current_function_decl
= NULL
;
1687 /* Because inlining might remove no-longer reachable nodes, we need to
1688 keep the array visible to garbage collector to avoid reading collected
1691 static GTY ((length ("nnodes"))) cgraph_node_ptr
*order
;
1693 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1694 function CALLBACK for every function in the call graph. Otherwise,
1695 call CALLBACK on the current function.
1696 This function is global so that plugins can use it. */
1698 do_per_function_toporder (void (*callback
) (void *data
), void *data
)
1702 if (current_function_decl
)
1706 gcc_assert (!order
);
1707 order
= ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes
);
1708 nnodes
= ipa_reverse_postorder (order
);
1709 for (i
= nnodes
- 1; i
>= 0; i
--)
1710 order
[i
]->process
= 1;
1711 for (i
= nnodes
- 1; i
>= 0; i
--)
1713 struct cgraph_node
*node
= order
[i
];
1715 /* Allow possibly removed nodes to be garbage collected. */
1718 if (cgraph_function_with_gimple_body_p (node
))
1720 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1721 current_function_decl
= node
->symbol
.decl
;
1723 free_dominance_info (CDI_DOMINATORS
);
1724 free_dominance_info (CDI_POST_DOMINATORS
);
1725 current_function_decl
= NULL
;
1736 /* Helper function to perform function body dump. */
1739 execute_function_dump (void *data ATTRIBUTE_UNUSED
)
1741 if (dump_file
&& current_function_decl
)
1743 if (cfun
->curr_properties
& PROP_trees
)
1744 dump_function_to_file (current_function_decl
, dump_file
, dump_flags
);
1747 if (dump_flags
& TDF_SLIM
)
1748 print_rtl_slim_with_bb (dump_file
, get_insns (), dump_flags
);
1749 else if ((cfun
->curr_properties
& PROP_cfg
)
1750 && (dump_flags
& TDF_BLOCKS
))
1751 print_rtl_with_bb (dump_file
, get_insns ());
1753 print_rtl (dump_file
, get_insns ());
1755 if ((cfun
->curr_properties
& PROP_cfg
)
1756 && graph_dump_format
!= no_graph
1757 && (dump_flags
& TDF_GRAPH
))
1758 print_rtl_graph_with_bb (dump_file_name
, get_insns ());
1761 /* Flush the file. If verification fails, we won't be able to
1762 close the file before aborting. */
1767 /* Perform all TODO actions that ought to be done on each function. */
1770 execute_function_todo (void *data
)
1772 unsigned int flags
= (size_t)data
;
1773 flags
&= ~cfun
->last_verified
;
1777 /* Always cleanup the CFG before trying to update SSA. */
1778 if (flags
& TODO_cleanup_cfg
)
1780 bool cleanup
= cleanup_tree_cfg ();
1782 if (cleanup
&& (cfun
->curr_properties
& PROP_ssa
))
1783 flags
|= TODO_remove_unused_locals
;
1785 /* When cleanup_tree_cfg merges consecutive blocks, it may
1786 perform some simplistic propagation when removing single
1787 valued PHI nodes. This propagation may, in turn, cause the
1788 SSA form to become out-of-date (see PR 22037). So, even
1789 if the parent pass had not scheduled an SSA update, we may
1790 still need to do one. */
1791 if (!(flags
& TODO_update_ssa_any
) && need_ssa_update_p (cfun
))
1792 flags
|= TODO_update_ssa
;
1795 if (flags
& TODO_update_ssa_any
)
1797 unsigned update_flags
= flags
& TODO_update_ssa_any
;
1798 update_ssa (update_flags
);
1799 cfun
->last_verified
&= ~TODO_verify_ssa
;
1802 if (flags
& TODO_rebuild_alias
)
1804 execute_update_addresses_taken ();
1805 compute_may_aliases ();
1807 else if (optimize
&& (flags
& TODO_update_address_taken
))
1808 execute_update_addresses_taken ();
1810 if (flags
& TODO_remove_unused_locals
)
1811 remove_unused_locals ();
1813 if (flags
& TODO_rebuild_frequencies
)
1814 rebuild_frequencies ();
1816 if (flags
& TODO_rebuild_cgraph_edges
)
1817 rebuild_cgraph_edges ();
1819 /* If we've seen errors do not bother running any verifiers. */
1823 #if defined ENABLE_CHECKING
1824 if (flags
& TODO_verify_ssa
1825 || (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
)))
1827 verify_gimple_in_cfg (cfun
);
1830 else if (flags
& TODO_verify_stmts
)
1831 verify_gimple_in_cfg (cfun
);
1832 if (flags
& TODO_verify_flow
)
1833 verify_flow_info ();
1834 if (current_loops
&& loops_state_satisfies_p (LOOP_CLOSED_SSA
))
1835 verify_loop_closed_ssa (false);
1836 if (flags
& TODO_verify_rtl_sharing
)
1837 verify_rtl_sharing ();
1840 cfun
->last_verified
= flags
& TODO_verify_all
;
1843 /* Perform all TODO actions. */
1845 execute_todo (unsigned int flags
)
1847 #if defined ENABLE_CHECKING
1849 && need_ssa_update_p (cfun
))
1850 gcc_assert (flags
& TODO_update_ssa_any
);
1853 timevar_push (TV_TODO
);
1855 /* Inform the pass whether it is the first time it is run. */
1856 first_pass_instance
= (flags
& TODO_mark_first_instance
) != 0;
1858 statistics_fini_pass ();
1860 do_per_function (execute_function_todo
, (void *)(size_t) flags
);
1862 /* Always remove functions just as before inlining: IPA passes might be
1863 interested to see bodies of extern inline functions that are not inlined
1864 to analyze side effects. The full removal is done just at the end
1865 of IPA pass queue. */
1866 if (flags
& TODO_remove_functions
)
1869 symtab_remove_unreachable_nodes (true, dump_file
);
1872 if ((flags
& TODO_dump_symtab
) && dump_file
&& !current_function_decl
)
1875 dump_symtab (dump_file
);
1876 /* Flush the file. If verification fails, we won't be able to
1877 close the file before aborting. */
1881 if (flags
& TODO_ggc_collect
)
1884 /* Now that the dumping has been done, we can get rid of the optional
1886 if (flags
& TODO_df_finish
)
1887 df_finish_pass ((flags
& TODO_df_verify
) != 0);
1889 timevar_pop (TV_TODO
);
1892 /* Verify invariants that should hold between passes. This is a place
1893 to put simple sanity checks. */
1896 verify_interpass_invariants (void)
1898 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1901 /* Clear the last verified flag. */
1904 clear_last_verified (void *data ATTRIBUTE_UNUSED
)
1906 cfun
->last_verified
= 0;
1909 /* Helper function. Verify that the properties has been turn into the
1910 properties expected by the pass. */
1912 #ifdef ENABLE_CHECKING
1914 verify_curr_properties (void *data
)
1916 unsigned int props
= (size_t)data
;
1917 gcc_assert ((cfun
->curr_properties
& props
) == props
);
1921 /* Initialize pass dump file. */
1922 /* This is non-static so that the plugins can use it. */
1925 pass_init_dump_file (struct opt_pass
*pass
)
1927 /* If a dump file name is present, open it if enabled. */
1928 if (pass
->static_pass_number
!= -1)
1930 bool initializing_dump
= !dump_initialized_p (pass
->static_pass_number
);
1931 dump_file_name
= get_dump_file_name (pass
->static_pass_number
);
1932 dump_file
= dump_begin (pass
->static_pass_number
, &dump_flags
);
1933 if (dump_file
&& current_function_decl
)
1934 dump_function_header (dump_file
, current_function_decl
, dump_flags
);
1935 return initializing_dump
;
1941 /* Flush PASS dump file. */
1942 /* This is non-static so that plugins can use it. */
1945 pass_fini_dump_file (struct opt_pass
*pass
)
1947 /* Flush and close dump file. */
1950 free (CONST_CAST (char *, dump_file_name
));
1951 dump_file_name
= NULL
;
1956 dump_end (pass
->static_pass_number
, dump_file
);
1961 /* After executing the pass, apply expected changes to the function
1965 update_properties_after_pass (void *data
)
1967 struct opt_pass
*pass
= (struct opt_pass
*) data
;
1968 cfun
->curr_properties
= (cfun
->curr_properties
| pass
->properties_provided
)
1969 & ~pass
->properties_destroyed
;
1972 /* Execute summary generation for all of the passes in IPA_PASS. */
1975 execute_ipa_summary_passes (struct ipa_opt_pass_d
*ipa_pass
)
1979 struct opt_pass
*pass
= &ipa_pass
->pass
;
1981 /* Execute all of the IPA_PASSes in the list. */
1982 if (ipa_pass
->pass
.type
== IPA_PASS
1983 && (!pass
->gate
|| pass
->gate ())
1984 && ipa_pass
->generate_summary
)
1986 pass_init_dump_file (pass
);
1988 /* If a timevar is present, start it. */
1990 timevar_push (pass
->tv_id
);
1992 ipa_pass
->generate_summary ();
1996 timevar_pop (pass
->tv_id
);
1998 pass_fini_dump_file (pass
);
2000 ipa_pass
= (struct ipa_opt_pass_d
*)ipa_pass
->pass
.next
;
2004 /* Execute IPA_PASS function transform on NODE. */
2007 execute_one_ipa_transform_pass (struct cgraph_node
*node
,
2008 struct ipa_opt_pass_d
*ipa_pass
)
2010 struct opt_pass
*pass
= &ipa_pass
->pass
;
2011 unsigned int todo_after
= 0;
2013 current_pass
= pass
;
2014 if (!ipa_pass
->function_transform
)
2017 /* Note that the folders should only create gimple expressions.
2018 This is a hack until the new folder is ready. */
2019 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2021 pass_init_dump_file (pass
);
2023 /* Run pre-pass verification. */
2024 execute_todo (ipa_pass
->function_transform_todo_flags_start
);
2026 /* If a timevar is present, start it. */
2027 if (pass
->tv_id
!= TV_NONE
)
2028 timevar_push (pass
->tv_id
);
2031 todo_after
= ipa_pass
->function_transform (node
);
2034 if (pass
->tv_id
!= TV_NONE
)
2035 timevar_pop (pass
->tv_id
);
2037 /* Run post-pass cleanup and verification. */
2038 execute_todo (todo_after
);
2039 verify_interpass_invariants ();
2041 do_per_function (execute_function_dump
, NULL
);
2042 pass_fini_dump_file (pass
);
2044 current_pass
= NULL
;
2047 /* For the current function, execute all ipa transforms. */
2050 execute_all_ipa_transforms (void)
2052 struct cgraph_node
*node
;
2055 node
= cgraph_get_node (current_function_decl
);
2057 if (node
->ipa_transforms_to_apply
)
2061 for (i
= 0; i
< VEC_length (ipa_opt_pass
, node
->ipa_transforms_to_apply
);
2063 execute_one_ipa_transform_pass (node
,
2064 VEC_index (ipa_opt_pass
,
2065 node
->ipa_transforms_to_apply
,
2067 VEC_free (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
);
2068 node
->ipa_transforms_to_apply
= NULL
;
2072 /* Callback for do_per_function to apply all IPA transforms. */
2075 apply_ipa_transforms (void *data
)
2077 struct cgraph_node
*node
= cgraph_get_node (current_function_decl
);
2078 if (!node
->global
.inlined_to
&& node
->ipa_transforms_to_apply
)
2080 *(bool *)data
= true;
2081 execute_all_ipa_transforms();
2082 rebuild_cgraph_edges ();
2086 /* Check if PASS is explicitly disabled or enabled and return
2087 the gate status. FUNC is the function to be processed, and
2088 GATE_STATUS is the gate status determined by pass manager by
2092 override_gate_status (struct opt_pass
*pass
, tree func
, bool gate_status
)
2094 bool explicitly_enabled
= false;
2095 bool explicitly_disabled
= false;
2098 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2099 enabled_pass_uid_range_tab
);
2101 = is_pass_explicitly_enabled_or_disabled (pass
, func
,
2102 disabled_pass_uid_range_tab
);
2104 gate_status
= !explicitly_disabled
&& (gate_status
|| explicitly_enabled
);
2113 execute_one_pass (struct opt_pass
*pass
)
2115 bool initializing_dump
;
2116 unsigned int todo_after
= 0;
2120 /* IPA passes are executed on whole program, so cfun should be NULL.
2121 Other passes need function context set. */
2122 if (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
)
2123 gcc_assert (!cfun
&& !current_function_decl
);
2125 gcc_assert (cfun
&& current_function_decl
);
2127 current_pass
= pass
;
2129 /* Check whether gate check should be avoided.
2130 User controls the value of the gate through the parameter "gate_status". */
2131 gate_status
= (pass
->gate
== NULL
) ? true : pass
->gate();
2132 gate_status
= override_gate_status (pass
, current_function_decl
, gate_status
);
2134 /* Override gate with plugin. */
2135 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE
, &gate_status
);
2139 current_pass
= NULL
;
2143 /* Pass execution event trigger: useful to identify passes being
2145 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION
, pass
);
2147 /* SIPLE IPA passes do not handle callgraphs with IPA transforms in it.
2148 Apply all trnasforms first. */
2149 if (pass
->type
== SIMPLE_IPA_PASS
)
2151 bool applied
= false;
2152 do_per_function (apply_ipa_transforms
, (void *)&applied
);
2154 symtab_remove_unreachable_nodes (true, dump_file
);
2155 /* Restore current_pass. */
2156 current_pass
= pass
;
2159 if (!quiet_flag
&& !cfun
)
2160 fprintf (stderr
, " <%s>", pass
->name
? pass
->name
: "");
2162 /* Note that the folders should only create gimple expressions.
2163 This is a hack until the new folder is ready. */
2164 in_gimple_form
= (cfun
&& (cfun
->curr_properties
& PROP_trees
)) != 0;
2166 initializing_dump
= pass_init_dump_file (pass
);
2168 /* Run pre-pass verification. */
2169 execute_todo (pass
->todo_flags_start
);
2171 #ifdef ENABLE_CHECKING
2172 do_per_function (verify_curr_properties
,
2173 (void *)(size_t)pass
->properties_required
);
2176 /* If a timevar is present, start it. */
2177 if (pass
->tv_id
!= TV_NONE
)
2178 timevar_push (pass
->tv_id
);
2183 todo_after
= pass
->execute ();
2184 do_per_function (clear_last_verified
, NULL
);
2188 if (pass
->tv_id
!= TV_NONE
)
2189 timevar_pop (pass
->tv_id
);
2191 do_per_function (update_properties_after_pass
, pass
);
2193 if (initializing_dump
2195 && graph_dump_format
!= no_graph
2197 && (cfun
->curr_properties
& (PROP_cfg
| PROP_rtl
))
2198 == (PROP_cfg
| PROP_rtl
))
2200 get_dump_file_info (pass
->static_pass_number
)->flags
|= TDF_GRAPH
;
2201 dump_flags
|= TDF_GRAPH
;
2202 clean_graph_dump_file (dump_file_name
);
2205 /* Run post-pass cleanup and verification. */
2206 execute_todo (todo_after
| pass
->todo_flags_finish
);
2207 verify_interpass_invariants ();
2208 do_per_function (execute_function_dump
, NULL
);
2209 if (pass
->type
== IPA_PASS
)
2211 struct cgraph_node
*node
;
2212 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node
)
2213 VEC_safe_push (ipa_opt_pass
, heap
, node
->ipa_transforms_to_apply
,
2214 (struct ipa_opt_pass_d
*)pass
);
2217 if (!current_function_decl
)
2218 cgraph_process_new_functions ();
2220 pass_fini_dump_file (pass
);
2222 if (pass
->type
!= SIMPLE_IPA_PASS
&& pass
->type
!= IPA_PASS
)
2223 gcc_assert (!(cfun
->curr_properties
& PROP_trees
)
2224 || pass
->type
!= RTL_PASS
);
2226 current_pass
= NULL
;
2232 execute_pass_list (struct opt_pass
*pass
)
2236 gcc_assert (pass
->type
== GIMPLE_PASS
2237 || pass
->type
== RTL_PASS
);
2238 if (execute_one_pass (pass
) && pass
->sub
)
2239 execute_pass_list (pass
->sub
);
2245 /* Same as execute_pass_list but assume that subpasses of IPA passes
2246 are local passes. If SET is not NULL, write out summaries of only
2247 those node in SET. */
2250 ipa_write_summaries_2 (struct opt_pass
*pass
, cgraph_node_set set
,
2251 varpool_node_set vset
,
2252 struct lto_out_decl_state
*state
)
2256 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2257 gcc_assert (!current_function_decl
);
2259 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2260 if (pass
->type
== IPA_PASS
2261 && ipa_pass
->write_summary
2262 && (!pass
->gate
|| pass
->gate ()))
2264 /* If a timevar is present, start it. */
2266 timevar_push (pass
->tv_id
);
2268 pass_init_dump_file (pass
);
2270 ipa_pass
->write_summary (set
,vset
);
2272 pass_fini_dump_file (pass
);
2274 /* If a timevar is present, start it. */
2276 timevar_pop (pass
->tv_id
);
2279 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2280 ipa_write_summaries_2 (pass
->sub
, set
, vset
, state
);
2286 /* Helper function of ipa_write_summaries. Creates and destroys the
2287 decl state and calls ipa_write_summaries_2 for all passes that have
2288 summaries. SET is the set of nodes to be written. */
2291 ipa_write_summaries_1 (cgraph_node_set set
, varpool_node_set vset
)
2293 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2294 compute_ltrans_boundary (state
, set
, vset
);
2296 lto_push_out_decl_state (state
);
2298 gcc_assert (!flag_wpa
);
2299 ipa_write_summaries_2 (all_regular_ipa_passes
, set
, vset
, state
);
2300 ipa_write_summaries_2 (all_lto_gen_passes
, set
, vset
, state
);
2302 gcc_assert (lto_get_out_decl_state () == state
);
2303 lto_pop_out_decl_state ();
2304 lto_delete_out_decl_state (state
);
2307 /* Write out summaries for all the nodes in the callgraph. */
2310 ipa_write_summaries (void)
2312 cgraph_node_set set
;
2313 varpool_node_set vset
;
2314 struct cgraph_node
**order
;
2315 struct varpool_node
*vnode
;
2318 if (!flag_generate_lto
|| seen_error ())
2321 set
= cgraph_node_set_new ();
2323 /* Create the callgraph set in the same order used in
2324 cgraph_expand_all_functions. This mostly facilitates debugging,
2325 since it causes the gimple file to be processed in the same order
2326 as the source code. */
2327 order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
2328 order_pos
= ipa_reverse_postorder (order
);
2329 gcc_assert (order_pos
== cgraph_n_nodes
);
2331 for (i
= order_pos
- 1; i
>= 0; i
--)
2333 struct cgraph_node
*node
= order
[i
];
2335 if (cgraph_function_with_gimple_body_p (node
))
2337 /* When streaming out references to statements as part of some IPA
2338 pass summary, the statements need to have uids assigned and the
2339 following does that for all the IPA passes here. Naturally, this
2340 ordering then matches the one IPA-passes get in their stmt_fixup
2343 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2344 renumber_gimple_stmt_uids ();
2348 cgraph_node_set_add (set
, node
);
2350 vset
= varpool_node_set_new ();
2352 FOR_EACH_DEFINED_VARIABLE (vnode
)
2353 if ((!vnode
->alias
|| vnode
->alias_of
))
2354 varpool_node_set_add (vset
, vnode
);
2356 ipa_write_summaries_1 (set
, vset
);
2359 free_cgraph_node_set (set
);
2360 free_varpool_node_set (vset
);
2363 /* Same as execute_pass_list but assume that subpasses of IPA passes
2364 are local passes. If SET is not NULL, write out optimization summaries of
2365 only those node in SET. */
2368 ipa_write_optimization_summaries_1 (struct opt_pass
*pass
, cgraph_node_set set
,
2369 varpool_node_set vset
,
2370 struct lto_out_decl_state
*state
)
2374 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*)pass
;
2375 gcc_assert (!current_function_decl
);
2377 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2378 if (pass
->type
== IPA_PASS
2379 && ipa_pass
->write_optimization_summary
2380 && (!pass
->gate
|| pass
->gate ()))
2382 /* If a timevar is present, start it. */
2384 timevar_push (pass
->tv_id
);
2386 pass_init_dump_file (pass
);
2388 ipa_pass
->write_optimization_summary (set
, vset
);
2390 pass_fini_dump_file (pass
);
2392 /* If a timevar is present, start it. */
2394 timevar_pop (pass
->tv_id
);
2397 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2398 ipa_write_optimization_summaries_1 (pass
->sub
, set
, vset
, state
);
2404 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
2405 NULL, write out all summaries of all nodes. */
2408 ipa_write_optimization_summaries (cgraph_node_set set
, varpool_node_set vset
)
2410 struct lto_out_decl_state
*state
= lto_new_out_decl_state ();
2411 cgraph_node_set_iterator csi
;
2412 compute_ltrans_boundary (state
, set
, vset
);
2414 lto_push_out_decl_state (state
);
2415 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
2417 struct cgraph_node
*node
= csi_node (csi
);
2418 /* When streaming out references to statements as part of some IPA
2419 pass summary, the statements need to have uids assigned.
2421 For functions newly born at WPA stage we need to initialize
2424 && gimple_has_body_p (node
->symbol
.decl
))
2426 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2427 renumber_gimple_stmt_uids ();
2432 gcc_assert (flag_wpa
);
2433 ipa_write_optimization_summaries_1 (all_regular_ipa_passes
, set
, vset
, state
);
2434 ipa_write_optimization_summaries_1 (all_lto_gen_passes
, set
, vset
, state
);
2436 gcc_assert (lto_get_out_decl_state () == state
);
2437 lto_pop_out_decl_state ();
2438 lto_delete_out_decl_state (state
);
2441 /* Same as execute_pass_list but assume that subpasses of IPA passes
2442 are local passes. */
2445 ipa_read_summaries_1 (struct opt_pass
*pass
)
2449 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2451 gcc_assert (!current_function_decl
);
2453 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2455 if (pass
->gate
== NULL
|| pass
->gate ())
2457 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_summary
)
2459 /* If a timevar is present, start it. */
2461 timevar_push (pass
->tv_id
);
2463 pass_init_dump_file (pass
);
2465 ipa_pass
->read_summary ();
2467 pass_fini_dump_file (pass
);
2471 timevar_pop (pass
->tv_id
);
2474 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2475 ipa_read_summaries_1 (pass
->sub
);
2482 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2485 ipa_read_summaries (void)
2487 ipa_read_summaries_1 (all_regular_ipa_passes
);
2488 ipa_read_summaries_1 (all_lto_gen_passes
);
2491 /* Same as execute_pass_list but assume that subpasses of IPA passes
2492 are local passes. */
2495 ipa_read_optimization_summaries_1 (struct opt_pass
*pass
)
2499 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2501 gcc_assert (!current_function_decl
);
2503 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2505 if (pass
->gate
== NULL
|| pass
->gate ())
2507 if (pass
->type
== IPA_PASS
&& ipa_pass
->read_optimization_summary
)
2509 /* If a timevar is present, start it. */
2511 timevar_push (pass
->tv_id
);
2513 pass_init_dump_file (pass
);
2515 ipa_pass
->read_optimization_summary ();
2517 pass_fini_dump_file (pass
);
2521 timevar_pop (pass
->tv_id
);
2524 if (pass
->sub
&& pass
->sub
->type
!= GIMPLE_PASS
)
2525 ipa_read_optimization_summaries_1 (pass
->sub
);
2531 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
2534 ipa_read_optimization_summaries (void)
2536 ipa_read_optimization_summaries_1 (all_regular_ipa_passes
);
2537 ipa_read_optimization_summaries_1 (all_lto_gen_passes
);
2540 /* Same as execute_pass_list but assume that subpasses of IPA passes
2541 are local passes. */
2543 execute_ipa_pass_list (struct opt_pass
*pass
)
2547 gcc_assert (!current_function_decl
);
2549 gcc_assert (pass
->type
== SIMPLE_IPA_PASS
|| pass
->type
== IPA_PASS
);
2550 if (execute_one_pass (pass
) && pass
->sub
)
2552 if (pass
->sub
->type
== GIMPLE_PASS
)
2554 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START
, NULL
);
2555 do_per_function_toporder ((void (*)(void *))execute_pass_list
,
2557 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END
, NULL
);
2559 else if (pass
->sub
->type
== SIMPLE_IPA_PASS
2560 || pass
->sub
->type
== IPA_PASS
)
2561 execute_ipa_pass_list (pass
->sub
);
2565 gcc_assert (!current_function_decl
);
2566 cgraph_process_new_functions ();
2572 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
2575 execute_ipa_stmt_fixups (struct opt_pass
*pass
,
2576 struct cgraph_node
*node
, gimple
*stmts
)
2580 /* Execute all of the IPA_PASSes in the list. */
2581 if (pass
->type
== IPA_PASS
2582 && (!pass
->gate
|| pass
->gate ()))
2584 struct ipa_opt_pass_d
*ipa_pass
= (struct ipa_opt_pass_d
*) pass
;
2586 if (ipa_pass
->stmt_fixup
)
2588 pass_init_dump_file (pass
);
2589 /* If a timevar is present, start it. */
2591 timevar_push (pass
->tv_id
);
2593 ipa_pass
->stmt_fixup (node
, stmts
);
2597 timevar_pop (pass
->tv_id
);
2598 pass_fini_dump_file (pass
);
2601 execute_ipa_stmt_fixups (pass
->sub
, node
, stmts
);
2607 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
2610 execute_all_ipa_stmt_fixups (struct cgraph_node
*node
, gimple
*stmts
)
2612 execute_ipa_stmt_fixups (all_regular_ipa_passes
, node
, stmts
);
2616 extern void debug_properties (unsigned int);
2617 extern void dump_properties (FILE *, unsigned int);
2620 dump_properties (FILE *dump
, unsigned int props
)
2622 fprintf (dump
, "Properties:\n");
2623 if (props
& PROP_gimple_any
)
2624 fprintf (dump
, "PROP_gimple_any\n");
2625 if (props
& PROP_gimple_lcf
)
2626 fprintf (dump
, "PROP_gimple_lcf\n");
2627 if (props
& PROP_gimple_leh
)
2628 fprintf (dump
, "PROP_gimple_leh\n");
2629 if (props
& PROP_cfg
)
2630 fprintf (dump
, "PROP_cfg\n");
2631 if (props
& PROP_referenced_vars
)
2632 fprintf (dump
, "PROP_referenced_vars\n");
2633 if (props
& PROP_ssa
)
2634 fprintf (dump
, "PROP_ssa\n");
2635 if (props
& PROP_no_crit_edges
)
2636 fprintf (dump
, "PROP_no_crit_edges\n");
2637 if (props
& PROP_rtl
)
2638 fprintf (dump
, "PROP_rtl\n");
2639 if (props
& PROP_gimple_lomp
)
2640 fprintf (dump
, "PROP_gimple_lomp\n");
2641 if (props
& PROP_gimple_lcx
)
2642 fprintf (dump
, "PROP_gimple_lcx\n");
2643 if (props
& PROP_cfglayout
)
2644 fprintf (dump
, "PROP_cfglayout\n");
2648 debug_properties (unsigned int props
)
2650 dump_properties (stderr
, props
);
2653 /* Called by local passes to see if function is called by already processed nodes.
2654 Because we process nodes in topological order, this means that function is
2655 in recursive cycle or we introduced new direct calls. */
2657 function_called_by_processed_nodes_p (void)
2659 struct cgraph_edge
*e
;
2660 for (e
= cgraph_get_node (current_function_decl
)->callers
;
2664 if (e
->caller
->symbol
.decl
== current_function_decl
)
2666 if (!cgraph_function_with_gimple_body_p (e
->caller
))
2668 if (TREE_ASM_WRITTEN (e
->caller
->symbol
.decl
))
2670 if (!e
->caller
->process
&& !e
->caller
->global
.inlined_to
)
2675 fprintf (dump_file
, "Already processed call to:\n");
2676 dump_cgraph_node (dump_file
, e
->caller
);
2681 #include "gt-passes.h"