Remove the lambda framework and make -ftree-loop-linear an alias of -floop-interchange.
[official-gcc/graphite-test-results.git] / gcc / passes.c
blobeaf65c42f3d51c73f1b40579729b0fe260398d7b
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 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
11 version.
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
16 for more details.
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "line-map.h"
32 #include "input.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "tm_p.h"
36 #include "flags.h"
37 #include "insn-attr.h"
38 #include "insn-config.h"
39 #include "insn-flags.h"
40 #include "hard-reg-set.h"
41 #include "recog.h"
42 #include "output.h"
43 #include "except.h"
44 #include "function.h"
45 #include "toplev.h"
46 #include "expr.h"
47 #include "basic-block.h"
48 #include "intl.h"
49 #include "ggc.h"
50 #include "graph.h"
51 #include "regs.h"
52 #include "timevar.h"
53 #include "diagnostic-core.h"
54 #include "params.h"
55 #include "reload.h"
56 #include "dwarf2asm.h"
57 #include "integrate.h"
58 #include "debug.h"
59 #include "target.h"
60 #include "langhooks.h"
61 #include "cfglayout.h"
62 #include "cfgloop.h"
63 #include "hosthooks.h"
64 #include "cgraph.h"
65 #include "opts.h"
66 #include "coverage.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"
72 #include "df.h"
73 #include "predict.h"
74 #include "lto-streamer.h"
75 #include "plugin.h"
77 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
78 #include "dwarf2out.h"
79 #endif
81 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
82 #include "dbxout.h"
83 #endif
85 #ifdef SDB_DEBUGGING_INFO
86 #include "sdbout.h"
87 #endif
89 #ifdef XCOFF_DEBUGGING_INFO
90 #include "xcoffout.h" /* Needed for external data
91 declarations for e.g. AIX 4.x. */
92 #endif
94 /* This is used for debugging. It allows the current pass to printed
95 from anywhere in compilation.
96 The variable current_pass is also used for statistics and plugins. */
97 struct opt_pass *current_pass;
99 /* Call from anywhere to find out what pass this is. Useful for
100 printing out debugging information deep inside an service
101 routine. */
102 void
103 print_current_pass (FILE *file)
105 if (current_pass)
106 fprintf (file, "current pass = %s (%d)\n",
107 current_pass->name, current_pass->static_pass_number);
108 else
109 fprintf (file, "no current pass.\n");
113 /* Call from the debugger to get the current pass name. */
114 DEBUG_FUNCTION void
115 debug_pass (void)
117 print_current_pass (stderr);
122 /* Global variables used to communicate with passes. */
123 int dump_flags;
124 bool in_gimple_form;
125 bool first_pass_instance;
128 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
129 and TYPE_DECL nodes.
131 This does nothing for local (non-static) variables, unless the
132 variable is a register variable with DECL_ASSEMBLER_NAME set. In
133 that case, or if the variable is not an automatic, it sets up the
134 RTL and outputs any assembler code (label definition, storage
135 allocation and initialization).
137 DECL is the declaration. TOP_LEVEL is nonzero
138 if this declaration is not within a function. */
140 void
141 rest_of_decl_compilation (tree decl,
142 int top_level,
143 int at_end)
145 /* We deferred calling assemble_alias so that we could collect
146 other attributes such as visibility. Emit the alias now. */
148 tree alias;
149 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
150 if (alias)
152 alias = TREE_VALUE (TREE_VALUE (alias));
153 alias = get_identifier (TREE_STRING_POINTER (alias));
154 assemble_alias (decl, alias);
158 /* Can't defer this, because it needs to happen before any
159 later function definitions are processed. */
160 if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl))
161 make_decl_rtl (decl);
163 /* Forward declarations for nested functions are not "external",
164 but we need to treat them as if they were. */
165 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
166 || TREE_CODE (decl) == FUNCTION_DECL)
168 timevar_push (TV_VARCONST);
170 /* Don't output anything when a tentative file-scope definition
171 is seen. But at end of compilation, do output code for them.
173 We do output all variables and rely on
174 callgraph code to defer them except for forward declarations
175 (see gcc.c-torture/compile/920624-1.c) */
176 if ((at_end
177 || !DECL_DEFER_OUTPUT (decl)
178 || DECL_INITIAL (decl))
179 && !DECL_EXTERNAL (decl))
181 /* When reading LTO unit, we also read varpool, so do not
182 rebuild it. */
183 if (in_lto_p && !at_end)
185 else if (TREE_CODE (decl) != FUNCTION_DECL)
186 varpool_finalize_decl (decl);
189 #ifdef ASM_FINISH_DECLARE_OBJECT
190 if (decl == last_assemble_variable_decl)
192 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
193 top_level, at_end);
195 #endif
197 timevar_pop (TV_VARCONST);
199 else if (TREE_CODE (decl) == TYPE_DECL
200 /* Like in rest_of_type_compilation, avoid confusing the debug
201 information machinery when there are errors. */
202 && !seen_error ())
204 timevar_push (TV_SYMOUT);
205 debug_hooks->type_decl (decl, !top_level);
206 timevar_pop (TV_SYMOUT);
209 /* Let cgraph know about the existence of variables. */
210 if (in_lto_p && !at_end)
212 else if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)
213 && TREE_STATIC (decl))
214 varpool_node (decl);
217 /* Called after finishing a record, union or enumeral type. */
219 void
220 rest_of_type_compilation (tree type, int toplev)
222 /* Avoid confusing the debug information machinery when there are
223 errors. */
224 if (seen_error ())
225 return;
227 timevar_push (TV_SYMOUT);
228 debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev);
229 timevar_pop (TV_SYMOUT);
234 void
235 finish_optimization_passes (void)
237 int i;
238 struct dump_file_info *dfi;
239 char *name;
241 timevar_push (TV_DUMP);
242 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
244 dump_file = dump_begin (pass_profile.pass.static_pass_number, NULL);
245 end_branch_prob ();
246 if (dump_file)
247 dump_end (pass_profile.pass.static_pass_number, dump_file);
250 if (optimize > 0)
252 dump_file = dump_begin (pass_combine.pass.static_pass_number, NULL);
253 if (dump_file)
255 dump_combine_total_stats (dump_file);
256 dump_end (pass_combine.pass.static_pass_number, dump_file);
260 /* Do whatever is necessary to finish printing the graphs. */
261 if (graph_dump_format != no_graph)
262 for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i)
263 if (dump_initialized_p (i)
264 && (dfi->flags & TDF_GRAPH) != 0
265 && (name = get_dump_file_name (i)) != NULL)
267 finish_graph_dump_file (name);
268 free (name);
271 timevar_pop (TV_DUMP);
274 static bool
275 gate_rest_of_compilation (void)
277 /* Early return if there were errors. We can run afoul of our
278 consistency checks, and there's not really much point in fixing them. */
279 return !(rtl_dump_and_exit || flag_syntax_only || seen_error ());
282 struct gimple_opt_pass pass_rest_of_compilation =
285 GIMPLE_PASS,
286 "*rest_of_compilation", /* name */
287 gate_rest_of_compilation, /* gate */
288 NULL, /* execute */
289 NULL, /* sub */
290 NULL, /* next */
291 0, /* static_pass_number */
292 TV_REST_OF_COMPILATION, /* tv_id */
293 PROP_rtl, /* properties_required */
294 0, /* properties_provided */
295 0, /* properties_destroyed */
296 0, /* todo_flags_start */
297 TODO_ggc_collect /* todo_flags_finish */
301 static bool
302 gate_postreload (void)
304 return reload_completed;
307 struct rtl_opt_pass pass_postreload =
310 RTL_PASS,
311 "*all-postreload", /* name */
312 gate_postreload, /* gate */
313 NULL, /* execute */
314 NULL, /* sub */
315 NULL, /* next */
316 0, /* static_pass_number */
317 TV_POSTRELOAD, /* tv_id */
318 PROP_rtl, /* properties_required */
319 0, /* properties_provided */
320 0, /* properties_destroyed */
321 0, /* todo_flags_start */
322 TODO_ggc_collect | TODO_verify_rtl_sharing /* todo_flags_finish */
328 /* The root of the compilation pass tree, once constructed. */
329 struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes,
330 *all_regular_ipa_passes, *all_lto_gen_passes;
332 /* This is used by plugins, and should also be used in register_pass. */
333 #define DEF_PASS_LIST(LIST) &LIST,
334 struct opt_pass **gcc_pass_lists[] = { GCC_PASS_LISTS NULL };
335 #undef DEF_PASS_LIST
337 /* A map from static pass id to optimization pass. */
338 struct opt_pass **passes_by_id;
339 int passes_by_id_size;
341 /* Set the static pass number of pass PASS to ID and record that
342 in the mapping from static pass number to pass. */
344 static void
345 set_pass_for_id (int id, struct opt_pass *pass)
347 pass->static_pass_number = id;
348 if (passes_by_id_size <= id)
350 passes_by_id = XRESIZEVEC (struct opt_pass *, passes_by_id, id + 1);
351 memset (passes_by_id + passes_by_id_size, 0,
352 (id + 1 - passes_by_id_size) * sizeof (void *));
353 passes_by_id_size = id + 1;
355 passes_by_id[id] = pass;
358 /* Return the pass with the static pass number ID. */
360 struct opt_pass *
361 get_pass_for_id (int id)
363 if (id >= passes_by_id_size)
364 return NULL;
365 return passes_by_id[id];
368 /* Iterate over the pass tree allocating dump file numbers. We want
369 to do this depth first, and independent of whether the pass is
370 enabled or not. */
372 void
373 register_one_dump_file (struct opt_pass *pass)
375 char *dot_name, *flag_name, *glob_name;
376 const char *name, *prefix;
377 char num[10];
378 int flags, id;
380 /* See below in next_pass_1. */
381 num[0] = '\0';
382 if (pass->static_pass_number != -1)
383 sprintf (num, "%d", ((int) pass->static_pass_number < 0
384 ? 1 : pass->static_pass_number));
386 /* The name is both used to identify the pass for the purposes of plugins,
387 and to specify dump file name and option.
388 The latter two might want something short which is not quite unique; for
389 that reason, we may have a disambiguating prefix, followed by a space
390 to mark the start of the following dump file name / option string. */
391 name = strchr (pass->name, ' ');
392 name = name ? name + 1 : pass->name;
393 dot_name = concat (".", name, num, NULL);
394 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
395 prefix = "ipa-", flags = TDF_IPA;
396 else if (pass->type == GIMPLE_PASS)
397 prefix = "tree-", flags = TDF_TREE;
398 else
399 prefix = "rtl-", flags = TDF_RTL;
401 flag_name = concat (prefix, name, num, NULL);
402 glob_name = concat (prefix, name, NULL);
403 id = dump_register (dot_name, flag_name, glob_name, flags);
404 set_pass_for_id (id, pass);
407 /* Recursive worker function for register_dump_files. */
409 static int
410 register_dump_files_1 (struct opt_pass *pass, int properties)
414 int new_properties = (properties | pass->properties_provided)
415 & ~pass->properties_destroyed;
417 if (pass->name && pass->name[0] != '*')
418 register_one_dump_file (pass);
420 if (pass->sub)
421 new_properties = register_dump_files_1 (pass->sub, new_properties);
423 /* If we have a gate, combine the properties that we could have with
424 and without the pass being examined. */
425 if (pass->gate)
426 properties &= new_properties;
427 else
428 properties = new_properties;
430 pass = pass->next;
432 while (pass);
434 return properties;
437 /* Register the dump files for the pipeline starting at PASS.
438 PROPERTIES reflects the properties that are guaranteed to be available at
439 the beginning of the pipeline. */
441 static void
442 register_dump_files (struct opt_pass *pass,int properties)
444 pass->properties_required |= properties;
445 register_dump_files_1 (pass, properties);
448 /* Look at the static_pass_number and duplicate the pass
449 if it is already added to a list. */
451 static struct opt_pass *
452 make_pass_instance (struct opt_pass *pass, bool track_duplicates)
454 /* A nonzero static_pass_number indicates that the
455 pass is already in the list. */
456 if (pass->static_pass_number)
458 struct opt_pass *new_pass;
460 if (pass->type == GIMPLE_PASS
461 || pass->type == RTL_PASS
462 || pass->type == SIMPLE_IPA_PASS)
464 new_pass = XNEW (struct opt_pass);
465 memcpy (new_pass, pass, sizeof (struct opt_pass));
467 else if (pass->type == IPA_PASS)
469 new_pass = (struct opt_pass *)XNEW (struct ipa_opt_pass_d);
470 memcpy (new_pass, pass, sizeof (struct ipa_opt_pass_d));
472 else
473 gcc_unreachable ();
475 new_pass->next = NULL;
477 new_pass->todo_flags_start &= ~TODO_mark_first_instance;
479 /* Indicate to register_dump_files that this pass has duplicates,
480 and so it should rename the dump file. The first instance will
481 be -1, and be number of duplicates = -static_pass_number - 1.
482 Subsequent instances will be > 0 and just the duplicate number. */
483 if ((pass->name && pass->name[0] != '*') || track_duplicates)
485 pass->static_pass_number -= 1;
486 new_pass->static_pass_number = -pass->static_pass_number;
488 return new_pass;
490 else
492 pass->todo_flags_start |= TODO_mark_first_instance;
493 pass->static_pass_number = -1;
495 invoke_plugin_callbacks (PLUGIN_NEW_PASS, pass);
497 return pass;
500 /* Add a pass to the pass list. Duplicate the pass if it's already
501 in the list. */
503 static struct opt_pass **
504 next_pass_1 (struct opt_pass **list, struct opt_pass *pass)
506 /* Every pass should have a name so that plugins can refer to them. */
507 gcc_assert (pass->name != NULL);
509 *list = make_pass_instance (pass, false);
511 return &(*list)->next;
514 /* List node for an inserted pass instance. We need to keep track of all
515 the newly-added pass instances (with 'added_pass_nodes' defined below)
516 so that we can register their dump files after pass-positioning is finished.
517 Registering dumping files needs to be post-processed or the
518 static_pass_number of the opt_pass object would be modified and mess up
519 the dump file names of future pass instances to be added. */
521 struct pass_list_node
523 struct opt_pass *pass;
524 struct pass_list_node *next;
527 static struct pass_list_node *added_pass_nodes = NULL;
528 static struct pass_list_node *prev_added_pass_node;
530 /* Insert the pass at the proper position. Return true if the pass
531 is successfully added.
533 NEW_PASS_INFO - new pass to be inserted
534 PASS_LIST - root of the pass list to insert the new pass to */
536 static bool
537 position_pass (struct register_pass_info *new_pass_info,
538 struct opt_pass **pass_list)
540 struct opt_pass *pass = *pass_list, *prev_pass = NULL;
541 bool success = false;
543 for ( ; pass; prev_pass = pass, pass = pass->next)
545 /* Check if the current pass is of the same type as the new pass and
546 matches the name and the instance number of the reference pass. */
547 if (pass->type == new_pass_info->pass->type
548 && pass->name
549 && !strcmp (pass->name, new_pass_info->reference_pass_name)
550 && ((new_pass_info->ref_pass_instance_number == 0)
551 || (new_pass_info->ref_pass_instance_number ==
552 pass->static_pass_number)
553 || (new_pass_info->ref_pass_instance_number == 1
554 && pass->todo_flags_start & TODO_mark_first_instance)))
556 struct opt_pass *new_pass;
557 struct pass_list_node *new_pass_node;
559 new_pass = make_pass_instance (new_pass_info->pass, true);
561 /* Insert the new pass instance based on the positioning op. */
562 switch (new_pass_info->pos_op)
564 case PASS_POS_INSERT_AFTER:
565 new_pass->next = pass->next;
566 pass->next = new_pass;
568 /* Skip newly inserted pass to avoid repeated
569 insertions in the case where the new pass and the
570 existing one have the same name. */
571 pass = new_pass;
572 break;
573 case PASS_POS_INSERT_BEFORE:
574 new_pass->next = pass;
575 if (prev_pass)
576 prev_pass->next = new_pass;
577 else
578 *pass_list = new_pass;
579 break;
580 case PASS_POS_REPLACE:
581 new_pass->next = pass->next;
582 if (prev_pass)
583 prev_pass->next = new_pass;
584 else
585 *pass_list = new_pass;
586 new_pass->sub = pass->sub;
587 new_pass->tv_id = pass->tv_id;
588 pass = new_pass;
589 break;
590 default:
591 error ("invalid pass positioning operation");
592 return false;
595 /* Save the newly added pass (instance) in the added_pass_nodes
596 list so that we can register its dump file later. Note that
597 we cannot register the dump file now because doing so will modify
598 the static_pass_number of the opt_pass object and therefore
599 mess up the dump file name of future instances. */
600 new_pass_node = XCNEW (struct pass_list_node);
601 new_pass_node->pass = new_pass;
602 if (!added_pass_nodes)
603 added_pass_nodes = new_pass_node;
604 else
605 prev_added_pass_node->next = new_pass_node;
606 prev_added_pass_node = new_pass_node;
608 success = true;
611 if (pass->sub && position_pass (new_pass_info, &pass->sub))
612 success = true;
615 return success;
618 /* Hooks a new pass into the pass lists.
620 PASS_INFO - pass information that specifies the opt_pass object,
621 reference pass, instance number, and how to position
622 the pass */
624 void
625 register_pass (struct register_pass_info *pass_info)
627 bool all_instances, success;
629 /* The checks below could fail in buggy plugins. Existing GCC
630 passes should never fail these checks, so we mention plugin in
631 the messages. */
632 if (!pass_info->pass)
633 fatal_error ("plugin cannot register a missing pass");
635 if (!pass_info->pass->name)
636 fatal_error ("plugin cannot register an unnamed pass");
638 if (!pass_info->reference_pass_name)
639 fatal_error
640 ("plugin cannot register pass %qs without reference pass name",
641 pass_info->pass->name);
643 /* Try to insert the new pass to the pass lists. We need to check
644 all five lists as the reference pass could be in one (or all) of
645 them. */
646 all_instances = pass_info->ref_pass_instance_number == 0;
647 success = position_pass (pass_info, &all_lowering_passes);
648 if (!success || all_instances)
649 success |= position_pass (pass_info, &all_small_ipa_passes);
650 if (!success || all_instances)
651 success |= position_pass (pass_info, &all_regular_ipa_passes);
652 if (!success || all_instances)
653 success |= position_pass (pass_info, &all_lto_gen_passes);
654 if (!success || all_instances)
655 success |= position_pass (pass_info, &all_passes);
656 if (!success)
657 fatal_error
658 ("pass %qs not found but is referenced by new pass %qs",
659 pass_info->reference_pass_name, pass_info->pass->name);
661 /* OK, we have successfully inserted the new pass. We need to register
662 the dump files for the newly added pass and its duplicates (if any).
663 Because the registration of plugin/backend passes happens after the
664 command-line options are parsed, the options that specify single
665 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
666 passes. Therefore we currently can only enable dumping of
667 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
668 are specified. While doing so, we also delete the pass_list_node
669 objects created during pass positioning. */
670 while (added_pass_nodes)
672 struct pass_list_node *next_node = added_pass_nodes->next;
673 enum tree_dump_index tdi;
674 register_one_dump_file (added_pass_nodes->pass);
675 if (added_pass_nodes->pass->type == SIMPLE_IPA_PASS
676 || added_pass_nodes->pass->type == IPA_PASS)
677 tdi = TDI_ipa_all;
678 else if (added_pass_nodes->pass->type == GIMPLE_PASS)
679 tdi = TDI_tree_all;
680 else
681 tdi = TDI_rtl_all;
682 /* Check if dump-all flag is specified. */
683 if (get_dump_file_info (tdi)->state)
684 get_dump_file_info (added_pass_nodes->pass->static_pass_number)
685 ->state = get_dump_file_info (tdi)->state;
686 XDELETE (added_pass_nodes);
687 added_pass_nodes = next_node;
691 /* Construct the pass tree. The sequencing of passes is driven by
692 the cgraph routines:
694 cgraph_finalize_compilation_unit ()
695 for each node N in the cgraph
696 cgraph_analyze_function (N)
697 cgraph_lower_function (N) -> all_lowering_passes
699 If we are optimizing, cgraph_optimize is then invoked:
701 cgraph_optimize ()
702 ipa_passes () -> all_small_ipa_passes
703 cgraph_expand_all_functions ()
704 for each node N in the cgraph
705 cgraph_expand_function (N)
706 tree_rest_of_compilation (DECL (N)) -> all_passes
709 void
710 init_optimization_passes (void)
712 struct opt_pass **p;
714 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &((PASS).pass)))
716 /* All passes needed to lower the function into shape optimizers can
717 operate on. These passes are always run first on the function, but
718 backend might produce already lowered functions that are not processed
719 by these passes. */
720 p = &all_lowering_passes;
721 NEXT_PASS (pass_warn_unused_result);
722 NEXT_PASS (pass_diagnose_omp_blocks);
723 NEXT_PASS (pass_mudflap_1);
724 NEXT_PASS (pass_lower_omp);
725 NEXT_PASS (pass_lower_cf);
726 NEXT_PASS (pass_refactor_eh);
727 NEXT_PASS (pass_lower_eh);
728 NEXT_PASS (pass_build_cfg);
729 NEXT_PASS (pass_warn_function_return);
730 NEXT_PASS (pass_build_cgraph_edges);
731 NEXT_PASS (pass_inline_parameters);
732 *p = NULL;
734 /* Interprocedural optimization passes. */
735 p = &all_small_ipa_passes;
736 NEXT_PASS (pass_ipa_free_lang_data);
737 NEXT_PASS (pass_ipa_function_and_variable_visibility);
738 NEXT_PASS (pass_early_local_passes);
740 struct opt_pass **p = &pass_early_local_passes.pass.sub;
741 NEXT_PASS (pass_fixup_cfg);
742 NEXT_PASS (pass_init_datastructures);
743 NEXT_PASS (pass_expand_omp);
745 NEXT_PASS (pass_referenced_vars);
746 NEXT_PASS (pass_build_ssa);
747 NEXT_PASS (pass_lower_vector);
748 NEXT_PASS (pass_early_warn_uninitialized);
749 /* Note that it is not strictly necessary to schedule an early
750 inline pass here. However, some test cases (e.g.,
751 g++.dg/other/p334435.C g++.dg/other/i386-1.C) expect extern
752 inline functions to be inlined even at -O0. This does not
753 happen during the first early inline pass. */
754 NEXT_PASS (pass_rebuild_cgraph_edges);
755 NEXT_PASS (pass_early_inline);
756 NEXT_PASS (pass_all_early_optimizations);
758 struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
759 NEXT_PASS (pass_remove_cgraph_callee_edges);
760 NEXT_PASS (pass_rename_ssa_copies);
761 NEXT_PASS (pass_ccp);
762 NEXT_PASS (pass_forwprop);
763 /* pass_build_ealias is a dummy pass that ensures that we
764 execute TODO_rebuild_alias at this point. Re-building
765 alias information also rewrites no longer addressed
766 locals into SSA form if possible. */
767 NEXT_PASS (pass_build_ealias);
768 NEXT_PASS (pass_sra_early);
769 NEXT_PASS (pass_copy_prop);
770 NEXT_PASS (pass_merge_phi);
771 NEXT_PASS (pass_cd_dce);
772 NEXT_PASS (pass_early_ipa_sra);
773 NEXT_PASS (pass_tail_recursion);
774 NEXT_PASS (pass_convert_switch);
775 NEXT_PASS (pass_cleanup_eh);
776 NEXT_PASS (pass_profile);
777 NEXT_PASS (pass_local_pure_const);
778 /* Split functions creates parts that are not run through
779 early optimizations again. It is thus good idea to do this
780 late. */
781 NEXT_PASS (pass_split_functions);
783 NEXT_PASS (pass_release_ssa_names);
784 NEXT_PASS (pass_rebuild_cgraph_edges);
785 NEXT_PASS (pass_inline_parameters);
787 NEXT_PASS (pass_ipa_tree_profile);
788 NEXT_PASS (pass_ipa_increase_alignment);
789 NEXT_PASS (pass_ipa_matrix_reorg);
790 NEXT_PASS (pass_ipa_lower_emutls);
791 *p = NULL;
793 p = &all_regular_ipa_passes;
794 NEXT_PASS (pass_ipa_whole_program_visibility);
795 NEXT_PASS (pass_ipa_profile);
796 NEXT_PASS (pass_ipa_cp);
797 NEXT_PASS (pass_ipa_cdtor_merge);
798 NEXT_PASS (pass_ipa_inline);
799 NEXT_PASS (pass_ipa_pure_const);
800 NEXT_PASS (pass_ipa_reference);
801 NEXT_PASS (pass_ipa_type_escape);
802 NEXT_PASS (pass_ipa_pta);
803 NEXT_PASS (pass_ipa_struct_reorg);
804 *p = NULL;
806 p = &all_lto_gen_passes;
807 NEXT_PASS (pass_ipa_lto_gimple_out);
808 NEXT_PASS (pass_ipa_lto_finish_out); /* This must be the last LTO pass. */
809 *p = NULL;
811 /* These passes are run after IPA passes on every function that is being
812 output to the assembler file. */
813 p = &all_passes;
814 NEXT_PASS (pass_lower_eh_dispatch);
815 NEXT_PASS (pass_all_optimizations);
817 struct opt_pass **p = &pass_all_optimizations.pass.sub;
818 NEXT_PASS (pass_remove_cgraph_callee_edges);
819 /* Initial scalar cleanups before alias computation.
820 They ensure memory accesses are not indirect wherever possible. */
821 NEXT_PASS (pass_strip_predict_hints);
822 NEXT_PASS (pass_rename_ssa_copies);
823 NEXT_PASS (pass_complete_unrolli);
824 NEXT_PASS (pass_ccp);
825 NEXT_PASS (pass_forwprop);
826 NEXT_PASS (pass_call_cdce);
827 /* pass_build_alias is a dummy pass that ensures that we
828 execute TODO_rebuild_alias at this point. Re-building
829 alias information also rewrites no longer addressed
830 locals into SSA form if possible. */
831 NEXT_PASS (pass_build_alias);
832 NEXT_PASS (pass_return_slot);
833 NEXT_PASS (pass_phiprop);
834 NEXT_PASS (pass_fre);
835 NEXT_PASS (pass_copy_prop);
836 NEXT_PASS (pass_merge_phi);
837 NEXT_PASS (pass_vrp);
838 NEXT_PASS (pass_dce);
839 NEXT_PASS (pass_cselim);
840 NEXT_PASS (pass_tree_ifcombine);
841 NEXT_PASS (pass_phiopt);
842 NEXT_PASS (pass_tail_recursion);
843 NEXT_PASS (pass_ch);
844 NEXT_PASS (pass_stdarg);
845 NEXT_PASS (pass_lower_complex);
846 NEXT_PASS (pass_sra);
847 NEXT_PASS (pass_rename_ssa_copies);
848 /* The dom pass will also resolve all __builtin_constant_p calls
849 that are still there to 0. This has to be done after some
850 propagations have already run, but before some more dead code
851 is removed, and this place fits nicely. Remember this when
852 trying to move or duplicate pass_dominator somewhere earlier. */
853 NEXT_PASS (pass_dominator);
854 /* The only const/copy propagation opportunities left after
855 DOM should be due to degenerate PHI nodes. So rather than
856 run the full propagators, run a specialized pass which
857 only examines PHIs to discover const/copy propagation
858 opportunities. */
859 NEXT_PASS (pass_phi_only_cprop);
860 NEXT_PASS (pass_dse);
861 NEXT_PASS (pass_reassoc);
862 NEXT_PASS (pass_dce);
863 NEXT_PASS (pass_forwprop);
864 NEXT_PASS (pass_phiopt);
865 NEXT_PASS (pass_object_sizes);
866 NEXT_PASS (pass_ccp);
867 NEXT_PASS (pass_copy_prop);
868 NEXT_PASS (pass_cse_sincos);
869 NEXT_PASS (pass_optimize_bswap);
870 NEXT_PASS (pass_split_crit_edges);
871 NEXT_PASS (pass_pre);
872 NEXT_PASS (pass_sink_code);
873 NEXT_PASS (pass_tree_loop);
875 struct opt_pass **p = &pass_tree_loop.pass.sub;
876 NEXT_PASS (pass_tree_loop_init);
877 NEXT_PASS (pass_lim);
878 NEXT_PASS (pass_copy_prop);
879 NEXT_PASS (pass_dce_loop);
880 NEXT_PASS (pass_tree_unswitch);
881 NEXT_PASS (pass_scev_cprop);
882 NEXT_PASS (pass_record_bounds);
883 NEXT_PASS (pass_check_data_deps);
884 NEXT_PASS (pass_loop_distribution);
885 NEXT_PASS (pass_copy_prop);
886 NEXT_PASS (pass_graphite);
888 struct opt_pass **p = &pass_graphite.pass.sub;
889 NEXT_PASS (pass_graphite_transforms);
890 NEXT_PASS (pass_copy_prop);
891 NEXT_PASS (pass_dce_loop);
892 NEXT_PASS (pass_lim);
894 NEXT_PASS (pass_iv_canon);
895 NEXT_PASS (pass_if_conversion);
896 NEXT_PASS (pass_vectorize);
898 struct opt_pass **p = &pass_vectorize.pass.sub;
899 NEXT_PASS (pass_lower_vector_ssa);
900 NEXT_PASS (pass_dce_loop);
902 NEXT_PASS (pass_predcom);
903 NEXT_PASS (pass_complete_unroll);
904 NEXT_PASS (pass_slp_vectorize);
905 NEXT_PASS (pass_parallelize_loops);
906 NEXT_PASS (pass_loop_prefetch);
907 NEXT_PASS (pass_iv_optimize);
908 NEXT_PASS (pass_tree_loop_done);
910 NEXT_PASS (pass_cse_reciprocals);
911 NEXT_PASS (pass_reassoc);
912 NEXT_PASS (pass_vrp);
913 NEXT_PASS (pass_dominator);
914 /* The only const/copy propagation opportunities left after
915 DOM should be due to degenerate PHI nodes. So rather than
916 run the full propagators, run a specialized pass which
917 only examines PHIs to discover const/copy propagation
918 opportunities. */
919 NEXT_PASS (pass_phi_only_cprop);
920 NEXT_PASS (pass_cd_dce);
921 NEXT_PASS (pass_tracer);
923 /* FIXME: If DCE is not run before checking for uninitialized uses,
924 we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
925 However, this also causes us to misdiagnose cases that should be
926 real warnings (e.g., testsuite/gcc.dg/pr18501.c).
928 To fix the false positives in uninit-5.c, we would have to
929 account for the predicates protecting the set and the use of each
930 variable. Using a representation like Gated Single Assignment
931 may help. */
932 NEXT_PASS (pass_late_warn_uninitialized);
933 NEXT_PASS (pass_dse);
934 NEXT_PASS (pass_forwprop);
935 NEXT_PASS (pass_phiopt);
936 NEXT_PASS (pass_fold_builtins);
937 NEXT_PASS (pass_optimize_widening_mul);
938 NEXT_PASS (pass_tail_calls);
939 NEXT_PASS (pass_rename_ssa_copies);
940 NEXT_PASS (pass_uncprop);
941 NEXT_PASS (pass_local_pure_const);
943 NEXT_PASS (pass_lower_complex_O0);
944 NEXT_PASS (pass_cleanup_eh);
945 NEXT_PASS (pass_lower_resx);
946 NEXT_PASS (pass_nrv);
947 NEXT_PASS (pass_mudflap_2);
948 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
949 NEXT_PASS (pass_warn_function_noreturn);
951 NEXT_PASS (pass_expand);
953 NEXT_PASS (pass_rest_of_compilation);
955 struct opt_pass **p = &pass_rest_of_compilation.pass.sub;
956 NEXT_PASS (pass_init_function);
957 NEXT_PASS (pass_jump);
958 NEXT_PASS (pass_rtl_eh);
959 NEXT_PASS (pass_initial_value_sets);
960 NEXT_PASS (pass_unshare_all_rtl);
961 NEXT_PASS (pass_instantiate_virtual_regs);
962 NEXT_PASS (pass_into_cfg_layout_mode);
963 NEXT_PASS (pass_jump2);
964 NEXT_PASS (pass_lower_subreg);
965 NEXT_PASS (pass_df_initialize_opt);
966 NEXT_PASS (pass_cse);
967 NEXT_PASS (pass_rtl_fwprop);
968 NEXT_PASS (pass_rtl_cprop);
969 NEXT_PASS (pass_rtl_pre);
970 NEXT_PASS (pass_rtl_hoist);
971 NEXT_PASS (pass_rtl_cprop);
972 NEXT_PASS (pass_rtl_store_motion);
973 NEXT_PASS (pass_cse_after_global_opts);
974 NEXT_PASS (pass_rtl_ifcvt);
975 NEXT_PASS (pass_reginfo_init);
976 /* Perform loop optimizations. It might be better to do them a bit
977 sooner, but we want the profile feedback to work more
978 efficiently. */
979 NEXT_PASS (pass_loop2);
981 struct opt_pass **p = &pass_loop2.pass.sub;
982 NEXT_PASS (pass_rtl_loop_init);
983 NEXT_PASS (pass_rtl_move_loop_invariants);
984 NEXT_PASS (pass_rtl_unswitch);
985 NEXT_PASS (pass_rtl_unroll_and_peel_loops);
986 NEXT_PASS (pass_rtl_doloop);
987 NEXT_PASS (pass_rtl_loop_done);
988 *p = NULL;
990 NEXT_PASS (pass_web);
991 NEXT_PASS (pass_rtl_cprop);
992 NEXT_PASS (pass_cse2);
993 NEXT_PASS (pass_rtl_dse1);
994 NEXT_PASS (pass_rtl_fwprop_addr);
995 NEXT_PASS (pass_inc_dec);
996 NEXT_PASS (pass_initialize_regs);
997 NEXT_PASS (pass_ud_rtl_dce);
998 NEXT_PASS (pass_combine);
999 NEXT_PASS (pass_if_after_combine);
1000 NEXT_PASS (pass_partition_blocks);
1001 NEXT_PASS (pass_regmove);
1002 NEXT_PASS (pass_outof_cfg_layout_mode);
1003 NEXT_PASS (pass_split_all_insns);
1004 NEXT_PASS (pass_lower_subreg2);
1005 NEXT_PASS (pass_df_initialize_no_opt);
1006 NEXT_PASS (pass_stack_ptr_mod);
1007 NEXT_PASS (pass_mode_switching);
1008 NEXT_PASS (pass_match_asm_constraints);
1009 NEXT_PASS (pass_sms);
1010 NEXT_PASS (pass_sched);
1011 NEXT_PASS (pass_ira);
1012 NEXT_PASS (pass_postreload);
1014 struct opt_pass **p = &pass_postreload.pass.sub;
1015 NEXT_PASS (pass_postreload_cse);
1016 NEXT_PASS (pass_gcse2);
1017 NEXT_PASS (pass_split_after_reload);
1018 NEXT_PASS (pass_implicit_zee);
1019 NEXT_PASS (pass_branch_target_load_optimize1);
1020 NEXT_PASS (pass_thread_prologue_and_epilogue);
1021 NEXT_PASS (pass_rtl_dse2);
1022 NEXT_PASS (pass_stack_adjustments);
1023 NEXT_PASS (pass_peephole2);
1024 NEXT_PASS (pass_if_after_reload);
1025 NEXT_PASS (pass_regrename);
1026 NEXT_PASS (pass_cprop_hardreg);
1027 NEXT_PASS (pass_fast_rtl_dce);
1028 NEXT_PASS (pass_reorder_blocks);
1029 NEXT_PASS (pass_branch_target_load_optimize2);
1030 NEXT_PASS (pass_leaf_regs);
1031 NEXT_PASS (pass_split_before_sched2);
1032 NEXT_PASS (pass_sched2);
1033 NEXT_PASS (pass_stack_regs);
1035 struct opt_pass **p = &pass_stack_regs.pass.sub;
1036 NEXT_PASS (pass_split_before_regstack);
1037 NEXT_PASS (pass_stack_regs_run);
1039 NEXT_PASS (pass_compute_alignments);
1040 NEXT_PASS (pass_duplicate_computed_gotos);
1041 NEXT_PASS (pass_variable_tracking);
1042 NEXT_PASS (pass_free_cfg);
1043 NEXT_PASS (pass_machine_reorg);
1044 NEXT_PASS (pass_cleanup_barriers);
1045 NEXT_PASS (pass_delay_slots);
1046 NEXT_PASS (pass_split_for_shorten_branches);
1047 NEXT_PASS (pass_convert_to_eh_region_ranges);
1048 NEXT_PASS (pass_shorten_branches);
1049 NEXT_PASS (pass_set_nothrow_function_flags);
1050 NEXT_PASS (pass_final);
1052 NEXT_PASS (pass_df_finish);
1054 NEXT_PASS (pass_clean_state);
1055 *p = NULL;
1057 #undef NEXT_PASS
1059 /* Register the passes with the tree dump code. */
1060 register_dump_files (all_lowering_passes, PROP_gimple_any);
1061 register_dump_files (all_small_ipa_passes,
1062 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1063 | PROP_cfg);
1064 register_dump_files (all_regular_ipa_passes,
1065 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1066 | PROP_cfg);
1067 register_dump_files (all_lto_gen_passes,
1068 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1069 | PROP_cfg);
1070 register_dump_files (all_passes,
1071 PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh
1072 | PROP_cfg);
1075 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1076 function CALLBACK for every function in the call graph. Otherwise,
1077 call CALLBACK on the current function. */
1079 static void
1080 do_per_function (void (*callback) (void *data), void *data)
1082 if (current_function_decl)
1083 callback (data);
1084 else
1086 struct cgraph_node *node;
1087 for (node = cgraph_nodes; node; node = node->next)
1088 if (node->analyzed && gimple_has_body_p (node->decl)
1089 && (!node->clone_of || node->decl != node->clone_of->decl))
1091 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1092 current_function_decl = node->decl;
1093 callback (data);
1094 if (!flag_wpa)
1096 free_dominance_info (CDI_DOMINATORS);
1097 free_dominance_info (CDI_POST_DOMINATORS);
1099 current_function_decl = NULL;
1100 pop_cfun ();
1101 ggc_collect ();
1106 /* Because inlining might remove no-longer reachable nodes, we need to
1107 keep the array visible to garbage collector to avoid reading collected
1108 out nodes. */
1109 static int nnodes;
1110 static GTY ((length ("nnodes"))) cgraph_node_ptr *order;
1112 /* If we are in IPA mode (i.e., current_function_decl is NULL), call
1113 function CALLBACK for every function in the call graph. Otherwise,
1114 call CALLBACK on the current function.
1115 This function is global so that plugins can use it. */
1116 void
1117 do_per_function_toporder (void (*callback) (void *data), void *data)
1119 int i;
1121 if (current_function_decl)
1122 callback (data);
1123 else
1125 gcc_assert (!order);
1126 order = ggc_alloc_vec_cgraph_node_ptr (cgraph_n_nodes);
1127 nnodes = cgraph_postorder (order);
1128 for (i = nnodes - 1; i >= 0; i--)
1129 order[i]->process = 1;
1130 for (i = nnodes - 1; i >= 0; i--)
1132 struct cgraph_node *node = order[i];
1134 /* Allow possibly removed nodes to be garbage collected. */
1135 order[i] = NULL;
1136 node->process = 0;
1137 if (node->analyzed)
1139 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1140 current_function_decl = node->decl;
1141 callback (data);
1142 free_dominance_info (CDI_DOMINATORS);
1143 free_dominance_info (CDI_POST_DOMINATORS);
1144 current_function_decl = NULL;
1145 pop_cfun ();
1146 ggc_collect ();
1150 ggc_free (order);
1151 order = NULL;
1152 nnodes = 0;
1155 /* Perform all TODO actions that ought to be done on each function. */
1157 static void
1158 execute_function_todo (void *data)
1160 unsigned int flags = (size_t)data;
1161 flags &= ~cfun->last_verified;
1162 if (!flags)
1163 return;
1165 /* Always cleanup the CFG before trying to update SSA. */
1166 if (flags & TODO_cleanup_cfg)
1168 bool cleanup = cleanup_tree_cfg ();
1170 if (cleanup && (cfun->curr_properties & PROP_ssa))
1171 flags |= TODO_remove_unused_locals;
1173 /* When cleanup_tree_cfg merges consecutive blocks, it may
1174 perform some simplistic propagation when removing single
1175 valued PHI nodes. This propagation may, in turn, cause the
1176 SSA form to become out-of-date (see PR 22037). So, even
1177 if the parent pass had not scheduled an SSA update, we may
1178 still need to do one. */
1179 if (!(flags & TODO_update_ssa_any) && need_ssa_update_p (cfun))
1180 flags |= TODO_update_ssa;
1183 if (flags & TODO_update_ssa_any)
1185 unsigned update_flags = flags & TODO_update_ssa_any;
1186 update_ssa (update_flags);
1187 cfun->last_verified &= ~TODO_verify_ssa;
1190 if (flags & TODO_rebuild_alias)
1192 execute_update_addresses_taken ();
1193 compute_may_aliases ();
1195 else if (optimize && (flags & TODO_update_address_taken))
1196 execute_update_addresses_taken ();
1198 if (flags & TODO_remove_unused_locals)
1199 remove_unused_locals ();
1201 if ((flags & TODO_dump_func) && dump_file && current_function_decl)
1203 if (cfun->curr_properties & PROP_trees)
1204 dump_function_to_file (current_function_decl, dump_file, dump_flags);
1205 else
1207 if (dump_flags & TDF_SLIM)
1208 print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags);
1209 else if ((cfun->curr_properties & PROP_cfg)
1210 && (dump_flags & TDF_BLOCKS))
1211 print_rtl_with_bb (dump_file, get_insns ());
1212 else
1213 print_rtl (dump_file, get_insns ());
1215 if ((cfun->curr_properties & PROP_cfg)
1216 && graph_dump_format != no_graph
1217 && (dump_flags & TDF_GRAPH))
1218 print_rtl_graph_with_bb (dump_file_name, get_insns ());
1221 /* Flush the file. If verification fails, we won't be able to
1222 close the file before aborting. */
1223 fflush (dump_file);
1226 if (flags & TODO_rebuild_frequencies)
1227 rebuild_frequencies ();
1229 /* If we've seen errors do not bother running any verifiers. */
1230 if (seen_error ())
1231 return;
1233 #if defined ENABLE_CHECKING
1234 if (flags & TODO_verify_ssa
1235 || (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA)))
1236 verify_ssa (true);
1237 if (flags & TODO_verify_flow)
1238 verify_flow_info ();
1239 if (flags & TODO_verify_stmts)
1240 verify_stmts ();
1241 if (current_loops && loops_state_satisfies_p (LOOP_CLOSED_SSA))
1242 verify_loop_closed_ssa (false);
1243 if (flags & TODO_verify_rtl_sharing)
1244 verify_rtl_sharing ();
1245 #endif
1247 cfun->last_verified = flags & TODO_verify_all;
1250 /* Perform all TODO actions. */
1251 static void
1252 execute_todo (unsigned int flags)
1254 #if defined ENABLE_CHECKING
1255 if (cfun
1256 && need_ssa_update_p (cfun))
1257 gcc_assert (flags & TODO_update_ssa_any);
1258 #endif
1260 timevar_push (TV_TODO);
1262 /* Inform the pass whether it is the first time it is run. */
1263 first_pass_instance = (flags & TODO_mark_first_instance) != 0;
1265 statistics_fini_pass ();
1267 do_per_function (execute_function_todo, (void *)(size_t) flags);
1269 /* Always remove functions just as before inlining: IPA passes might be
1270 interested to see bodies of extern inline functions that are not inlined
1271 to analyze side effects. The full removal is done just at the end
1272 of IPA pass queue. */
1273 if (flags & TODO_remove_functions)
1275 gcc_assert (!cfun);
1276 cgraph_remove_unreachable_nodes (true, dump_file);
1279 if ((flags & TODO_dump_cgraph) && dump_file && !current_function_decl)
1281 gcc_assert (!cfun);
1282 dump_cgraph (dump_file);
1283 /* Flush the file. If verification fails, we won't be able to
1284 close the file before aborting. */
1285 fflush (dump_file);
1288 if (flags & TODO_ggc_collect)
1289 ggc_collect ();
1291 /* Now that the dumping has been done, we can get rid of the optional
1292 df problems. */
1293 if (flags & TODO_df_finish)
1294 df_finish_pass ((flags & TODO_df_verify) != 0);
1296 timevar_pop (TV_TODO);
1299 /* Verify invariants that should hold between passes. This is a place
1300 to put simple sanity checks. */
1302 static void
1303 verify_interpass_invariants (void)
1305 gcc_checking_assert (!fold_deferring_overflow_warnings_p ());
1308 /* Clear the last verified flag. */
1310 static void
1311 clear_last_verified (void *data ATTRIBUTE_UNUSED)
1313 cfun->last_verified = 0;
1316 /* Helper function. Verify that the properties has been turn into the
1317 properties expected by the pass. */
1319 #ifdef ENABLE_CHECKING
1320 static void
1321 verify_curr_properties (void *data)
1323 unsigned int props = (size_t)data;
1324 gcc_assert ((cfun->curr_properties & props) == props);
1326 #endif
1328 /* Initialize pass dump file. */
1329 /* This is non-static so that the plugins can use it. */
1331 bool
1332 pass_init_dump_file (struct opt_pass *pass)
1334 /* If a dump file name is present, open it if enabled. */
1335 if (pass->static_pass_number != -1)
1337 bool initializing_dump = !dump_initialized_p (pass->static_pass_number);
1338 dump_file_name = get_dump_file_name (pass->static_pass_number);
1339 dump_file = dump_begin (pass->static_pass_number, &dump_flags);
1340 if (dump_file && current_function_decl)
1342 const char *dname, *aname;
1343 struct cgraph_node *node = cgraph_node (current_function_decl);
1344 dname = lang_hooks.decl_printable_name (current_function_decl, 2);
1345 aname = (IDENTIFIER_POINTER
1346 (DECL_ASSEMBLER_NAME (current_function_decl)));
1347 fprintf (dump_file, "\n;; Function %s (%s)%s\n\n", dname, aname,
1348 node->frequency == NODE_FREQUENCY_HOT
1349 ? " (hot)"
1350 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
1351 ? " (unlikely executed)"
1352 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
1353 ? " (executed once)"
1354 : "");
1356 return initializing_dump;
1358 else
1359 return false;
1362 /* Flush PASS dump file. */
1363 /* This is non-static so that plugins can use it. */
1365 void
1366 pass_fini_dump_file (struct opt_pass *pass)
1368 /* Flush and close dump file. */
1369 if (dump_file_name)
1371 free (CONST_CAST (char *, dump_file_name));
1372 dump_file_name = NULL;
1375 if (dump_file)
1377 dump_end (pass->static_pass_number, dump_file);
1378 dump_file = NULL;
1382 /* After executing the pass, apply expected changes to the function
1383 properties. */
1385 static void
1386 update_properties_after_pass (void *data)
1388 struct opt_pass *pass = (struct opt_pass *) data;
1389 cfun->curr_properties = (cfun->curr_properties | pass->properties_provided)
1390 & ~pass->properties_destroyed;
1393 /* Execute summary generation for all of the passes in IPA_PASS. */
1395 void
1396 execute_ipa_summary_passes (struct ipa_opt_pass_d *ipa_pass)
1398 while (ipa_pass)
1400 struct opt_pass *pass = &ipa_pass->pass;
1402 /* Execute all of the IPA_PASSes in the list. */
1403 if (ipa_pass->pass.type == IPA_PASS
1404 && (!pass->gate || pass->gate ())
1405 && ipa_pass->generate_summary)
1407 pass_init_dump_file (pass);
1409 /* If a timevar is present, start it. */
1410 if (pass->tv_id)
1411 timevar_push (pass->tv_id);
1413 ipa_pass->generate_summary ();
1415 /* Stop timevar. */
1416 if (pass->tv_id)
1417 timevar_pop (pass->tv_id);
1419 pass_fini_dump_file (pass);
1421 ipa_pass = (struct ipa_opt_pass_d *)ipa_pass->pass.next;
1425 /* Execute IPA_PASS function transform on NODE. */
1427 static void
1428 execute_one_ipa_transform_pass (struct cgraph_node *node,
1429 struct ipa_opt_pass_d *ipa_pass)
1431 struct opt_pass *pass = &ipa_pass->pass;
1432 unsigned int todo_after = 0;
1434 current_pass = pass;
1435 if (!ipa_pass->function_transform)
1436 return;
1438 /* Note that the folders should only create gimple expressions.
1439 This is a hack until the new folder is ready. */
1440 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1442 pass_init_dump_file (pass);
1444 /* Run pre-pass verification. */
1445 execute_todo (ipa_pass->function_transform_todo_flags_start);
1447 /* If a timevar is present, start it. */
1448 if (pass->tv_id != TV_NONE)
1449 timevar_push (pass->tv_id);
1451 /* Do it! */
1452 todo_after = ipa_pass->function_transform (node);
1454 /* Stop timevar. */
1455 if (pass->tv_id != TV_NONE)
1456 timevar_pop (pass->tv_id);
1458 /* Run post-pass cleanup and verification. */
1459 execute_todo (todo_after);
1460 verify_interpass_invariants ();
1462 pass_fini_dump_file (pass);
1464 current_pass = NULL;
1467 /* For the current function, execute all ipa transforms. */
1469 void
1470 execute_all_ipa_transforms (void)
1472 struct cgraph_node *node;
1473 if (!cfun)
1474 return;
1475 node = cgraph_node (current_function_decl);
1477 if (node->ipa_transforms_to_apply)
1479 unsigned int i;
1481 for (i = 0; i < VEC_length (ipa_opt_pass, node->ipa_transforms_to_apply);
1482 i++)
1483 execute_one_ipa_transform_pass (node,
1484 VEC_index (ipa_opt_pass,
1485 node->ipa_transforms_to_apply,
1486 i));
1487 VEC_free (ipa_opt_pass, heap, node->ipa_transforms_to_apply);
1488 node->ipa_transforms_to_apply = NULL;
1492 /* Execute PASS. */
1494 bool
1495 execute_one_pass (struct opt_pass *pass)
1497 bool initializing_dump;
1498 unsigned int todo_after = 0;
1500 bool gate_status;
1502 /* IPA passes are executed on whole program, so cfun should be NULL.
1503 Other passes need function context set. */
1504 if (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS)
1505 gcc_assert (!cfun && !current_function_decl);
1506 else
1507 gcc_assert (cfun && current_function_decl);
1509 current_pass = pass;
1511 /* Check whether gate check should be avoided.
1512 User controls the value of the gate through the parameter "gate_status". */
1513 gate_status = (pass->gate == NULL) ? true : pass->gate();
1515 /* Override gate with plugin. */
1516 invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
1518 if (!gate_status)
1520 current_pass = NULL;
1521 return false;
1524 /* Pass execution event trigger: useful to identify passes being
1525 executed. */
1526 invoke_plugin_callbacks (PLUGIN_PASS_EXECUTION, pass);
1528 if (!quiet_flag && !cfun)
1529 fprintf (stderr, " <%s>", pass->name ? pass->name : "");
1531 /* Note that the folders should only create gimple expressions.
1532 This is a hack until the new folder is ready. */
1533 in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
1535 initializing_dump = pass_init_dump_file (pass);
1537 /* Run pre-pass verification. */
1538 execute_todo (pass->todo_flags_start);
1540 #ifdef ENABLE_CHECKING
1541 do_per_function (verify_curr_properties,
1542 (void *)(size_t)pass->properties_required);
1543 #endif
1545 /* If a timevar is present, start it. */
1546 if (pass->tv_id != TV_NONE)
1547 timevar_push (pass->tv_id);
1549 /* Do it! */
1550 if (pass->execute)
1552 todo_after = pass->execute ();
1553 do_per_function (clear_last_verified, NULL);
1556 /* Stop timevar. */
1557 if (pass->tv_id != TV_NONE)
1558 timevar_pop (pass->tv_id);
1560 do_per_function (update_properties_after_pass, pass);
1562 if (initializing_dump
1563 && dump_file
1564 && graph_dump_format != no_graph
1565 && cfun
1566 && (cfun->curr_properties & (PROP_cfg | PROP_rtl))
1567 == (PROP_cfg | PROP_rtl))
1569 get_dump_file_info (pass->static_pass_number)->flags |= TDF_GRAPH;
1570 dump_flags |= TDF_GRAPH;
1571 clean_graph_dump_file (dump_file_name);
1574 /* Run post-pass cleanup and verification. */
1575 execute_todo (todo_after | pass->todo_flags_finish);
1576 verify_interpass_invariants ();
1577 if (pass->type == IPA_PASS)
1579 struct cgraph_node *node;
1580 for (node = cgraph_nodes; node; node = node->next)
1581 if (node->analyzed)
1582 VEC_safe_push (ipa_opt_pass, heap, node->ipa_transforms_to_apply,
1583 (struct ipa_opt_pass_d *)pass);
1586 if (!current_function_decl)
1587 cgraph_process_new_functions ();
1589 pass_fini_dump_file (pass);
1591 if (pass->type != SIMPLE_IPA_PASS && pass->type != IPA_PASS)
1592 gcc_assert (!(cfun->curr_properties & PROP_trees)
1593 || pass->type != RTL_PASS);
1595 current_pass = NULL;
1597 return true;
1600 void
1601 execute_pass_list (struct opt_pass *pass)
1605 gcc_assert (pass->type == GIMPLE_PASS
1606 || pass->type == RTL_PASS);
1607 if (execute_one_pass (pass) && pass->sub)
1608 execute_pass_list (pass->sub);
1609 pass = pass->next;
1611 while (pass);
1614 /* Same as execute_pass_list but assume that subpasses of IPA passes
1615 are local passes. If SET is not NULL, write out summaries of only
1616 those node in SET. */
1618 static void
1619 ipa_write_summaries_2 (struct opt_pass *pass, cgraph_node_set set,
1620 varpool_node_set vset,
1621 struct lto_out_decl_state *state)
1623 while (pass)
1625 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
1626 gcc_assert (!current_function_decl);
1627 gcc_assert (!cfun);
1628 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1629 if (pass->type == IPA_PASS
1630 && ipa_pass->write_summary
1631 && (!pass->gate || pass->gate ()))
1633 /* If a timevar is present, start it. */
1634 if (pass->tv_id)
1635 timevar_push (pass->tv_id);
1637 pass_init_dump_file (pass);
1639 ipa_pass->write_summary (set,vset);
1641 pass_fini_dump_file (pass);
1643 /* If a timevar is present, start it. */
1644 if (pass->tv_id)
1645 timevar_pop (pass->tv_id);
1648 if (pass->sub && pass->sub->type != GIMPLE_PASS)
1649 ipa_write_summaries_2 (pass->sub, set, vset, state);
1651 pass = pass->next;
1655 /* Helper function of ipa_write_summaries. Creates and destroys the
1656 decl state and calls ipa_write_summaries_2 for all passes that have
1657 summaries. SET is the set of nodes to be written. */
1659 static void
1660 ipa_write_summaries_1 (cgraph_node_set set, varpool_node_set vset)
1662 struct lto_out_decl_state *state = lto_new_out_decl_state ();
1663 compute_ltrans_boundary (state, set, vset);
1665 lto_push_out_decl_state (state);
1667 gcc_assert (!flag_wpa);
1668 ipa_write_summaries_2 (all_regular_ipa_passes, set, vset, state);
1669 ipa_write_summaries_2 (all_lto_gen_passes, set, vset, state);
1671 gcc_assert (lto_get_out_decl_state () == state);
1672 lto_pop_out_decl_state ();
1673 lto_delete_out_decl_state (state);
1676 /* Write out summaries for all the nodes in the callgraph. */
1678 void
1679 ipa_write_summaries (void)
1681 cgraph_node_set set;
1682 varpool_node_set vset;
1683 struct cgraph_node **order;
1684 struct varpool_node *vnode;
1685 int i, order_pos;
1687 if (!flag_generate_lto || seen_error ())
1688 return;
1690 set = cgraph_node_set_new ();
1692 /* Create the callgraph set in the same order used in
1693 cgraph_expand_all_functions. This mostly facilitates debugging,
1694 since it causes the gimple file to be processed in the same order
1695 as the source code. */
1696 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
1697 order_pos = cgraph_postorder (order);
1698 gcc_assert (order_pos == cgraph_n_nodes);
1700 for (i = order_pos - 1; i >= 0; i--)
1702 struct cgraph_node *node = order[i];
1704 if (node->analyzed)
1706 /* When streaming out references to statements as part of some IPA
1707 pass summary, the statements need to have uids assigned and the
1708 following does that for all the IPA passes here. Naturally, this
1709 ordering then matches the one IPA-passes get in their stmt_fixup
1710 hooks. */
1712 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1713 renumber_gimple_stmt_uids ();
1714 pop_cfun ();
1716 if (node->analyzed)
1717 cgraph_node_set_add (set, node);
1719 vset = varpool_node_set_new ();
1721 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1722 if (vnode->needed && !vnode->alias)
1723 varpool_node_set_add (vset, vnode);
1725 ipa_write_summaries_1 (set, vset);
1727 free (order);
1728 ggc_free (set);
1729 ggc_free (vset);
1732 /* Same as execute_pass_list but assume that subpasses of IPA passes
1733 are local passes. If SET is not NULL, write out optimization summaries of
1734 only those node in SET. */
1736 static void
1737 ipa_write_optimization_summaries_1 (struct opt_pass *pass, cgraph_node_set set,
1738 varpool_node_set vset,
1739 struct lto_out_decl_state *state)
1741 while (pass)
1743 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *)pass;
1744 gcc_assert (!current_function_decl);
1745 gcc_assert (!cfun);
1746 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1747 if (pass->type == IPA_PASS
1748 && ipa_pass->write_optimization_summary
1749 && (!pass->gate || pass->gate ()))
1751 /* If a timevar is present, start it. */
1752 if (pass->tv_id)
1753 timevar_push (pass->tv_id);
1755 pass_init_dump_file (pass);
1757 ipa_pass->write_optimization_summary (set, vset);
1759 pass_fini_dump_file (pass);
1761 /* If a timevar is present, start it. */
1762 if (pass->tv_id)
1763 timevar_pop (pass->tv_id);
1766 if (pass->sub && pass->sub->type != GIMPLE_PASS)
1767 ipa_write_optimization_summaries_1 (pass->sub, set, vset, state);
1769 pass = pass->next;
1773 /* Write all the optimization summaries for the cgraph nodes in SET. If SET is
1774 NULL, write out all summaries of all nodes. */
1776 void
1777 ipa_write_optimization_summaries (cgraph_node_set set, varpool_node_set vset)
1779 struct lto_out_decl_state *state = lto_new_out_decl_state ();
1780 cgraph_node_set_iterator csi;
1781 compute_ltrans_boundary (state, set, vset);
1783 lto_push_out_decl_state (state);
1784 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
1786 struct cgraph_node *node = csi_node (csi);
1787 /* When streaming out references to statements as part of some IPA
1788 pass summary, the statements need to have uids assigned.
1790 For functions newly born at WPA stage we need to initialize
1791 the uids here. */
1792 if (node->analyzed
1793 && gimple_has_body_p (node->decl))
1795 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1796 renumber_gimple_stmt_uids ();
1797 pop_cfun ();
1801 gcc_assert (flag_wpa);
1802 ipa_write_optimization_summaries_1 (all_regular_ipa_passes, set, vset, state);
1803 ipa_write_optimization_summaries_1 (all_lto_gen_passes, set, vset, state);
1805 gcc_assert (lto_get_out_decl_state () == state);
1806 lto_pop_out_decl_state ();
1807 lto_delete_out_decl_state (state);
1810 /* Same as execute_pass_list but assume that subpasses of IPA passes
1811 are local passes. */
1813 static void
1814 ipa_read_summaries_1 (struct opt_pass *pass)
1816 while (pass)
1818 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
1820 gcc_assert (!current_function_decl);
1821 gcc_assert (!cfun);
1822 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1824 if (pass->gate == NULL || pass->gate ())
1826 if (pass->type == IPA_PASS && ipa_pass->read_summary)
1828 /* If a timevar is present, start it. */
1829 if (pass->tv_id)
1830 timevar_push (pass->tv_id);
1832 pass_init_dump_file (pass);
1834 ipa_pass->read_summary ();
1836 pass_fini_dump_file (pass);
1838 /* Stop timevar. */
1839 if (pass->tv_id)
1840 timevar_pop (pass->tv_id);
1843 if (pass->sub && pass->sub->type != GIMPLE_PASS)
1844 ipa_read_summaries_1 (pass->sub);
1846 pass = pass->next;
1851 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
1853 void
1854 ipa_read_summaries (void)
1856 ipa_read_summaries_1 (all_regular_ipa_passes);
1857 ipa_read_summaries_1 (all_lto_gen_passes);
1860 /* Same as execute_pass_list but assume that subpasses of IPA passes
1861 are local passes. */
1863 static void
1864 ipa_read_optimization_summaries_1 (struct opt_pass *pass)
1866 while (pass)
1868 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
1870 gcc_assert (!current_function_decl);
1871 gcc_assert (!cfun);
1872 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1874 if (pass->gate == NULL || pass->gate ())
1876 if (pass->type == IPA_PASS && ipa_pass->read_optimization_summary)
1878 /* If a timevar is present, start it. */
1879 if (pass->tv_id)
1880 timevar_push (pass->tv_id);
1882 pass_init_dump_file (pass);
1884 ipa_pass->read_optimization_summary ();
1886 pass_fini_dump_file (pass);
1888 /* Stop timevar. */
1889 if (pass->tv_id)
1890 timevar_pop (pass->tv_id);
1893 if (pass->sub && pass->sub->type != GIMPLE_PASS)
1894 ipa_read_optimization_summaries_1 (pass->sub);
1896 pass = pass->next;
1900 /* Read all the summaries for all_regular_ipa_passes and all_lto_gen_passes. */
1902 void
1903 ipa_read_optimization_summaries (void)
1905 ipa_read_optimization_summaries_1 (all_regular_ipa_passes);
1906 ipa_read_optimization_summaries_1 (all_lto_gen_passes);
1909 /* Same as execute_pass_list but assume that subpasses of IPA passes
1910 are local passes. */
1911 void
1912 execute_ipa_pass_list (struct opt_pass *pass)
1916 gcc_assert (!current_function_decl);
1917 gcc_assert (!cfun);
1918 gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
1919 if (execute_one_pass (pass) && pass->sub)
1921 if (pass->sub->type == GIMPLE_PASS)
1923 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
1924 do_per_function_toporder ((void (*)(void *))execute_pass_list,
1925 pass->sub);
1926 invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
1928 else if (pass->sub->type == SIMPLE_IPA_PASS
1929 || pass->sub->type == IPA_PASS)
1930 execute_ipa_pass_list (pass->sub);
1931 else
1932 gcc_unreachable ();
1934 gcc_assert (!current_function_decl);
1935 cgraph_process_new_functions ();
1936 pass = pass->next;
1938 while (pass);
1941 /* Execute stmt fixup hooks of all passes in PASS for NODE and STMTS. */
1943 static void
1944 execute_ipa_stmt_fixups (struct opt_pass *pass,
1945 struct cgraph_node *node, gimple *stmts)
1947 while (pass)
1949 /* Execute all of the IPA_PASSes in the list. */
1950 if (pass->type == IPA_PASS
1951 && (!pass->gate || pass->gate ()))
1953 struct ipa_opt_pass_d *ipa_pass = (struct ipa_opt_pass_d *) pass;
1955 if (ipa_pass->stmt_fixup)
1957 pass_init_dump_file (pass);
1958 /* If a timevar is present, start it. */
1959 if (pass->tv_id)
1960 timevar_push (pass->tv_id);
1962 ipa_pass->stmt_fixup (node, stmts);
1964 /* Stop timevar. */
1965 if (pass->tv_id)
1966 timevar_pop (pass->tv_id);
1967 pass_fini_dump_file (pass);
1969 if (pass->sub)
1970 execute_ipa_stmt_fixups (pass->sub, node, stmts);
1972 pass = pass->next;
1976 /* Execute stmt fixup hooks of all IPA passes for NODE and STMTS. */
1978 void
1979 execute_all_ipa_stmt_fixups (struct cgraph_node *node, gimple *stmts)
1981 execute_ipa_stmt_fixups (all_regular_ipa_passes, node, stmts);
1985 extern void debug_properties (unsigned int);
1986 extern void dump_properties (FILE *, unsigned int);
1988 DEBUG_FUNCTION void
1989 dump_properties (FILE *dump, unsigned int props)
1991 fprintf (dump, "Properties:\n");
1992 if (props & PROP_gimple_any)
1993 fprintf (dump, "PROP_gimple_any\n");
1994 if (props & PROP_gimple_lcf)
1995 fprintf (dump, "PROP_gimple_lcf\n");
1996 if (props & PROP_gimple_leh)
1997 fprintf (dump, "PROP_gimple_leh\n");
1998 if (props & PROP_cfg)
1999 fprintf (dump, "PROP_cfg\n");
2000 if (props & PROP_referenced_vars)
2001 fprintf (dump, "PROP_referenced_vars\n");
2002 if (props & PROP_ssa)
2003 fprintf (dump, "PROP_ssa\n");
2004 if (props & PROP_no_crit_edges)
2005 fprintf (dump, "PROP_no_crit_edges\n");
2006 if (props & PROP_rtl)
2007 fprintf (dump, "PROP_rtl\n");
2008 if (props & PROP_gimple_lomp)
2009 fprintf (dump, "PROP_gimple_lomp\n");
2010 if (props & PROP_gimple_lcx)
2011 fprintf (dump, "PROP_gimple_lcx\n");
2012 if (props & PROP_cfglayout)
2013 fprintf (dump, "PROP_cfglayout\n");
2016 DEBUG_FUNCTION void
2017 debug_properties (unsigned int props)
2019 dump_properties (stderr, props);
2022 /* Called by local passes to see if function is called by already processed nodes.
2023 Because we process nodes in topological order, this means that function is
2024 in recursive cycle or we introduced new direct calls. */
2025 bool
2026 function_called_by_processed_nodes_p (void)
2028 struct cgraph_edge *e;
2029 for (e = cgraph_node (current_function_decl)->callers; e; e = e->next_caller)
2031 if (e->caller->decl == current_function_decl)
2032 continue;
2033 if (!e->caller->analyzed)
2034 continue;
2035 if (TREE_ASM_WRITTEN (e->caller->decl))
2036 continue;
2037 if (!e->caller->process && !e->caller->global.inlined_to)
2038 break;
2040 if (dump_file && e)
2042 fprintf (dump_file, "Already processed call to:\n");
2043 dump_cgraph_node (dump_file, e->caller);
2045 return e != NULL;
2048 #include "gt-passes.h"