]>
Commit | Line | Data |
---|---|---|
7bfefa9d | 1 | /* LTO IL options. |
2 | ||
fbd26352 | 3 | Copyright (C) 2009-2019 Free Software Foundation, Inc. |
7bfefa9d | 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" | |
9ef16211 | 25 | #include "backend.h" |
7c29e30e | 26 | #include "target.h" |
b20a8bb4 | 27 | #include "tree.h" |
9ef16211 | 28 | #include "gimple.h" |
7c29e30e | 29 | #include "cgraph.h" |
30 | #include "lto-streamer.h" | |
7bfefa9d | 31 | #include "opts.h" |
954825c9 | 32 | #include "toplev.h" |
7bfefa9d | 33 | |
f0284264 | 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; | |
883554eb | 43 | if (!*first_p) |
f0284264 | 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 | ||
7bfefa9d | 57 | /* Write currently held options to an LTO IL section. */ |
58 | ||
59 | void | |
60 | lto_write_options (void) | |
61 | { | |
954825c9 | 62 | char *section_name; |
63 | struct obstack temporary_obstack; | |
64 | unsigned int i, j; | |
65 | char *args; | |
f0284264 | 66 | bool first_p = true; |
7bfefa9d | 67 | |
954825c9 | 68 | section_name = lto_get_section_name (LTO_section_opts, NULL, NULL); |
69 | lto_begin_section (section_name, false); | |
7bfefa9d | 70 | |
954825c9 | 71 | obstack_init (&temporary_obstack); |
f0284264 | 72 | |
fa175926 | 73 | if (!global_options_set.x_flag_openmp |
74 | && !global_options.x_flag_openmp) | |
fa48a8cb | 75 | append_to_collect_gcc_options (&temporary_obstack, &first_p, |
76 | "-fno-openmp"); | |
85977647 | 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"); | |
995068e4 | 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 | } | |
fa175926 | 96 | |
38e21583 | 97 | /* Append options from target hook and store them to offload_lto section. */ |
ba000093 | 98 | if (lto_stream_offload_p) |
38e21583 | 99 | { |
100 | char *offload_opts = targetm.offload_options (); | |
101 | char *offload_ptr = offload_opts; | |
102 | while (offload_ptr) | |
103 | { | |
104 | char *next = strchr (offload_ptr, ' '); | |
105 | if (next) | |
106 | *next++ = '\0'; | |
107 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
108 | offload_ptr); | |
109 | offload_ptr = next; | |
110 | } | |
111 | free (offload_opts); | |
112 | } | |
113 | ||
8eabe518 | 114 | /* Output explicitly passed options. */ |
954825c9 | 115 | for (i = 1; i < save_decoded_options_count; ++i) |
7bfefa9d | 116 | { |
954825c9 | 117 | struct cl_decoded_option *option = &save_decoded_options[i]; |
954825c9 | 118 | |
645c2597 | 119 | /* Skip explicitly some common options that we do not need. */ |
120 | switch (option->opt_index) | |
121 | { | |
122 | case OPT_dumpbase: | |
123 | case OPT_SPECIAL_unknown: | |
124 | case OPT_SPECIAL_ignore: | |
0c46a085 | 125 | case OPT_SPECIAL_deprecated: |
645c2597 | 126 | case OPT_SPECIAL_program_name: |
127 | case OPT_SPECIAL_input_file: | |
1b350e37 | 128 | case OPT_dumpdir: |
129 | case OPT_fresolution_: | |
645c2597 | 130 | continue; |
131 | ||
132 | default: | |
133 | break; | |
134 | } | |
135 | ||
954825c9 | 136 | /* Skip frontend and driver specific options here. */ |
137 | if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO))) | |
138 | continue; | |
139 | ||
38e21583 | 140 | /* Do not store target-specific options in offload_lto section. */ |
141 | if ((cl_options[option->opt_index].flags & CL_TARGET) | |
ba000093 | 142 | && lto_stream_offload_p) |
38e21583 | 143 | continue; |
144 | ||
954825c9 | 145 | /* Drop options created from the gcc driver that will be rejected |
146 | when passed on to the driver again. */ | |
147 | if (cl_options[option->opt_index].cl_reject_driver) | |
148 | continue; | |
149 | ||
150 | /* Also drop all options that are handled by the driver as well, | |
38e21583 | 151 | which includes things like -o and -v or -fhelp for example. |
152 | We do not need those. The only exception is -foffload option, if we | |
153 | write it in offload_lto section. Also drop all diagnostic options. */ | |
154 | if ((cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING)) | |
ba000093 | 155 | && (!lto_stream_offload_p || option->opt_index != OPT_foffload_)) |
954825c9 | 156 | continue; |
157 | ||
f0284264 | 158 | for (j = 0; j < option->canonical_option_num_elements; ++j) |
159 | append_to_collect_gcc_options (&temporary_obstack, &first_p, | |
160 | option->canonical_option[j]); | |
7bfefa9d | 161 | } |
954825c9 | 162 | obstack_grow (&temporary_obstack, "\0", 1); |
163 | args = XOBFINISH (&temporary_obstack, char *); | |
2d97af95 | 164 | lto_write_data (args, strlen (args) + 1); |
954825c9 | 165 | lto_end_section (); |
166 | ||
167 | obstack_free (&temporary_obstack, NULL); | |
168 | free (section_name); | |
7bfefa9d | 169 | } |