]>
Commit | Line | Data |
---|---|---|
1 | /* Common hooks for IBM RS/6000. | |
2 | Copyright (C) 1991-2024 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published | |
8 | by the Free Software Foundation; either version 3, or (at your | |
9 | option) any later version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT | |
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
13 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
14 | License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
23 | #include "diagnostic-core.h" | |
24 | #include "tm.h" | |
25 | #include "common/common-target.h" | |
26 | #include "common/common-target-def.h" | |
27 | #include "opts.h" | |
28 | #include "flags.h" | |
29 | ||
30 | /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */ | |
31 | static const struct default_options rs6000_option_optimization_table[] = | |
32 | { | |
33 | /* Split multi-word types early. */ | |
34 | { OPT_LEVELS_ALL, OPT_fsplit_wide_types_early, NULL, 1 }, | |
35 | /* Enable -fsched-pressure for first pass instruction scheduling. */ | |
36 | { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 }, | |
37 | /* Enable -free for zero extension and sign extension elimination.*/ | |
38 | { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 }, | |
39 | /* Enable -munroll-only-small-loops with -funroll-loops to unroll small | |
40 | loops at -O2 and above by default. */ | |
41 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_funroll_loops, NULL, 1 }, | |
42 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_munroll_only_small_loops, NULL, 1 }, | |
43 | ||
44 | /* -frename-registers leads to non-optimal codegen and performance | |
45 | on rs6000, turn it off by default. */ | |
46 | { OPT_LEVELS_ALL, OPT_frename_registers, NULL, 0 }, | |
47 | ||
48 | /* Double growth factor to counter reduced min jump length. */ | |
49 | { OPT_LEVELS_ALL, OPT__param_max_grow_copy_bb_insns_, NULL, 16 }, | |
50 | { OPT_LEVELS_NONE, 0, NULL, 0 } | |
51 | }; | |
52 | ||
53 | /* Implement TARGET_OPTION_INIT_STRUCT. */ | |
54 | ||
55 | static void | |
56 | rs6000_option_init_struct (struct gcc_options *opts) | |
57 | { | |
58 | if (DEFAULT_ABI == ABI_DARWIN) | |
59 | /* The Darwin libraries never set errno, so we might as well | |
60 | avoid calling them when that's the only reason we would. */ | |
61 | opts->x_flag_errno_math = 0; | |
62 | ||
63 | /* Enable section anchors by default. */ | |
64 | if (!TARGET_MACHO) | |
65 | opts->x_flag_section_anchors = 1; | |
66 | ||
67 | /* By default, always emit DWARF-2 unwind info. This allows debugging | |
68 | without maintaining a stack frame back-chain. It also allows the | |
69 | debugger to find out where on-entry register values are stored at any | |
70 | point in a function, without having to analyze the executable code (which | |
71 | isn't even possible to do in the general case). */ | |
72 | #ifdef OBJECT_FORMAT_ELF | |
73 | opts->x_flag_asynchronous_unwind_tables = 1; | |
74 | #endif | |
75 | } | |
76 | ||
77 | /* If not otherwise specified by a target, make 'long double' equivalent to | |
78 | 'double'. */ | |
79 | ||
80 | #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE | |
81 | #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64 | |
82 | #endif | |
83 | ||
84 | /* Implement TARGET_HANDLE_OPTION. */ | |
85 | ||
86 | static bool | |
87 | rs6000_handle_option (struct gcc_options *opts, struct gcc_options *opts_set, | |
88 | const struct cl_decoded_option *decoded, | |
89 | location_t loc) | |
90 | { | |
91 | char *p, *q; | |
92 | size_t code = decoded->opt_index; | |
93 | const char *arg = decoded->arg; | |
94 | int value = decoded->value; | |
95 | ||
96 | switch (code) | |
97 | { | |
98 | case OPT_mfull_toc: | |
99 | opts->x_rs6000_isa_flags &= ~OPTION_MASK_MINIMAL_TOC; | |
100 | opts->x_TARGET_NO_FP_IN_TOC = 0; | |
101 | opts->x_TARGET_NO_SUM_IN_TOC = 0; | |
102 | opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
103 | #ifdef TARGET_USES_SYSV4_OPT | |
104 | /* Note, V.4 no longer uses a normal TOC, so make -mfull-toc, be | |
105 | just the same as -mminimal-toc. */ | |
106 | opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
107 | opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
108 | #endif | |
109 | break; | |
110 | ||
111 | #ifdef TARGET_USES_SYSV4_OPT | |
112 | case OPT_mtoc: | |
113 | /* Make -mtoc behave like -mminimal-toc. */ | |
114 | opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
115 | opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
116 | break; | |
117 | #endif | |
118 | ||
119 | #ifdef TARGET_USES_AIX64_OPT | |
120 | case OPT_maix64: | |
121 | #else | |
122 | case OPT_m64: | |
123 | #endif | |
124 | opts->x_rs6000_isa_flags |= (~opts_set->x_rs6000_isa_flags | |
125 | & OPTION_MASK_PPC_GFXOPT); | |
126 | break; | |
127 | ||
128 | case OPT_mminimal_toc: | |
129 | if (value == 1) | |
130 | { | |
131 | opts->x_TARGET_NO_FP_IN_TOC = 0; | |
132 | opts->x_TARGET_NO_SUM_IN_TOC = 0; | |
133 | } | |
134 | break; | |
135 | ||
136 | case OPT_mpowerpc_gpopt: | |
137 | case OPT_mpowerpc_gfxopt: | |
138 | break; | |
139 | ||
140 | case OPT_mdebug_: | |
141 | p = ASTRDUP (arg); | |
142 | opts->x_rs6000_debug = 0; | |
143 | ||
144 | while ((q = strtok (p, ",")) != NULL) | |
145 | { | |
146 | unsigned mask = 0; | |
147 | bool invert; | |
148 | ||
149 | p = NULL; | |
150 | if (*q == '!') | |
151 | { | |
152 | invert = true; | |
153 | q++; | |
154 | } | |
155 | else | |
156 | invert = false; | |
157 | ||
158 | if (! strcmp (q, "all")) | |
159 | mask = MASK_DEBUG_ALL; | |
160 | else if (! strcmp (q, "stack")) | |
161 | mask = MASK_DEBUG_STACK; | |
162 | else if (! strcmp (q, "arg")) | |
163 | mask = MASK_DEBUG_ARG; | |
164 | else if (! strcmp (q, "reg")) | |
165 | mask = MASK_DEBUG_REG; | |
166 | else if (! strcmp (q, "addr")) | |
167 | mask = MASK_DEBUG_ADDR; | |
168 | else if (! strcmp (q, "cost")) | |
169 | mask = MASK_DEBUG_COST; | |
170 | else if (! strcmp (q, "target")) | |
171 | mask = MASK_DEBUG_TARGET; | |
172 | else if (! strcmp (q, "builtin")) | |
173 | mask = MASK_DEBUG_BUILTIN; | |
174 | else | |
175 | error_at (loc, "unknown %<-mdebug-%s%> switch", q); | |
176 | ||
177 | if (invert) | |
178 | opts->x_rs6000_debug &= ~mask; | |
179 | else | |
180 | opts->x_rs6000_debug |= mask; | |
181 | } | |
182 | break; | |
183 | ||
184 | #ifdef TARGET_USES_SYSV4_OPT | |
185 | case OPT_mrelocatable: | |
186 | if (value == 1) | |
187 | { | |
188 | opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
189 | opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC; | |
190 | opts->x_TARGET_NO_FP_IN_TOC = 1; | |
191 | } | |
192 | break; | |
193 | ||
194 | case OPT_mrelocatable_lib: | |
195 | if (value == 1) | |
196 | { | |
197 | opts->x_rs6000_isa_flags |= (OPTION_MASK_RELOCATABLE | |
198 | | OPTION_MASK_MINIMAL_TOC); | |
199 | opts_set->x_rs6000_isa_flags |= (OPTION_MASK_RELOCATABLE | |
200 | | OPTION_MASK_MINIMAL_TOC); | |
201 | opts->x_TARGET_NO_FP_IN_TOC = 1; | |
202 | } | |
203 | else | |
204 | { | |
205 | opts->x_rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE; | |
206 | opts_set->x_rs6000_isa_flags |= OPTION_MASK_RELOCATABLE; | |
207 | } | |
208 | break; | |
209 | #endif | |
210 | ||
211 | case OPT_mlong_double_: | |
212 | if (value != 64 && value != 128) | |
213 | { | |
214 | error_at (loc, "unknown switch %<-mlong-double-%s%>", arg); | |
215 | opts->x_rs6000_long_double_type_size | |
216 | = RS6000_DEFAULT_LONG_DOUBLE_SIZE; | |
217 | return false; | |
218 | } | |
219 | break; | |
220 | ||
221 | case OPT_mabi_ibmlongdouble: | |
222 | case OPT_mabi_ieeelongdouble: | |
223 | if (opts->x_rs6000_long_double_type_size == 64) | |
224 | { | |
225 | error_at (loc, "option %<%s%> requires %<-mlong-double-128%>", | |
226 | decoded->orig_option_with_args_text); | |
227 | return true; | |
228 | } | |
229 | break; | |
230 | ||
231 | case OPT_mrecip: | |
232 | opts->x_rs6000_recip_name = (value) ? "default" : "none"; | |
233 | break; | |
234 | } | |
235 | return true; | |
236 | } | |
237 | ||
238 | /* -fsplit-stack uses a field in the TCB, available with glibc-2.19. | |
239 | We also allow 2.18 because alignment padding guarantees that the | |
240 | space is available there too. */ | |
241 | ||
242 | static bool | |
243 | rs6000_supports_split_stack (bool report, | |
244 | struct gcc_options *opts ATTRIBUTE_UNUSED) | |
245 | { | |
246 | #ifndef TARGET_GLIBC_MAJOR | |
247 | #define TARGET_GLIBC_MAJOR 0 | |
248 | #endif | |
249 | #ifndef TARGET_GLIBC_MINOR | |
250 | #define TARGET_GLIBC_MINOR 0 | |
251 | #endif | |
252 | /* Note: Can't test DEFAULT_ABI here, it isn't set until later. */ | |
253 | if (TARGET_GLIBC_MAJOR * 1000 + TARGET_GLIBC_MINOR >= 2018 | |
254 | && TARGET_64BIT | |
255 | && TARGET_ELF) | |
256 | return true; | |
257 | ||
258 | if (report) | |
259 | error ("%<-fsplit-stack%> currently only supported on PowerPC64 GNU/Linux with glibc-2.18 or later"); | |
260 | return false; | |
261 | } | |
262 | ||
263 | #undef TARGET_HANDLE_OPTION | |
264 | #define TARGET_HANDLE_OPTION rs6000_handle_option | |
265 | ||
266 | #undef TARGET_OPTION_INIT_STRUCT | |
267 | #define TARGET_OPTION_INIT_STRUCT rs6000_option_init_struct | |
268 | ||
269 | #undef TARGET_OPTION_OPTIMIZATION_TABLE | |
270 | #define TARGET_OPTION_OPTIMIZATION_TABLE rs6000_option_optimization_table | |
271 | ||
272 | #undef TARGET_SUPPORTS_SPLIT_STACK | |
273 | #define TARGET_SUPPORTS_SPLIT_STACK rs6000_supports_split_stack | |
274 | ||
275 | struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; |