]>
Commit | Line | Data |
---|---|---|
d7f09764 DN |
1 | /* LTO IL options. |
2 | ||
8d9254fc | 3 | Copyright (C) 2009-2020 Free Software Foundation, Inc. |
d7f09764 DN |
4 | Contributed by Simon Baldwin <simonb@google.com> |
5 | ||
6 | This file is part of GCC. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
c7131fb2 | 25 | #include "backend.h" |
957060b5 | 26 | #include "target.h" |
40e23961 | 27 | #include "tree.h" |
c7131fb2 | 28 | #include "gimple.h" |
957060b5 AM |
29 | #include "cgraph.h" |
30 | #include "lto-streamer.h" | |
d7f09764 | 31 | #include "opts.h" |
52a35ef7 | 32 | #include "toplev.h" |
d7f09764 | 33 | |
a456676f RG |
34 | /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string |
35 | set up by OB, appropriately quoted and separated by spaces | |
36 | (if !*FIRST_P). */ | |
37 | ||
38 | static void | |
39 | append_to_collect_gcc_options (struct obstack *ob, | |
40 | bool *first_p, const char *opt) | |
41 | { | |
42 | const char *p, *q = opt; | |
0b8c30f9 | 43 | if (!*first_p) |
a456676f RG |
44 | obstack_grow (ob, " ", 1); |
45 | obstack_grow (ob, "'", 1); | |
46 | while ((p = strchr (q, '\''))) | |
47 | { | |
48 | obstack_grow (ob, q, p - q); | |
49 | obstack_grow (ob, "'\\''", 4); | |
50 | q = ++p; | |
51 | } | |
52 | obstack_grow (ob, q, strlen (q)); | |
53 | obstack_grow (ob, "'", 1); | |
54 | *first_p = false; | |
55 | } | |
56 | ||
d7f09764 DN |
57 | /* Write currently held options to an LTO IL section. */ |
58 | ||
59 | void | |
60 | lto_write_options (void) | |
61 | { | |
52a35ef7 RG |
62 | char *section_name; |
63 | struct obstack temporary_obstack; | |
64 | unsigned int i, j; | |
65 | char *args; | |
a456676f | 66 | bool first_p = true; |
d7f09764 | 67 | |
3c56d8d8 | 68 | section_name = lto_get_section_name (LTO_section_opts, NULL, 0, NULL); |
52a35ef7 | 69 | lto_begin_section (section_name, false); |
d7f09764 | 70 | |
52a35ef7 | 71 | obstack_init (&temporary_obstack); |
a456676f | 72 | |
1506ae0e TV |
73 | if (!global_options_set.x_flag_openmp |
74 | && !global_options.x_flag_openmp) | |
2f02b2c2 EB |
75 | append_to_collect_gcc_options (&temporary_obstack, &first_p, |
76 | "-fno-openmp"); | |
a0c88d06 TV |
77 | if (!global_options_set.x_flag_openacc |
78 | && !global_options.x_flag_openacc) | |
79 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
80 | "-fno-openacc"); | |
4e6a9380 JH |
81 | /* Append PIC/PIE mode because its default depends on target and it is |
82 | subject of merging in lto-wrapper. */ | |
83 | if (!global_options_set.x_flag_pic && !global_options_set.x_flag_pie) | |
84 | { | |
85 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
86 | global_options.x_flag_pic == 2 | |
87 | ? "-fPIC" | |
88 | : global_options.x_flag_pic == 1 | |
89 | ? "-fpic" | |
90 | : global_options.x_flag_pie == 2 | |
91 | ? "-fPIE" | |
92 | : global_options.x_flag_pie == 1 | |
93 | ? "-fpie" | |
94 | : "-fno-pie"); | |
95 | } | |
1506ae0e | 96 | |
5a307ee5 RB |
97 | /* If debug info is enabled append -g. */ |
98 | if (debug_info_level > DINFO_LEVEL_NONE) | |
99 | append_to_collect_gcc_options (&temporary_obstack, &first_p, "-g"); | |
100 | ||
c713ddc0 | 101 | /* Append options from target hook and store them to offload_lto section. */ |
1b34e6e2 | 102 | if (lto_stream_offload_p) |
c713ddc0 BS |
103 | { |
104 | char *offload_opts = targetm.offload_options (); | |
105 | char *offload_ptr = offload_opts; | |
106 | while (offload_ptr) | |
107 | { | |
108 | char *next = strchr (offload_ptr, ' '); | |
109 | if (next) | |
110 | *next++ = '\0'; | |
111 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
112 | offload_ptr); | |
113 | offload_ptr = next; | |
114 | } | |
115 | free (offload_opts); | |
116 | } | |
117 | ||
2a5145b0 | 118 | /* Output explicitly passed options. */ |
52a35ef7 | 119 | for (i = 1; i < save_decoded_options_count; ++i) |
d7f09764 | 120 | { |
52a35ef7 | 121 | struct cl_decoded_option *option = &save_decoded_options[i]; |
52a35ef7 | 122 | |
169d8507 L |
123 | /* Skip explicitly some common options that we do not need. */ |
124 | switch (option->opt_index) | |
125 | { | |
126 | case OPT_dumpbase: | |
127 | case OPT_SPECIAL_unknown: | |
128 | case OPT_SPECIAL_ignore: | |
68a57628 | 129 | case OPT_SPECIAL_warn_removed: |
169d8507 L |
130 | case OPT_SPECIAL_program_name: |
131 | case OPT_SPECIAL_input_file: | |
6c363ddd JH |
132 | case OPT_dumpdir: |
133 | case OPT_fresolution_: | |
d1215304 RB |
134 | case OPT_fdebug_prefix_map_: |
135 | case OPT_ffile_prefix_map_: | |
136 | case OPT_fmacro_prefix_map_: | |
169d8507 L |
137 | continue; |
138 | ||
139 | default: | |
140 | break; | |
141 | } | |
142 | ||
52a35ef7 RG |
143 | /* Skip frontend and driver specific options here. */ |
144 | if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO))) | |
145 | continue; | |
146 | ||
c713ddc0 BS |
147 | /* Do not store target-specific options in offload_lto section. */ |
148 | if ((cl_options[option->opt_index].flags & CL_TARGET) | |
1b34e6e2 | 149 | && lto_stream_offload_p) |
c713ddc0 BS |
150 | continue; |
151 | ||
52a35ef7 RG |
152 | /* Drop options created from the gcc driver that will be rejected |
153 | when passed on to the driver again. */ | |
154 | if (cl_options[option->opt_index].cl_reject_driver) | |
155 | continue; | |
156 | ||
157 | /* Also drop all options that are handled by the driver as well, | |
c713ddc0 BS |
158 | which includes things like -o and -v or -fhelp for example. |
159 | We do not need those. The only exception is -foffload option, if we | |
160 | write it in offload_lto section. Also drop all diagnostic options. */ | |
161 | if ((cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING)) | |
1b34e6e2 | 162 | && (!lto_stream_offload_p || option->opt_index != OPT_foffload_)) |
52a35ef7 RG |
163 | continue; |
164 | ||
a456676f RG |
165 | for (j = 0; j < option->canonical_option_num_elements; ++j) |
166 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
167 | option->canonical_option[j]); | |
d7f09764 | 168 | } |
f1a681a1 PK |
169 | |
170 | const char *collect_as_options = getenv ("COLLECT_AS_OPTIONS"); | |
171 | if (collect_as_options) | |
172 | prepend_xassembler_to_collect_as_options (collect_as_options, | |
173 | &temporary_obstack); | |
174 | ||
52a35ef7 RG |
175 | obstack_grow (&temporary_obstack, "\0", 1); |
176 | args = XOBFINISH (&temporary_obstack, char *); | |
f6bcdb5e | 177 | lto_write_data (args, strlen (args) + 1); |
52a35ef7 RG |
178 | lto_end_section (); |
179 | ||
180 | obstack_free (&temporary_obstack, NULL); | |
181 | free (section_name); | |
d7f09764 | 182 | } |