tree-ssa-threadupdate.c: Include tree-cfg.h and tree-pass.h
[official-gcc.git] / gcc / lto-opts.c
blob2cb536bfc558bba9887cc557e3ee1065fd226201
1 /* LTO IL options.
3 Copyright (C) 2009-2013 Free Software Foundation, Inc.
4 Contributed by Simon Baldwin <simonb@google.com>
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 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "gimple.h"
27 #include "hashtab.h"
28 #include "ggc.h"
29 #include "vec.h"
30 #include "bitmap.h"
31 #include "flags.h"
32 #include "opts.h"
33 #include "options.h"
34 #include "common/common-target.h"
35 #include "diagnostic.h"
36 #include "lto-streamer.h"
37 #include "toplev.h"
39 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
40 set up by OB, appropriately quoted and separated by spaces
41 (if !*FIRST_P). */
43 static void
44 append_to_collect_gcc_options (struct obstack *ob,
45 bool *first_p, const char *opt)
47 const char *p, *q = opt;
48 if (!*first_p)
49 obstack_grow (ob, " ", 1);
50 obstack_grow (ob, "'", 1);
51 while ((p = strchr (q, '\'')))
53 obstack_grow (ob, q, p - q);
54 obstack_grow (ob, "'\\''", 4);
55 q = ++p;
57 obstack_grow (ob, q, strlen (q));
58 obstack_grow (ob, "'", 1);
59 *first_p = false;
62 /* Write currently held options to an LTO IL section. */
64 void
65 lto_write_options (void)
67 struct lto_output_stream stream;
68 char *section_name;
69 struct obstack temporary_obstack;
70 unsigned int i, j;
71 char *args;
72 bool first_p = true;
74 section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
75 lto_begin_section (section_name, false);
76 memset (&stream, 0, sizeof (stream));
78 obstack_init (&temporary_obstack);
80 /* Output options that affect GIMPLE IL semantics and are implicitly
81 enabled by the frontend.
82 This for now includes an explicit set of options that we also handle
83 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
84 semantics should be explicitely encoded in the IL or saved per
85 function rather than per compilation unit. */
86 /* -fexceptions causes the EH machinery to be initialized, enabling
87 generation of unwind data so that explicit throw() calls work. */
88 if (!global_options_set.x_flag_exceptions
89 && global_options.x_flag_exceptions)
90 append_to_collect_gcc_options (&temporary_obstack, &first_p,
91 "-fexceptions");
92 /* -fnon-call-exceptions changes the generation of exception
93 regions. It is enabled implicitly by the Go frontend. */
94 if (!global_options_set.x_flag_non_call_exceptions
95 && global_options.x_flag_non_call_exceptions)
96 append_to_collect_gcc_options (&temporary_obstack, &first_p,
97 "-fnon-call-exceptions");
98 /* The default -ffp-contract changes depending on the language
99 standard. Pass thru conservative standard settings. */
100 if (!global_options_set.x_flag_fp_contract_mode)
101 switch (global_options.x_flag_fp_contract_mode)
103 case FP_CONTRACT_OFF:
104 append_to_collect_gcc_options (&temporary_obstack, &first_p,
105 "-ffp-contract=off");
106 break;
107 case FP_CONTRACT_ON:
108 append_to_collect_gcc_options (&temporary_obstack, &first_p,
109 "-ffp-contract=on");
110 break;
111 case FP_CONTRACT_FAST:
112 /* Nothing. That merges conservatively and is the default for LTO. */
113 break;
114 default:
115 gcc_unreachable ();
118 /* Output explicitly passed options. */
119 for (i = 1; i < save_decoded_options_count; ++i)
121 struct cl_decoded_option *option = &save_decoded_options[i];
123 /* Skip explicitly some common options that we do not need. */
124 switch (option->opt_index)
126 case OPT_dumpbase:
127 case OPT_SPECIAL_unknown:
128 case OPT_SPECIAL_ignore:
129 case OPT_SPECIAL_program_name:
130 case OPT_SPECIAL_input_file:
131 continue;
133 default:
134 break;
137 /* Skip frontend and driver specific options here. */
138 if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
139 continue;
141 /* Drop options created from the gcc driver that will be rejected
142 when passed on to the driver again. */
143 if (cl_options[option->opt_index].cl_reject_driver)
144 continue;
146 /* Also drop all options that are handled by the driver as well,
147 which includes things like -o and -v or -fhelp for example.
148 We do not need those. Also drop all diagnostic options. */
149 if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
150 continue;
152 for (j = 0; j < option->canonical_option_num_elements; ++j)
153 append_to_collect_gcc_options (&temporary_obstack, &first_p,
154 option->canonical_option[j]);
156 obstack_grow (&temporary_obstack, "\0", 1);
157 args = XOBFINISH (&temporary_obstack, char *);
158 lto_output_data_stream (&stream, args, strlen (args) + 1);
160 lto_write_stream (&stream);
161 lto_end_section ();
163 obstack_free (&temporary_obstack, NULL);
164 free (section_name);