2013-10-11 Marc Glisse <marc.glisse@inria.fr>
[official-gcc.git] / gcc / tree-optimize.c
blobd823dbed412d98188321cd1ffb8327b5da71c2f0
1 /* Top-level control of tree optimizations.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "tm_p.h"
27 #include "basic-block.h"
28 #include "flags.h"
29 #include "tree-ssa.h"
30 #include "function.h"
31 #include "langhooks.h"
32 #include "diagnostic-core.h"
33 #include "toplev.h"
34 #include "flags.h"
35 #include "cgraph.h"
36 #include "tree-inline.h"
37 #include "tree-pass.h"
38 #include "ggc.h"
39 #include "cgraph.h"
40 #include "cfgloop.h"
41 #include "except.h"
42 #include "plugin.h"
45 /* Pass: cleanup the CFG just before expanding trees to RTL.
46 This is just a round of label cleanups and case node grouping
47 because after the tree optimizers have run such cleanups may
48 be necessary. */
50 static unsigned int
51 execute_cleanup_cfg_post_optimizing (void)
53 unsigned int todo = 0;
54 if (cleanup_tree_cfg ())
55 todo |= TODO_update_ssa;
56 maybe_remove_unreachable_handlers ();
57 cleanup_dead_labels ();
58 group_case_labels ();
59 if ((flag_compare_debug_opt || flag_compare_debug)
60 && flag_dump_final_insns)
62 FILE *final_output = fopen (flag_dump_final_insns, "a");
64 if (!final_output)
66 error ("could not open final insn dump file %qs: %m",
67 flag_dump_final_insns);
68 flag_dump_final_insns = NULL;
70 else
72 int save_unnumbered = flag_dump_unnumbered;
73 int save_noaddr = flag_dump_noaddr;
75 flag_dump_noaddr = flag_dump_unnumbered = 1;
76 fprintf (final_output, "\n");
77 dump_enumerated_decls (final_output, dump_flags | TDF_NOUID);
78 flag_dump_noaddr = save_noaddr;
79 flag_dump_unnumbered = save_unnumbered;
80 if (fclose (final_output))
82 error ("could not close final insn dump file %qs: %m",
83 flag_dump_final_insns);
84 flag_dump_final_insns = NULL;
88 return todo;
91 namespace {
93 const pass_data pass_data_cleanup_cfg_post_optimizing =
95 GIMPLE_PASS, /* type */
96 "optimized", /* name */
97 OPTGROUP_NONE, /* optinfo_flags */
98 false, /* has_gate */
99 true, /* has_execute */
100 TV_TREE_CLEANUP_CFG, /* tv_id */
101 PROP_cfg, /* properties_required */
102 0, /* properties_provided */
103 0, /* properties_destroyed */
104 0, /* todo_flags_start */
105 TODO_remove_unused_locals, /* todo_flags_finish */
108 class pass_cleanup_cfg_post_optimizing : public gimple_opt_pass
110 public:
111 pass_cleanup_cfg_post_optimizing (gcc::context *ctxt)
112 : gimple_opt_pass (pass_data_cleanup_cfg_post_optimizing, ctxt)
115 /* opt_pass methods: */
116 unsigned int execute () {
117 return execute_cleanup_cfg_post_optimizing ();
120 }; // class pass_cleanup_cfg_post_optimizing
122 } // anon namespace
124 gimple_opt_pass *
125 make_pass_cleanup_cfg_post_optimizing (gcc::context *ctxt)
127 return new pass_cleanup_cfg_post_optimizing (ctxt);