]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | /* Copyright (C) 1988-2022 Free Software Foundation, Inc. |
2bf6d935 ML |
2 | |
3 | This file is part of GCC. | |
4 | ||
5 | GCC is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3, or (at your option) | |
8 | any later version. | |
9 | ||
10 | GCC is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with GCC; see the file COPYING3. If not see | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #define IN_TARGET_CODE 1 | |
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "backend.h" | |
25 | #include "rtl.h" | |
26 | #include "tree.h" | |
27 | #include "memmodel.h" | |
28 | #include "gimple.h" | |
29 | #include "cfghooks.h" | |
30 | #include "cfgloop.h" | |
31 | #include "df.h" | |
32 | #include "tm_p.h" | |
33 | #include "stringpool.h" | |
34 | #include "expmed.h" | |
35 | #include "optabs.h" | |
36 | #include "regs.h" | |
37 | #include "emit-rtl.h" | |
38 | #include "recog.h" | |
39 | #include "cgraph.h" | |
40 | #include "diagnostic.h" | |
41 | #include "cfgbuild.h" | |
42 | #include "alias.h" | |
43 | #include "fold-const.h" | |
44 | #include "attribs.h" | |
45 | #include "calls.h" | |
46 | #include "stor-layout.h" | |
47 | #include "varasm.h" | |
48 | #include "output.h" | |
49 | #include "insn-attr.h" | |
50 | #include "flags.h" | |
51 | #include "except.h" | |
52 | #include "explow.h" | |
53 | #include "expr.h" | |
54 | #include "cfgrtl.h" | |
55 | #include "common/common-target.h" | |
56 | #include "langhooks.h" | |
57 | #include "reload.h" | |
58 | #include "gimplify.h" | |
59 | #include "dwarf2.h" | |
60 | #include "tm-constrs.h" | |
2bf6d935 ML |
61 | #include "cselib.h" |
62 | #include "sched-int.h" | |
63 | #include "opts.h" | |
64 | #include "tree-pass.h" | |
65 | #include "context.h" | |
66 | #include "pass_manager.h" | |
67 | #include "target-globals.h" | |
68 | #include "gimple-iterator.h" | |
69 | #include "tree-vectorizer.h" | |
70 | #include "shrink-wrap.h" | |
71 | #include "builtins.h" | |
72 | #include "rtl-iter.h" | |
73 | #include "tree-iterator.h" | |
74 | #include "dbgcnt.h" | |
75 | #include "case-cfn-macros.h" | |
76 | #include "dojump.h" | |
77 | #include "fold-const-call.h" | |
78 | #include "tree-vrp.h" | |
79 | #include "tree-ssanames.h" | |
80 | #include "selftest.h" | |
81 | #include "selftest-rtl.h" | |
82 | #include "print-rtl.h" | |
83 | #include "intl.h" | |
84 | #include "ifcvt.h" | |
85 | #include "symbol-summary.h" | |
86 | #include "ipa-prop.h" | |
87 | #include "ipa-fnsummary.h" | |
88 | #include "wide-int-bitmask.h" | |
89 | #include "tree-vector-builder.h" | |
90 | #include "debug.h" | |
91 | #include "dwarf2out.h" | |
92 | #include "i386-options.h" | |
93 | ||
94 | #include "x86-tune-costs.h" | |
95 | ||
96 | #ifndef SUBTARGET32_DEFAULT_CPU | |
97 | #define SUBTARGET32_DEFAULT_CPU "i386" | |
98 | #endif | |
99 | ||
100 | /* Processor feature/optimization bitmasks. */ | |
37876976 JJ |
101 | #define m_NONE HOST_WIDE_INT_0U |
102 | #define m_ALL (~HOST_WIDE_INT_0U) | |
2bf6d935 ML |
103 | #define m_386 (HOST_WIDE_INT_1U<<PROCESSOR_I386) |
104 | #define m_486 (HOST_WIDE_INT_1U<<PROCESSOR_I486) | |
105 | #define m_PENT (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUM) | |
106 | #define m_LAKEMONT (HOST_WIDE_INT_1U<<PROCESSOR_LAKEMONT) | |
107 | #define m_PPRO (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUMPRO) | |
108 | #define m_PENT4 (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUM4) | |
109 | #define m_NOCONA (HOST_WIDE_INT_1U<<PROCESSOR_NOCONA) | |
110 | #define m_P4_NOCONA (m_PENT4 | m_NOCONA) | |
111 | #define m_CORE2 (HOST_WIDE_INT_1U<<PROCESSOR_CORE2) | |
112 | #define m_NEHALEM (HOST_WIDE_INT_1U<<PROCESSOR_NEHALEM) | |
113 | #define m_SANDYBRIDGE (HOST_WIDE_INT_1U<<PROCESSOR_SANDYBRIDGE) | |
114 | #define m_HASWELL (HOST_WIDE_INT_1U<<PROCESSOR_HASWELL) | |
115 | #define m_BONNELL (HOST_WIDE_INT_1U<<PROCESSOR_BONNELL) | |
116 | #define m_SILVERMONT (HOST_WIDE_INT_1U<<PROCESSOR_SILVERMONT) | |
117 | #define m_KNL (HOST_WIDE_INT_1U<<PROCESSOR_KNL) | |
118 | #define m_KNM (HOST_WIDE_INT_1U<<PROCESSOR_KNM) | |
119 | #define m_SKYLAKE (HOST_WIDE_INT_1U<<PROCESSOR_SKYLAKE) | |
120 | #define m_SKYLAKE_AVX512 (HOST_WIDE_INT_1U<<PROCESSOR_SKYLAKE_AVX512) | |
121 | #define m_CANNONLAKE (HOST_WIDE_INT_1U<<PROCESSOR_CANNONLAKE) | |
122 | #define m_ICELAKE_CLIENT (HOST_WIDE_INT_1U<<PROCESSOR_ICELAKE_CLIENT) | |
123 | #define m_ICELAKE_SERVER (HOST_WIDE_INT_1U<<PROCESSOR_ICELAKE_SERVER) | |
124 | #define m_CASCADELAKE (HOST_WIDE_INT_1U<<PROCESSOR_CASCADELAKE) | |
a9fcfec3 HL |
125 | #define m_TIGERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_TIGERLAKE) |
126 | #define m_COOPERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_COOPERLAKE) | |
ba9c87d3 CL |
127 | #define m_SAPPHIRERAPIDS (HOST_WIDE_INT_1U<<PROCESSOR_SAPPHIRERAPIDS) |
128 | #define m_ALDERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_ALDERLAKE) | |
c02c39fa | 129 | #define m_ROCKETLAKE (HOST_WIDE_INT_1U<<PROCESSOR_ROCKETLAKE) |
2bf6d935 | 130 | #define m_CORE_AVX512 (m_SKYLAKE_AVX512 | m_CANNONLAKE \ |
a9fcfec3 | 131 | | m_ICELAKE_CLIENT | m_ICELAKE_SERVER | m_CASCADELAKE \ |
c02c39fa CL |
132 | | m_TIGERLAKE | m_COOPERLAKE | m_SAPPHIRERAPIDS \ |
133 | | m_ROCKETLAKE) | |
4f442a3b | 134 | #define m_CORE_AVX2 (m_HASWELL | m_SKYLAKE | m_CORE_AVX512) |
2bf6d935 ML |
135 | #define m_CORE_ALL (m_CORE2 | m_NEHALEM | m_SANDYBRIDGE | m_CORE_AVX2) |
136 | #define m_GOLDMONT (HOST_WIDE_INT_1U<<PROCESSOR_GOLDMONT) | |
137 | #define m_GOLDMONT_PLUS (HOST_WIDE_INT_1U<<PROCESSOR_GOLDMONT_PLUS) | |
138 | #define m_TREMONT (HOST_WIDE_INT_1U<<PROCESSOR_TREMONT) | |
139 | #define m_INTEL (HOST_WIDE_INT_1U<<PROCESSOR_INTEL) | |
140 | ||
141 | #define m_GEODE (HOST_WIDE_INT_1U<<PROCESSOR_GEODE) | |
142 | #define m_K6 (HOST_WIDE_INT_1U<<PROCESSOR_K6) | |
143 | #define m_K6_GEODE (m_K6 | m_GEODE) | |
144 | #define m_K8 (HOST_WIDE_INT_1U<<PROCESSOR_K8) | |
145 | #define m_ATHLON (HOST_WIDE_INT_1U<<PROCESSOR_ATHLON) | |
146 | #define m_ATHLON_K8 (m_K8 | m_ATHLON) | |
147 | #define m_AMDFAM10 (HOST_WIDE_INT_1U<<PROCESSOR_AMDFAM10) | |
148 | #define m_BDVER1 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER1) | |
149 | #define m_BDVER2 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER2) | |
150 | #define m_BDVER3 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER3) | |
151 | #define m_BDVER4 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER4) | |
152 | #define m_ZNVER1 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER1) | |
153 | #define m_ZNVER2 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER2) | |
3e2ae3ee | 154 | #define m_ZNVER3 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER3) |
2bf6d935 ML |
155 | #define m_BTVER1 (HOST_WIDE_INT_1U<<PROCESSOR_BTVER1) |
156 | #define m_BTVER2 (HOST_WIDE_INT_1U<<PROCESSOR_BTVER2) | |
157 | #define m_BDVER (m_BDVER1 | m_BDVER2 | m_BDVER3 | m_BDVER4) | |
158 | #define m_BTVER (m_BTVER1 | m_BTVER2) | |
3e2ae3ee | 159 | #define m_ZNVER (m_ZNVER1 | m_ZNVER2 | m_ZNVER3) |
2bf6d935 ML |
160 | #define m_AMD_MULTIPLE (m_ATHLON_K8 | m_AMDFAM10 | m_BDVER | m_BTVER \ |
161 | | m_ZNVER) | |
162 | ||
163 | #define m_GENERIC (HOST_WIDE_INT_1U<<PROCESSOR_GENERIC) | |
164 | ||
165 | const char* ix86_tune_feature_names[X86_TUNE_LAST] = { | |
166 | #undef DEF_TUNE | |
167 | #define DEF_TUNE(tune, name, selector) name, | |
168 | #include "x86-tune.def" | |
169 | #undef DEF_TUNE | |
170 | }; | |
171 | ||
172 | /* Feature tests against the various tunings. */ | |
173 | unsigned char ix86_tune_features[X86_TUNE_LAST]; | |
174 | ||
175 | /* Feature tests against the various tunings used to create ix86_tune_features | |
176 | based on the processor mask. */ | |
177 | static unsigned HOST_WIDE_INT initial_ix86_tune_features[X86_TUNE_LAST] = { | |
178 | #undef DEF_TUNE | |
179 | #define DEF_TUNE(tune, name, selector) selector, | |
180 | #include "x86-tune.def" | |
181 | #undef DEF_TUNE | |
182 | }; | |
183 | ||
184 | /* Feature tests against the various architecture variations. */ | |
185 | unsigned char ix86_arch_features[X86_ARCH_LAST]; | |
186 | ||
9ba66bf5 JJ |
187 | struct ix86_target_opts |
188 | { | |
189 | const char *option; /* option string */ | |
190 | HOST_WIDE_INT mask; /* isa mask options */ | |
191 | }; | |
192 | ||
193 | /* This table is ordered so that options like -msse4.2 that imply other | |
194 | ISAs come first. Target string will be displayed in the same order. */ | |
195 | static struct ix86_target_opts isa2_opts[] = | |
196 | { | |
8cf86e14 HL |
197 | { "-mcx16", OPTION_MASK_ISA2_CX16 }, |
198 | { "-mvaes", OPTION_MASK_ISA2_VAES }, | |
199 | { "-mrdpid", OPTION_MASK_ISA2_RDPID }, | |
200 | { "-mpconfig", OPTION_MASK_ISA2_PCONFIG }, | |
201 | { "-mwbnoinvd", OPTION_MASK_ISA2_WBNOINVD }, | |
202 | { "-mavx512vp2intersect", OPTION_MASK_ISA2_AVX512VP2INTERSECT }, | |
203 | { "-msgx", OPTION_MASK_ISA2_SGX }, | |
204 | { "-mavx5124vnniw", OPTION_MASK_ISA2_AVX5124VNNIW }, | |
205 | { "-mavx5124fmaps", OPTION_MASK_ISA2_AVX5124FMAPS }, | |
206 | { "-mhle", OPTION_MASK_ISA2_HLE }, | |
207 | { "-mmovbe", OPTION_MASK_ISA2_MOVBE }, | |
208 | { "-mclzero", OPTION_MASK_ISA2_CLZERO }, | |
209 | { "-mmwaitx", OPTION_MASK_ISA2_MWAITX }, | |
d8c6cc2c | 210 | { "-mmwait", OPTION_MASK_ISA2_MWAIT }, |
8cf86e14 HL |
211 | { "-mmovdir64b", OPTION_MASK_ISA2_MOVDIR64B }, |
212 | { "-mwaitpkg", OPTION_MASK_ISA2_WAITPKG }, | |
213 | { "-mcldemote", OPTION_MASK_ISA2_CLDEMOTE }, | |
214 | { "-mptwrite", OPTION_MASK_ISA2_PTWRITE }, | |
215 | { "-mavx512bf16", OPTION_MASK_ISA2_AVX512BF16 }, | |
366386c7 | 216 | { "-menqcmd", OPTION_MASK_ISA2_ENQCMD }, |
1e47cb35 | 217 | { "-mserialize", OPTION_MASK_ISA2_SERIALIZE }, |
5c609842 | 218 | { "-mtsxldtrk", OPTION_MASK_ISA2_TSXLDTRK }, |
219 | { "-mamx-tile", OPTION_MASK_ISA2_AMX_TILE }, | |
220 | { "-mamx-int8", OPTION_MASK_ISA2_AMX_INT8 }, | |
299a53d7 | 221 | { "-mamx-bf16", OPTION_MASK_ISA2_AMX_BF16 }, |
83927c63 | 222 | { "-muintr", OPTION_MASK_ISA2_UINTR }, |
632a2f50 | 223 | { "-mhreset", OPTION_MASK_ISA2_HRESET }, |
224 | { "-mkl", OPTION_MASK_ISA2_KL }, | |
ca813880 | 225 | { "-mwidekl", OPTION_MASK_ISA2_WIDEKL }, |
a6841211 GX |
226 | { "-mavxvnni", OPTION_MASK_ISA2_AVXVNNI }, |
227 | { "-mavx512fp16", OPTION_MASK_ISA2_AVX512FP16 } | |
9ba66bf5 JJ |
228 | }; |
229 | static struct ix86_target_opts isa_opts[] = | |
230 | { | |
231 | { "-mavx512vpopcntdq", OPTION_MASK_ISA_AVX512VPOPCNTDQ }, | |
232 | { "-mavx512bitalg", OPTION_MASK_ISA_AVX512BITALG }, | |
233 | { "-mvpclmulqdq", OPTION_MASK_ISA_VPCLMULQDQ }, | |
234 | { "-mgfni", OPTION_MASK_ISA_GFNI }, | |
235 | { "-mavx512vnni", OPTION_MASK_ISA_AVX512VNNI }, | |
236 | { "-mavx512vbmi2", OPTION_MASK_ISA_AVX512VBMI2 }, | |
237 | { "-mavx512vbmi", OPTION_MASK_ISA_AVX512VBMI }, | |
238 | { "-mavx512ifma", OPTION_MASK_ISA_AVX512IFMA }, | |
239 | { "-mavx512vl", OPTION_MASK_ISA_AVX512VL }, | |
240 | { "-mavx512bw", OPTION_MASK_ISA_AVX512BW }, | |
241 | { "-mavx512dq", OPTION_MASK_ISA_AVX512DQ }, | |
242 | { "-mavx512er", OPTION_MASK_ISA_AVX512ER }, | |
243 | { "-mavx512pf", OPTION_MASK_ISA_AVX512PF }, | |
244 | { "-mavx512cd", OPTION_MASK_ISA_AVX512CD }, | |
245 | { "-mavx512f", OPTION_MASK_ISA_AVX512F }, | |
246 | { "-mavx2", OPTION_MASK_ISA_AVX2 }, | |
247 | { "-mfma", OPTION_MASK_ISA_FMA }, | |
248 | { "-mxop", OPTION_MASK_ISA_XOP }, | |
249 | { "-mfma4", OPTION_MASK_ISA_FMA4 }, | |
250 | { "-mf16c", OPTION_MASK_ISA_F16C }, | |
251 | { "-mavx", OPTION_MASK_ISA_AVX }, | |
252 | /*{ "-msse4" OPTION_MASK_ISA_SSE4 }, */ | |
253 | { "-msse4.2", OPTION_MASK_ISA_SSE4_2 }, | |
254 | { "-msse4.1", OPTION_MASK_ISA_SSE4_1 }, | |
255 | { "-msse4a", OPTION_MASK_ISA_SSE4A }, | |
256 | { "-mssse3", OPTION_MASK_ISA_SSSE3 }, | |
257 | { "-msse3", OPTION_MASK_ISA_SSE3 }, | |
258 | { "-maes", OPTION_MASK_ISA_AES }, | |
259 | { "-msha", OPTION_MASK_ISA_SHA }, | |
260 | { "-mpclmul", OPTION_MASK_ISA_PCLMUL }, | |
261 | { "-msse2", OPTION_MASK_ISA_SSE2 }, | |
262 | { "-msse", OPTION_MASK_ISA_SSE }, | |
263 | { "-m3dnowa", OPTION_MASK_ISA_3DNOW_A }, | |
264 | { "-m3dnow", OPTION_MASK_ISA_3DNOW }, | |
265 | { "-mmmx", OPTION_MASK_ISA_MMX }, | |
266 | { "-mrtm", OPTION_MASK_ISA_RTM }, | |
267 | { "-mprfchw", OPTION_MASK_ISA_PRFCHW }, | |
268 | { "-mrdseed", OPTION_MASK_ISA_RDSEED }, | |
269 | { "-madx", OPTION_MASK_ISA_ADX }, | |
270 | { "-mprefetchwt1", OPTION_MASK_ISA_PREFETCHWT1 }, | |
271 | { "-mclflushopt", OPTION_MASK_ISA_CLFLUSHOPT }, | |
272 | { "-mxsaves", OPTION_MASK_ISA_XSAVES }, | |
273 | { "-mxsavec", OPTION_MASK_ISA_XSAVEC }, | |
274 | { "-mxsaveopt", OPTION_MASK_ISA_XSAVEOPT }, | |
275 | { "-mxsave", OPTION_MASK_ISA_XSAVE }, | |
276 | { "-mabm", OPTION_MASK_ISA_ABM }, | |
277 | { "-mbmi", OPTION_MASK_ISA_BMI }, | |
278 | { "-mbmi2", OPTION_MASK_ISA_BMI2 }, | |
279 | { "-mlzcnt", OPTION_MASK_ISA_LZCNT }, | |
280 | { "-mtbm", OPTION_MASK_ISA_TBM }, | |
281 | { "-mpopcnt", OPTION_MASK_ISA_POPCNT }, | |
282 | { "-msahf", OPTION_MASK_ISA_SAHF }, | |
283 | { "-mcrc32", OPTION_MASK_ISA_CRC32 }, | |
284 | { "-mfsgsbase", OPTION_MASK_ISA_FSGSBASE }, | |
285 | { "-mrdrnd", OPTION_MASK_ISA_RDRND }, | |
286 | { "-mpku", OPTION_MASK_ISA_PKU }, | |
287 | { "-mlwp", OPTION_MASK_ISA_LWP }, | |
288 | { "-mfxsr", OPTION_MASK_ISA_FXSR }, | |
289 | { "-mclwb", OPTION_MASK_ISA_CLWB }, | |
290 | { "-mshstk", OPTION_MASK_ISA_SHSTK }, | |
291 | { "-mmovdiri", OPTION_MASK_ISA_MOVDIRI } | |
292 | }; | |
293 | ||
294 | /* Return 1 if TRAIT NAME is present in the OpenMP context's | |
295 | device trait set, return 0 if not present in any OpenMP context in the | |
296 | whole translation unit, or -1 if not present in the current OpenMP context | |
297 | but might be present in another OpenMP context in the same TU. */ | |
298 | ||
299 | int | |
300 | ix86_omp_device_kind_arch_isa (enum omp_device_kind_arch_isa trait, | |
301 | const char *name) | |
302 | { | |
303 | switch (trait) | |
304 | { | |
305 | case omp_device_kind: | |
306 | return strcmp (name, "cpu") == 0; | |
307 | case omp_device_arch: | |
bb75b22a TS |
308 | #ifdef ACCEL_COMPILER |
309 | if (strcmp (name, "intel_mic") == 0) | |
310 | return 1; | |
311 | #endif | |
9ba66bf5 JJ |
312 | if (strcmp (name, "x86") == 0) |
313 | return 1; | |
314 | if (TARGET_64BIT) | |
315 | { | |
316 | if (TARGET_X32) | |
317 | return strcmp (name, "x32") == 0; | |
318 | else | |
319 | return strcmp (name, "x86_64") == 0; | |
320 | } | |
321 | if (strcmp (name, "ia32") == 0 || strcmp (name, "i386") == 0) | |
322 | return 1; | |
323 | if (strcmp (name, "i486") == 0) | |
324 | return ix86_arch != PROCESSOR_I386 ? 1 : -1; | |
325 | if (strcmp (name, "i586") == 0) | |
326 | return (ix86_arch != PROCESSOR_I386 | |
327 | && ix86_arch != PROCESSOR_I486) ? 1 : -1; | |
328 | if (strcmp (name, "i686") == 0) | |
329 | return (ix86_arch != PROCESSOR_I386 | |
330 | && ix86_arch != PROCESSOR_I486 | |
331 | && ix86_arch != PROCESSOR_LAKEMONT | |
332 | && ix86_arch != PROCESSOR_PENTIUM) ? 1 : -1; | |
333 | return 0; | |
334 | case omp_device_isa: | |
335 | for (int i = 0; i < 2; i++) | |
336 | { | |
337 | struct ix86_target_opts *opts = i ? isa2_opts : isa_opts; | |
338 | size_t nopts = i ? ARRAY_SIZE (isa2_opts) : ARRAY_SIZE (isa_opts); | |
339 | HOST_WIDE_INT mask = i ? ix86_isa_flags2 : ix86_isa_flags; | |
340 | for (size_t n = 0; n < nopts; n++) | |
341 | { | |
aa16689e | 342 | /* Handle sse4 as an alias to sse4.2. */ |
9ba66bf5 JJ |
343 | if (opts[n].mask == OPTION_MASK_ISA_SSE4_2) |
344 | { | |
9ba66bf5 JJ |
345 | if (strcmp (name, "sse4") == 0) |
346 | return (mask & opts[n].mask) != 0 ? 1 : -1; | |
347 | } | |
aa16689e | 348 | if (strcmp (name, opts[n].option + 2) == 0) |
9ba66bf5 JJ |
349 | return (mask & opts[n].mask) != 0 ? 1 : -1; |
350 | } | |
351 | } | |
352 | return 0; | |
353 | default: | |
354 | gcc_unreachable (); | |
355 | } | |
356 | } | |
357 | ||
2bf6d935 ML |
358 | /* Return a string that documents the current -m options. The caller is |
359 | responsible for freeing the string. */ | |
360 | ||
361 | char * | |
362 | ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2, | |
363 | int flags, int flags2, | |
364 | const char *arch, const char *tune, | |
46e6341f JJ |
365 | enum fpmath_unit fpmath, |
366 | enum prefer_vector_width pvw, | |
654cd743 L |
367 | enum prefer_vector_width move_max, |
368 | enum prefer_vector_width store_max, | |
46e6341f | 369 | bool add_nl_p, bool add_abi_p) |
2bf6d935 | 370 | { |
2bf6d935 ML |
371 | /* Flag options. */ |
372 | static struct ix86_target_opts flag_opts[] = | |
373 | { | |
374 | { "-m128bit-long-double", MASK_128BIT_LONG_DOUBLE }, | |
375 | { "-mlong-double-128", MASK_LONG_DOUBLE_128 }, | |
376 | { "-mlong-double-64", MASK_LONG_DOUBLE_64 }, | |
377 | { "-m80387", MASK_80387 }, | |
378 | { "-maccumulate-outgoing-args", MASK_ACCUMULATE_OUTGOING_ARGS }, | |
379 | { "-malign-double", MASK_ALIGN_DOUBLE }, | |
380 | { "-mcld", MASK_CLD }, | |
381 | { "-mfp-ret-in-387", MASK_FLOAT_RETURNS }, | |
382 | { "-mieee-fp", MASK_IEEE_FP }, | |
383 | { "-minline-all-stringops", MASK_INLINE_ALL_STRINGOPS }, | |
384 | { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY }, | |
385 | { "-mms-bitfields", MASK_MS_BITFIELD_LAYOUT }, | |
386 | { "-mno-align-stringops", MASK_NO_ALIGN_STRINGOPS }, | |
387 | { "-mno-fancy-math-387", MASK_NO_FANCY_MATH_387 }, | |
388 | { "-mno-push-args", MASK_NO_PUSH_ARGS }, | |
389 | { "-mno-red-zone", MASK_NO_RED_ZONE }, | |
390 | { "-momit-leaf-frame-pointer", MASK_OMIT_LEAF_FRAME_POINTER }, | |
391 | { "-mrecip", MASK_RECIP }, | |
392 | { "-mrtd", MASK_RTD }, | |
393 | { "-msseregparm", MASK_SSEREGPARM }, | |
394 | { "-mstack-arg-probe", MASK_STACK_PROBE }, | |
395 | { "-mtls-direct-seg-refs", MASK_TLS_DIRECT_SEG_REFS }, | |
396 | { "-mvect8-ret-in-mem", MASK_VECT8_RETURNS }, | |
397 | { "-m8bit-idiv", MASK_USE_8BIT_IDIV }, | |
398 | { "-mvzeroupper", MASK_VZEROUPPER }, | |
399 | { "-mstv", MASK_STV }, | |
400 | { "-mavx256-split-unaligned-load", MASK_AVX256_SPLIT_UNALIGNED_LOAD }, | |
401 | { "-mavx256-split-unaligned-store", MASK_AVX256_SPLIT_UNALIGNED_STORE }, | |
4d281ff7 HW |
402 | { "-mcall-ms2sysv-xlogues", MASK_CALL_MS2SYSV_XLOGUES }, |
403 | { "-mrelax-cmpxchg-loop", MASK_RELAX_CMPXCHG_LOOP } | |
2bf6d935 ML |
404 | }; |
405 | ||
406 | /* Additional flag options. */ | |
407 | static struct ix86_target_opts flag2_opts[] = | |
408 | { | |
409 | { "-mgeneral-regs-only", OPTION_MASK_GENERAL_REGS_ONLY } | |
410 | }; | |
411 | ||
412 | const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (isa2_opts) | |
413 | + ARRAY_SIZE (flag_opts) + ARRAY_SIZE (flag2_opts) + 6][2]; | |
414 | ||
415 | char isa_other[40]; | |
416 | char isa2_other[40]; | |
417 | char flags_other[40]; | |
418 | char flags2_other[40]; | |
419 | unsigned num = 0; | |
420 | unsigned i, j; | |
421 | char *ret; | |
422 | char *ptr; | |
423 | size_t len; | |
424 | size_t line_len; | |
425 | size_t sep_len; | |
426 | const char *abi; | |
427 | ||
428 | memset (opts, '\0', sizeof (opts)); | |
429 | ||
430 | /* Add -march= option. */ | |
431 | if (arch) | |
432 | { | |
433 | opts[num][0] = "-march="; | |
434 | opts[num++][1] = arch; | |
435 | } | |
436 | ||
437 | /* Add -mtune= option. */ | |
438 | if (tune) | |
439 | { | |
440 | opts[num][0] = "-mtune="; | |
441 | opts[num++][1] = tune; | |
442 | } | |
443 | ||
444 | /* Add -m32/-m64/-mx32. */ | |
445 | if (add_abi_p) | |
446 | { | |
447 | if ((isa & OPTION_MASK_ISA_64BIT) != 0) | |
448 | { | |
449 | if ((isa & OPTION_MASK_ABI_64) != 0) | |
450 | abi = "-m64"; | |
451 | else | |
452 | abi = "-mx32"; | |
453 | } | |
454 | else | |
455 | abi = "-m32"; | |
456 | opts[num++][0] = abi; | |
457 | } | |
458 | isa &= ~(OPTION_MASK_ISA_64BIT | OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32); | |
459 | ||
460 | /* Pick out the options in isa2 options. */ | |
461 | for (i = 0; i < ARRAY_SIZE (isa2_opts); i++) | |
462 | { | |
463 | if ((isa2 & isa2_opts[i].mask) != 0) | |
464 | { | |
465 | opts[num++][0] = isa2_opts[i].option; | |
466 | isa2 &= ~ isa2_opts[i].mask; | |
467 | } | |
468 | } | |
469 | ||
470 | if (isa2 && add_nl_p) | |
471 | { | |
472 | opts[num++][0] = isa2_other; | |
473 | sprintf (isa2_other, "(other isa2: %#" HOST_WIDE_INT_PRINT "x)", isa2); | |
474 | } | |
475 | ||
476 | /* Pick out the options in isa options. */ | |
477 | for (i = 0; i < ARRAY_SIZE (isa_opts); i++) | |
478 | { | |
479 | if ((isa & isa_opts[i].mask) != 0) | |
480 | { | |
481 | opts[num++][0] = isa_opts[i].option; | |
482 | isa &= ~ isa_opts[i].mask; | |
483 | } | |
484 | } | |
485 | ||
486 | if (isa && add_nl_p) | |
487 | { | |
488 | opts[num++][0] = isa_other; | |
489 | sprintf (isa_other, "(other isa: %#" HOST_WIDE_INT_PRINT "x)", isa); | |
490 | } | |
491 | ||
492 | /* Add flag options. */ | |
493 | for (i = 0; i < ARRAY_SIZE (flag_opts); i++) | |
494 | { | |
495 | if ((flags & flag_opts[i].mask) != 0) | |
496 | { | |
497 | opts[num++][0] = flag_opts[i].option; | |
498 | flags &= ~ flag_opts[i].mask; | |
499 | } | |
500 | } | |
501 | ||
502 | if (flags && add_nl_p) | |
503 | { | |
504 | opts[num++][0] = flags_other; | |
505 | sprintf (flags_other, "(other flags: %#x)", flags); | |
506 | } | |
507 | ||
508 | /* Add additional flag options. */ | |
509 | for (i = 0; i < ARRAY_SIZE (flag2_opts); i++) | |
510 | { | |
511 | if ((flags2 & flag2_opts[i].mask) != 0) | |
512 | { | |
513 | opts[num++][0] = flag2_opts[i].option; | |
514 | flags2 &= ~ flag2_opts[i].mask; | |
515 | } | |
516 | } | |
517 | ||
518 | if (flags2 && add_nl_p) | |
519 | { | |
520 | opts[num++][0] = flags2_other; | |
521 | sprintf (flags2_other, "(other flags2: %#x)", flags2); | |
522 | } | |
523 | ||
46e6341f | 524 | /* Add -mfpmath= option. */ |
2bf6d935 ML |
525 | if (fpmath) |
526 | { | |
527 | opts[num][0] = "-mfpmath="; | |
528 | switch ((int) fpmath) | |
529 | { | |
530 | case FPMATH_387: | |
531 | opts[num++][1] = "387"; | |
532 | break; | |
533 | ||
534 | case FPMATH_SSE: | |
535 | opts[num++][1] = "sse"; | |
536 | break; | |
537 | ||
538 | case FPMATH_387 | FPMATH_SSE: | |
539 | opts[num++][1] = "sse+387"; | |
540 | break; | |
541 | ||
542 | default: | |
543 | gcc_unreachable (); | |
544 | } | |
545 | } | |
546 | ||
654cd743 L |
547 | auto add_vector_width = [&opts, &num] (prefer_vector_width pvw, |
548 | const char *cmd) | |
46e6341f | 549 | { |
654cd743 | 550 | opts[num][0] = cmd; |
46e6341f JJ |
551 | switch ((int) pvw) |
552 | { | |
553 | case PVW_AVX128: | |
554 | opts[num++][1] = "128"; | |
555 | break; | |
556 | ||
557 | case PVW_AVX256: | |
558 | opts[num++][1] = "256"; | |
559 | break; | |
560 | ||
561 | case PVW_AVX512: | |
562 | opts[num++][1] = "512"; | |
563 | break; | |
564 | ||
565 | default: | |
566 | gcc_unreachable (); | |
567 | } | |
654cd743 L |
568 | }; |
569 | ||
570 | /* Add -mprefer-vector-width= option. */ | |
571 | if (pvw) | |
572 | add_vector_width (pvw, "-mprefer-vector-width="); | |
573 | ||
574 | /* Add -mmove-max= option. */ | |
575 | if (move_max) | |
576 | add_vector_width (move_max, "-mmove-max="); | |
577 | ||
578 | /* Add -mstore-max= option. */ | |
579 | if (store_max) | |
580 | add_vector_width (store_max, "-mstore-max="); | |
46e6341f | 581 | |
2bf6d935 ML |
582 | /* Any options? */ |
583 | if (num == 0) | |
584 | return NULL; | |
585 | ||
586 | gcc_assert (num < ARRAY_SIZE (opts)); | |
587 | ||
588 | /* Size the string. */ | |
589 | len = 0; | |
590 | sep_len = (add_nl_p) ? 3 : 1; | |
591 | for (i = 0; i < num; i++) | |
592 | { | |
593 | len += sep_len; | |
594 | for (j = 0; j < 2; j++) | |
595 | if (opts[i][j]) | |
596 | len += strlen (opts[i][j]); | |
597 | } | |
598 | ||
599 | /* Build the string. */ | |
600 | ret = ptr = (char *) xmalloc (len); | |
601 | line_len = 0; | |
602 | ||
603 | for (i = 0; i < num; i++) | |
604 | { | |
605 | size_t len2[2]; | |
606 | ||
607 | for (j = 0; j < 2; j++) | |
608 | len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0; | |
609 | ||
610 | if (i != 0) | |
611 | { | |
612 | *ptr++ = ' '; | |
613 | line_len++; | |
614 | ||
615 | if (add_nl_p && line_len + len2[0] + len2[1] > 70) | |
616 | { | |
617 | *ptr++ = '\\'; | |
618 | *ptr++ = '\n'; | |
619 | line_len = 0; | |
620 | } | |
621 | } | |
622 | ||
623 | for (j = 0; j < 2; j++) | |
624 | if (opts[i][j]) | |
625 | { | |
626 | memcpy (ptr, opts[i][j], len2[j]); | |
627 | ptr += len2[j]; | |
628 | line_len += len2[j]; | |
629 | } | |
630 | } | |
631 | ||
632 | *ptr = '\0'; | |
633 | gcc_assert (ret + len >= ptr); | |
634 | ||
635 | return ret; | |
636 | } | |
637 | ||
638 | /* Function that is callable from the debugger to print the current | |
639 | options. */ | |
640 | void ATTRIBUTE_UNUSED | |
641 | ix86_debug_options (void) | |
642 | { | |
643 | char *opts = ix86_target_string (ix86_isa_flags, ix86_isa_flags2, | |
644 | target_flags, ix86_target_flags, | |
46e6341f JJ |
645 | ix86_arch_string, ix86_tune_string, |
646 | ix86_fpmath, prefer_vector_width_type, | |
654cd743 | 647 | ix86_move_max, ix86_store_max, |
46e6341f | 648 | true, true); |
2bf6d935 ML |
649 | |
650 | if (opts) | |
651 | { | |
652 | fprintf (stderr, "%s\n\n", opts); | |
653 | free (opts); | |
654 | } | |
655 | else | |
656 | fputs ("<no options>\n\n", stderr); | |
657 | ||
658 | return; | |
659 | } | |
660 | ||
661 | /* Save the current options */ | |
662 | ||
663 | void | |
664 | ix86_function_specific_save (struct cl_target_option *ptr, | |
ba948b37 JJ |
665 | struct gcc_options *opts, |
666 | struct gcc_options */* opts_set */) | |
2bf6d935 ML |
667 | { |
668 | ptr->arch = ix86_arch; | |
669 | ptr->schedule = ix86_schedule; | |
08a4adcf | 670 | ptr->prefetch_sse = ix86_prefetch_sse; |
2bf6d935 ML |
671 | ptr->tune = ix86_tune; |
672 | ptr->branch_cost = ix86_branch_cost; | |
673 | ptr->tune_defaulted = ix86_tune_defaulted; | |
674 | ptr->arch_specified = ix86_arch_specified; | |
675 | ptr->x_ix86_isa_flags_explicit = opts->x_ix86_isa_flags_explicit; | |
676 | ptr->x_ix86_isa_flags2_explicit = opts->x_ix86_isa_flags2_explicit; | |
677 | ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit; | |
678 | ptr->x_ix86_arch_string = opts->x_ix86_arch_string; | |
679 | ptr->x_ix86_tune_string = opts->x_ix86_tune_string; | |
2bf6d935 ML |
680 | ptr->x_ix86_abi = opts->x_ix86_abi; |
681 | ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect; | |
682 | ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost; | |
683 | ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes; | |
684 | ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer; | |
685 | ptr->x_ix86_force_drap = opts->x_ix86_force_drap; | |
2bf6d935 | 686 | ptr->x_ix86_recip_name = opts->x_ix86_recip_name; |
2bf6d935 ML |
687 | ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold; |
688 | ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx; | |
689 | ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard; | |
690 | ptr->x_ix86_stringop_alg = opts->x_ix86_stringop_alg; | |
691 | ptr->x_ix86_tls_dialect = opts->x_ix86_tls_dialect; | |
692 | ptr->x_ix86_tune_ctrl_string = opts->x_ix86_tune_ctrl_string; | |
693 | ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy; | |
694 | ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy; | |
695 | ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default; | |
2bf6d935 ML |
696 | |
697 | /* The fields are char but the variables are not; make sure the | |
698 | values fit in the fields. */ | |
699 | gcc_assert (ptr->arch == ix86_arch); | |
700 | gcc_assert (ptr->schedule == ix86_schedule); | |
701 | gcc_assert (ptr->tune == ix86_tune); | |
702 | gcc_assert (ptr->branch_cost == ix86_branch_cost); | |
703 | } | |
704 | ||
705 | /* Feature tests against the various architecture variations, used to create | |
706 | ix86_arch_features based on the processor mask. */ | |
707 | static unsigned HOST_WIDE_INT initial_ix86_arch_features[X86_ARCH_LAST] = { | |
708 | /* X86_ARCH_CMOV: Conditional move was added for pentiumpro. */ | |
709 | ~(m_386 | m_486 | m_PENT | m_LAKEMONT | m_K6), | |
710 | ||
711 | /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486. */ | |
712 | ~m_386, | |
713 | ||
714 | /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */ | |
715 | ~(m_386 | m_486), | |
716 | ||
717 | /* X86_ARCH_XADD: Exchange and add was added for 80486. */ | |
718 | ~m_386, | |
719 | ||
720 | /* X86_ARCH_BSWAP: Byteswap was added for 80486. */ | |
721 | ~m_386, | |
722 | }; | |
723 | ||
724 | /* This table must be in sync with enum processor_type in i386.h. */ | |
725 | static const struct processor_costs *processor_cost_table[] = | |
726 | { | |
727 | &generic_cost, | |
728 | &i386_cost, | |
729 | &i486_cost, | |
730 | &pentium_cost, | |
731 | &lakemont_cost, | |
732 | &pentiumpro_cost, | |
733 | &pentium4_cost, | |
734 | &nocona_cost, | |
735 | &core_cost, | |
736 | &core_cost, | |
737 | &core_cost, | |
738 | &core_cost, | |
739 | &atom_cost, | |
740 | &slm_cost, | |
741 | &slm_cost, | |
742 | &slm_cost, | |
c3a2437f | 743 | &tremont_cost, |
2bf6d935 ML |
744 | &slm_cost, |
745 | &slm_cost, | |
746 | &skylake_cost, | |
747 | &skylake_cost, | |
bf24f4ec L |
748 | &icelake_cost, |
749 | &icelake_cost, | |
750 | &icelake_cost, | |
2bf6d935 | 751 | &skylake_cost, |
bf24f4ec | 752 | &icelake_cost, |
2bf6d935 | 753 | &skylake_cost, |
bf24f4ec | 754 | &icelake_cost, |
4f442a3b | 755 | &alderlake_cost, |
2cde2d62 | 756 | &icelake_cost, |
2bf6d935 ML |
757 | &intel_cost, |
758 | &geode_cost, | |
759 | &k6_cost, | |
760 | &athlon_cost, | |
761 | &k8_cost, | |
762 | &amdfam10_cost, | |
763 | &bdver_cost, | |
764 | &bdver_cost, | |
765 | &bdver_cost, | |
766 | &bdver_cost, | |
767 | &btver1_cost, | |
768 | &btver2_cost, | |
769 | &znver1_cost, | |
3e2ae3ee | 770 | &znver2_cost, |
5b32a181 | 771 | &znver3_cost |
2bf6d935 ML |
772 | }; |
773 | ||
774 | /* Guarantee that the array is aligned with enum processor_type. */ | |
775 | STATIC_ASSERT (ARRAY_SIZE (processor_cost_table) == PROCESSOR_max); | |
776 | ||
777 | static bool | |
778 | ix86_option_override_internal (bool main_args_p, | |
779 | struct gcc_options *opts, | |
780 | struct gcc_options *opts_set); | |
781 | static void | |
1e964774 L |
782 | set_ix86_tune_features (struct gcc_options *opts, |
783 | enum processor_type ix86_tune, bool dump); | |
2bf6d935 ML |
784 | |
785 | /* Restore the current options */ | |
786 | ||
787 | void | |
788 | ix86_function_specific_restore (struct gcc_options *opts, | |
ba948b37 | 789 | struct gcc_options */* opts_set */, |
2bf6d935 ML |
790 | struct cl_target_option *ptr) |
791 | { | |
792 | enum processor_type old_tune = ix86_tune; | |
793 | enum processor_type old_arch = ix86_arch; | |
794 | unsigned HOST_WIDE_INT ix86_arch_mask; | |
795 | int i; | |
796 | ||
797 | /* We don't change -fPIC. */ | |
798 | opts->x_flag_pic = flag_pic; | |
799 | ||
800 | ix86_arch = (enum processor_type) ptr->arch; | |
801 | ix86_schedule = (enum attr_cpu) ptr->schedule; | |
802 | ix86_tune = (enum processor_type) ptr->tune; | |
08a4adcf | 803 | ix86_prefetch_sse = ptr->prefetch_sse; |
2bf6d935 ML |
804 | ix86_tune_defaulted = ptr->tune_defaulted; |
805 | ix86_arch_specified = ptr->arch_specified; | |
806 | opts->x_ix86_isa_flags_explicit = ptr->x_ix86_isa_flags_explicit; | |
807 | opts->x_ix86_isa_flags2_explicit = ptr->x_ix86_isa_flags2_explicit; | |
808 | opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit; | |
809 | opts->x_ix86_arch_string = ptr->x_ix86_arch_string; | |
810 | opts->x_ix86_tune_string = ptr->x_ix86_tune_string; | |
2bf6d935 ML |
811 | opts->x_ix86_abi = ptr->x_ix86_abi; |
812 | opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect; | |
813 | opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost; | |
814 | opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes; | |
815 | opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer; | |
816 | opts->x_ix86_force_drap = ptr->x_ix86_force_drap; | |
2bf6d935 | 817 | opts->x_ix86_recip_name = ptr->x_ix86_recip_name; |
2bf6d935 ML |
818 | opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold; |
819 | opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx; | |
820 | opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard; | |
821 | opts->x_ix86_stringop_alg = ptr->x_ix86_stringop_alg; | |
822 | opts->x_ix86_tls_dialect = ptr->x_ix86_tls_dialect; | |
823 | opts->x_ix86_tune_ctrl_string = ptr->x_ix86_tune_ctrl_string; | |
824 | opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy; | |
825 | opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy; | |
826 | opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default; | |
2bf6d935 ML |
827 | ix86_tune_cost = processor_cost_table[ix86_tune]; |
828 | /* TODO: ix86_cost should be chosen at instruction or function granuality | |
829 | so for cold code we use size_cost even in !optimize_size compilation. */ | |
830 | if (opts->x_optimize_size) | |
831 | ix86_cost = &ix86_size_cost; | |
832 | else | |
833 | ix86_cost = ix86_tune_cost; | |
834 | ||
835 | /* Recreate the arch feature tests if the arch changed */ | |
836 | if (old_arch != ix86_arch) | |
837 | { | |
838 | ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch; | |
839 | for (i = 0; i < X86_ARCH_LAST; ++i) | |
840 | ix86_arch_features[i] | |
841 | = !!(initial_ix86_arch_features[i] & ix86_arch_mask); | |
842 | } | |
843 | ||
844 | /* Recreate the tune optimization tests */ | |
845 | if (old_tune != ix86_tune) | |
1e964774 | 846 | set_ix86_tune_features (opts, ix86_tune, false); |
2bf6d935 ML |
847 | } |
848 | ||
849 | /* Adjust target options after streaming them in. This is mainly about | |
850 | reconciling them with global options. */ | |
851 | ||
852 | void | |
853 | ix86_function_specific_post_stream_in (struct cl_target_option *ptr) | |
854 | { | |
855 | /* flag_pic is a global option, but ix86_cmodel is target saved option | |
856 | partly computed from flag_pic. If flag_pic is on, adjust x_ix86_cmodel | |
857 | for PIC, or error out. */ | |
858 | if (flag_pic) | |
859 | switch (ptr->x_ix86_cmodel) | |
860 | { | |
861 | case CM_SMALL: | |
862 | ptr->x_ix86_cmodel = CM_SMALL_PIC; | |
863 | break; | |
864 | ||
865 | case CM_MEDIUM: | |
866 | ptr->x_ix86_cmodel = CM_MEDIUM_PIC; | |
867 | break; | |
868 | ||
869 | case CM_LARGE: | |
870 | ptr->x_ix86_cmodel = CM_LARGE_PIC; | |
871 | break; | |
872 | ||
873 | case CM_KERNEL: | |
874 | error ("code model %s does not support PIC mode", "kernel"); | |
875 | break; | |
876 | ||
877 | default: | |
878 | break; | |
879 | } | |
880 | else | |
881 | switch (ptr->x_ix86_cmodel) | |
882 | { | |
883 | case CM_SMALL_PIC: | |
884 | ptr->x_ix86_cmodel = CM_SMALL; | |
885 | break; | |
886 | ||
887 | case CM_MEDIUM_PIC: | |
888 | ptr->x_ix86_cmodel = CM_MEDIUM; | |
889 | break; | |
890 | ||
891 | case CM_LARGE_PIC: | |
892 | ptr->x_ix86_cmodel = CM_LARGE; | |
893 | break; | |
894 | ||
895 | default: | |
896 | break; | |
897 | } | |
898 | } | |
899 | ||
900 | /* Print the current options */ | |
901 | ||
902 | void | |
903 | ix86_function_specific_print (FILE *file, int indent, | |
904 | struct cl_target_option *ptr) | |
905 | { | |
906 | char *target_string | |
907 | = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_ix86_isa_flags2, | |
908 | ptr->x_target_flags, ptr->x_ix86_target_flags, | |
46e6341f | 909 | NULL, NULL, ptr->x_ix86_fpmath, |
654cd743 L |
910 | ptr->x_prefer_vector_width_type, |
911 | ptr->x_ix86_move_max, ptr->x_ix86_store_max, | |
912 | false, true); | |
2bf6d935 ML |
913 | |
914 | gcc_assert (ptr->arch < PROCESSOR_max); | |
915 | fprintf (file, "%*sarch = %d (%s)\n", | |
916 | indent, "", | |
917 | ptr->arch, processor_names[ptr->arch]); | |
918 | ||
919 | gcc_assert (ptr->tune < PROCESSOR_max); | |
920 | fprintf (file, "%*stune = %d (%s)\n", | |
921 | indent, "", | |
922 | ptr->tune, processor_names[ptr->tune]); | |
923 | ||
924 | fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost); | |
925 | ||
926 | if (target_string) | |
927 | { | |
928 | fprintf (file, "%*s%s\n", indent, "", target_string); | |
929 | free (target_string); | |
930 | } | |
931 | } | |
932 | ||
933 | \f | |
934 | /* Inner function to process the attribute((target(...))), take an argument and | |
935 | set the current options from the argument. If we have a list, recursively go | |
936 | over the list. */ | |
937 | ||
938 | static bool | |
939 | ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[], | |
940 | struct gcc_options *opts, | |
941 | struct gcc_options *opts_set, | |
942 | struct gcc_options *enum_opts_set, | |
943 | bool target_clone_attr) | |
944 | { | |
945 | char *next_optstr; | |
946 | bool ret = true; | |
947 | ||
948 | #define IX86_ATTR_ISA(S,O) { S, sizeof (S)-1, ix86_opt_isa, O, 0 } | |
949 | #define IX86_ATTR_STR(S,O) { S, sizeof (S)-1, ix86_opt_str, O, 0 } | |
950 | #define IX86_ATTR_ENUM(S,O) { S, sizeof (S)-1, ix86_opt_enum, O, 0 } | |
951 | #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M } | |
952 | #define IX86_ATTR_NO(S,O,M) { S, sizeof (S)-1, ix86_opt_no, O, M } | |
87c753ac L |
953 | #define IX86_ATTR_IX86_YES(S,O,M) \ |
954 | { S, sizeof (S)-1, ix86_opt_ix86_yes, O, M } | |
955 | #define IX86_ATTR_IX86_NO(S,O,M) \ | |
956 | { S, sizeof (S)-1, ix86_opt_ix86_no, O, M } | |
2bf6d935 ML |
957 | |
958 | enum ix86_opt_type | |
959 | { | |
960 | ix86_opt_unknown, | |
961 | ix86_opt_yes, | |
962 | ix86_opt_no, | |
87c753ac L |
963 | ix86_opt_ix86_yes, |
964 | ix86_opt_ix86_no, | |
2bf6d935 ML |
965 | ix86_opt_str, |
966 | ix86_opt_enum, | |
967 | ix86_opt_isa | |
968 | }; | |
969 | ||
970 | static const struct | |
971 | { | |
972 | const char *string; | |
973 | size_t len; | |
974 | enum ix86_opt_type type; | |
975 | int opt; | |
976 | int mask; | |
977 | } attrs[] = { | |
978 | /* isa options */ | |
979 | IX86_ATTR_ISA ("pconfig", OPT_mpconfig), | |
980 | IX86_ATTR_ISA ("wbnoinvd", OPT_mwbnoinvd), | |
981 | IX86_ATTR_ISA ("sgx", OPT_msgx), | |
982 | IX86_ATTR_ISA ("avx5124fmaps", OPT_mavx5124fmaps), | |
983 | IX86_ATTR_ISA ("avx5124vnniw", OPT_mavx5124vnniw), | |
984 | IX86_ATTR_ISA ("avx512vpopcntdq", OPT_mavx512vpopcntdq), | |
985 | IX86_ATTR_ISA ("avx512vbmi2", OPT_mavx512vbmi2), | |
986 | IX86_ATTR_ISA ("avx512vnni", OPT_mavx512vnni), | |
987 | IX86_ATTR_ISA ("avx512bitalg", OPT_mavx512bitalg), | |
e21b52af | 988 | IX86_ATTR_ISA ("avx512vp2intersect", OPT_mavx512vp2intersect), |
2bf6d935 ML |
989 | |
990 | IX86_ATTR_ISA ("avx512vbmi", OPT_mavx512vbmi), | |
991 | IX86_ATTR_ISA ("avx512ifma", OPT_mavx512ifma), | |
992 | IX86_ATTR_ISA ("avx512vl", OPT_mavx512vl), | |
993 | IX86_ATTR_ISA ("avx512bw", OPT_mavx512bw), | |
994 | IX86_ATTR_ISA ("avx512dq", OPT_mavx512dq), | |
995 | IX86_ATTR_ISA ("avx512er", OPT_mavx512er), | |
996 | IX86_ATTR_ISA ("avx512pf", OPT_mavx512pf), | |
997 | IX86_ATTR_ISA ("avx512cd", OPT_mavx512cd), | |
998 | IX86_ATTR_ISA ("avx512f", OPT_mavx512f), | |
999 | IX86_ATTR_ISA ("avx2", OPT_mavx2), | |
1000 | IX86_ATTR_ISA ("fma", OPT_mfma), | |
1001 | IX86_ATTR_ISA ("xop", OPT_mxop), | |
1002 | IX86_ATTR_ISA ("fma4", OPT_mfma4), | |
1003 | IX86_ATTR_ISA ("f16c", OPT_mf16c), | |
1004 | IX86_ATTR_ISA ("avx", OPT_mavx), | |
1005 | IX86_ATTR_ISA ("sse4", OPT_msse4), | |
1006 | IX86_ATTR_ISA ("sse4.2", OPT_msse4_2), | |
1007 | IX86_ATTR_ISA ("sse4.1", OPT_msse4_1), | |
1008 | IX86_ATTR_ISA ("sse4a", OPT_msse4a), | |
1009 | IX86_ATTR_ISA ("ssse3", OPT_mssse3), | |
1010 | IX86_ATTR_ISA ("sse3", OPT_msse3), | |
1011 | IX86_ATTR_ISA ("aes", OPT_maes), | |
1012 | IX86_ATTR_ISA ("sha", OPT_msha), | |
1013 | IX86_ATTR_ISA ("pclmul", OPT_mpclmul), | |
1014 | IX86_ATTR_ISA ("sse2", OPT_msse2), | |
1015 | IX86_ATTR_ISA ("sse", OPT_msse), | |
1016 | IX86_ATTR_ISA ("3dnowa", OPT_m3dnowa), | |
1017 | IX86_ATTR_ISA ("3dnow", OPT_m3dnow), | |
1018 | IX86_ATTR_ISA ("mmx", OPT_mmmx), | |
1019 | IX86_ATTR_ISA ("rtm", OPT_mrtm), | |
1020 | IX86_ATTR_ISA ("prfchw", OPT_mprfchw), | |
1021 | IX86_ATTR_ISA ("rdseed", OPT_mrdseed), | |
1022 | IX86_ATTR_ISA ("adx", OPT_madx), | |
1023 | IX86_ATTR_ISA ("prefetchwt1", OPT_mprefetchwt1), | |
1024 | IX86_ATTR_ISA ("clflushopt", OPT_mclflushopt), | |
1025 | IX86_ATTR_ISA ("xsaves", OPT_mxsaves), | |
1026 | IX86_ATTR_ISA ("xsavec", OPT_mxsavec), | |
1027 | IX86_ATTR_ISA ("xsaveopt", OPT_mxsaveopt), | |
1028 | IX86_ATTR_ISA ("xsave", OPT_mxsave), | |
1029 | IX86_ATTR_ISA ("abm", OPT_mabm), | |
1030 | IX86_ATTR_ISA ("bmi", OPT_mbmi), | |
1031 | IX86_ATTR_ISA ("bmi2", OPT_mbmi2), | |
1032 | IX86_ATTR_ISA ("lzcnt", OPT_mlzcnt), | |
1033 | IX86_ATTR_ISA ("tbm", OPT_mtbm), | |
1034 | IX86_ATTR_ISA ("popcnt", OPT_mpopcnt), | |
1035 | IX86_ATTR_ISA ("cx16", OPT_mcx16), | |
1036 | IX86_ATTR_ISA ("sahf", OPT_msahf), | |
1037 | IX86_ATTR_ISA ("movbe", OPT_mmovbe), | |
1038 | IX86_ATTR_ISA ("crc32", OPT_mcrc32), | |
1039 | IX86_ATTR_ISA ("fsgsbase", OPT_mfsgsbase), | |
1040 | IX86_ATTR_ISA ("rdrnd", OPT_mrdrnd), | |
1041 | IX86_ATTR_ISA ("mwaitx", OPT_mmwaitx), | |
d8c6cc2c | 1042 | IX86_ATTR_ISA ("mwait", OPT_mmwait), |
2bf6d935 ML |
1043 | IX86_ATTR_ISA ("clzero", OPT_mclzero), |
1044 | IX86_ATTR_ISA ("pku", OPT_mpku), | |
1045 | IX86_ATTR_ISA ("lwp", OPT_mlwp), | |
1046 | IX86_ATTR_ISA ("hle", OPT_mhle), | |
1047 | IX86_ATTR_ISA ("fxsr", OPT_mfxsr), | |
1048 | IX86_ATTR_ISA ("clwb", OPT_mclwb), | |
1049 | IX86_ATTR_ISA ("rdpid", OPT_mrdpid), | |
1050 | IX86_ATTR_ISA ("gfni", OPT_mgfni), | |
1051 | IX86_ATTR_ISA ("shstk", OPT_mshstk), | |
1052 | IX86_ATTR_ISA ("vaes", OPT_mvaes), | |
1053 | IX86_ATTR_ISA ("vpclmulqdq", OPT_mvpclmulqdq), | |
1054 | IX86_ATTR_ISA ("movdiri", OPT_mmovdiri), | |
1055 | IX86_ATTR_ISA ("movdir64b", OPT_mmovdir64b), | |
1056 | IX86_ATTR_ISA ("waitpkg", OPT_mwaitpkg), | |
1057 | IX86_ATTR_ISA ("cldemote", OPT_mcldemote), | |
299a53d7 | 1058 | IX86_ATTR_ISA ("uintr", OPT_muintr), |
2bf6d935 | 1059 | IX86_ATTR_ISA ("ptwrite", OPT_mptwrite), |
632a2f50 | 1060 | IX86_ATTR_ISA ("kl", OPT_mkl), |
1061 | IX86_ATTR_ISA ("widekl", OPT_mwidekl), | |
4f0e90fa | 1062 | IX86_ATTR_ISA ("avx512bf16", OPT_mavx512bf16), |
6a10feda | 1063 | IX86_ATTR_ISA ("enqcmd", OPT_menqcmd), |
366386c7 | 1064 | IX86_ATTR_ISA ("serialize", OPT_mserialize), |
1e47cb35 | 1065 | IX86_ATTR_ISA ("tsxldtrk", OPT_mtsxldtrk), |
5c609842 | 1066 | IX86_ATTR_ISA ("amx-tile", OPT_mamx_tile), |
1067 | IX86_ATTR_ISA ("amx-int8", OPT_mamx_int8), | |
1068 | IX86_ATTR_ISA ("amx-bf16", OPT_mamx_bf16), | |
83927c63 | 1069 | IX86_ATTR_ISA ("hreset", OPT_mhreset), |
ca813880 | 1070 | IX86_ATTR_ISA ("avxvnni", OPT_mavxvnni), |
a6841211 | 1071 | IX86_ATTR_ISA ("avx512fp16", OPT_mavx512fp16), |
2bf6d935 ML |
1072 | |
1073 | /* enum options */ | |
1074 | IX86_ATTR_ENUM ("fpmath=", OPT_mfpmath_), | |
46e6341f | 1075 | IX86_ATTR_ENUM ("prefer-vector-width=", OPT_mprefer_vector_width_), |
2bf6d935 ML |
1076 | |
1077 | /* string options */ | |
1078 | IX86_ATTR_STR ("arch=", IX86_FUNCTION_SPECIFIC_ARCH), | |
1079 | IX86_ATTR_STR ("tune=", IX86_FUNCTION_SPECIFIC_TUNE), | |
1080 | ||
1081 | /* flag options */ | |
1082 | IX86_ATTR_YES ("cld", | |
1083 | OPT_mcld, | |
1084 | MASK_CLD), | |
1085 | ||
1086 | IX86_ATTR_NO ("fancy-math-387", | |
1087 | OPT_mfancy_math_387, | |
1088 | MASK_NO_FANCY_MATH_387), | |
1089 | ||
1090 | IX86_ATTR_YES ("ieee-fp", | |
1091 | OPT_mieee_fp, | |
1092 | MASK_IEEE_FP), | |
1093 | ||
1094 | IX86_ATTR_YES ("inline-all-stringops", | |
1095 | OPT_minline_all_stringops, | |
1096 | MASK_INLINE_ALL_STRINGOPS), | |
1097 | ||
1098 | IX86_ATTR_YES ("inline-stringops-dynamically", | |
1099 | OPT_minline_stringops_dynamically, | |
1100 | MASK_INLINE_STRINGOPS_DYNAMICALLY), | |
1101 | ||
1102 | IX86_ATTR_NO ("align-stringops", | |
1103 | OPT_mno_align_stringops, | |
1104 | MASK_NO_ALIGN_STRINGOPS), | |
1105 | ||
1106 | IX86_ATTR_YES ("recip", | |
1107 | OPT_mrecip, | |
1108 | MASK_RECIP), | |
87c753ac L |
1109 | |
1110 | IX86_ATTR_IX86_YES ("general-regs-only", | |
1111 | OPT_mgeneral_regs_only, | |
1112 | OPTION_MASK_GENERAL_REGS_ONLY), | |
4d281ff7 HW |
1113 | |
1114 | IX86_ATTR_YES ("relax-cmpxchg-loop", | |
1115 | OPT_mrelax_cmpxchg_loop, | |
1116 | MASK_RELAX_CMPXCHG_LOOP), | |
2bf6d935 ML |
1117 | }; |
1118 | ||
1119 | location_t loc | |
1120 | = fndecl == NULL ? UNKNOWN_LOCATION : DECL_SOURCE_LOCATION (fndecl); | |
1121 | const char *attr_name = target_clone_attr ? "target_clone" : "target"; | |
1122 | ||
1123 | /* If this is a list, recurse to get the options. */ | |
1124 | if (TREE_CODE (args) == TREE_LIST) | |
1125 | { | |
2bf6d935 ML |
1126 | for (; args; args = TREE_CHAIN (args)) |
1127 | if (TREE_VALUE (args) | |
1128 | && !ix86_valid_target_attribute_inner_p (fndecl, TREE_VALUE (args), | |
1129 | p_strings, opts, opts_set, | |
1130 | enum_opts_set, | |
1131 | target_clone_attr)) | |
1132 | ret = false; | |
1133 | ||
1134 | return ret; | |
1135 | } | |
1136 | ||
1137 | else if (TREE_CODE (args) != STRING_CST) | |
1138 | { | |
1139 | error_at (loc, "attribute %qs argument is not a string", attr_name); | |
1140 | return false; | |
1141 | } | |
1142 | ||
1143 | /* Handle multiple arguments separated by commas. */ | |
1144 | next_optstr = ASTRDUP (TREE_STRING_POINTER (args)); | |
1145 | ||
1146 | while (next_optstr && *next_optstr != '\0') | |
1147 | { | |
1148 | char *p = next_optstr; | |
1149 | char *orig_p = p; | |
1150 | char *comma = strchr (next_optstr, ','); | |
1151 | size_t len, opt_len; | |
1152 | int opt; | |
1153 | bool opt_set_p; | |
1154 | char ch; | |
1155 | unsigned i; | |
1156 | enum ix86_opt_type type = ix86_opt_unknown; | |
1157 | int mask = 0; | |
1158 | ||
1159 | if (comma) | |
1160 | { | |
1161 | *comma = '\0'; | |
1162 | len = comma - next_optstr; | |
1163 | next_optstr = comma + 1; | |
1164 | } | |
1165 | else | |
1166 | { | |
1167 | len = strlen (p); | |
1168 | next_optstr = NULL; | |
1169 | } | |
1170 | ||
1171 | /* Recognize no-xxx. */ | |
1172 | if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-') | |
1173 | { | |
1174 | opt_set_p = false; | |
1175 | p += 3; | |
1176 | len -= 3; | |
1177 | } | |
1178 | else | |
1179 | opt_set_p = true; | |
1180 | ||
1181 | /* Find the option. */ | |
1182 | ch = *p; | |
1183 | opt = N_OPTS; | |
1184 | for (i = 0; i < ARRAY_SIZE (attrs); i++) | |
1185 | { | |
1186 | type = attrs[i].type; | |
1187 | opt_len = attrs[i].len; | |
1188 | if (ch == attrs[i].string[0] | |
1189 | && ((type != ix86_opt_str && type != ix86_opt_enum) | |
1190 | ? len == opt_len | |
1191 | : len > opt_len) | |
1192 | && memcmp (p, attrs[i].string, opt_len) == 0) | |
1193 | { | |
1194 | opt = attrs[i].opt; | |
1195 | mask = attrs[i].mask; | |
1196 | break; | |
1197 | } | |
1198 | } | |
1199 | ||
1200 | /* Process the option. */ | |
1201 | if (opt == N_OPTS) | |
1202 | { | |
1203 | error_at (loc, "attribute %qs argument %qs is unknown", | |
1204 | orig_p, attr_name); | |
1205 | ret = false; | |
1206 | } | |
1207 | ||
1208 | else if (type == ix86_opt_isa) | |
1209 | { | |
1210 | struct cl_decoded_option decoded; | |
1211 | ||
1212 | generate_option (opt, NULL, opt_set_p, CL_TARGET, &decoded); | |
1213 | ix86_handle_option (opts, opts_set, | |
1214 | &decoded, input_location); | |
1215 | } | |
1216 | ||
1217 | else if (type == ix86_opt_yes || type == ix86_opt_no) | |
1218 | { | |
1219 | if (type == ix86_opt_no) | |
1220 | opt_set_p = !opt_set_p; | |
1221 | ||
1222 | if (opt_set_p) | |
1223 | opts->x_target_flags |= mask; | |
1224 | else | |
1225 | opts->x_target_flags &= ~mask; | |
1226 | } | |
1227 | ||
87c753ac L |
1228 | else if (type == ix86_opt_ix86_yes || type == ix86_opt_ix86_no) |
1229 | { | |
1230 | if (mask == OPTION_MASK_GENERAL_REGS_ONLY) | |
1231 | { | |
8f1ea8dd L |
1232 | if (!opt_set_p) |
1233 | { | |
ca23341b | 1234 | error_at (loc, "pragma or attribute %<target(\"%s\")%> " |
8f1ea8dd L |
1235 | "does not allow a negated form", p); |
1236 | return false; | |
1237 | } | |
1238 | ||
87c753ac L |
1239 | if (type != ix86_opt_ix86_yes) |
1240 | gcc_unreachable (); | |
1241 | ||
1242 | opts->x_ix86_target_flags |= mask; | |
1243 | ||
1244 | struct cl_decoded_option decoded; | |
1245 | generate_option (opt, NULL, opt_set_p, CL_TARGET, | |
1246 | &decoded); | |
1247 | ix86_handle_option (opts, opts_set, &decoded, | |
1248 | input_location); | |
1249 | } | |
1250 | else | |
1251 | { | |
1252 | if (type == ix86_opt_ix86_no) | |
1253 | opt_set_p = !opt_set_p; | |
1254 | ||
1255 | if (opt_set_p) | |
1256 | opts->x_ix86_target_flags |= mask; | |
1257 | else | |
1258 | opts->x_ix86_target_flags &= ~mask; | |
1259 | } | |
1260 | } | |
1261 | ||
2bf6d935 ML |
1262 | else if (type == ix86_opt_str) |
1263 | { | |
1264 | if (p_strings[opt]) | |
1265 | { | |
1266 | error_at (loc, "attribute value %qs was already specified " | |
1267 | "in %qs attribute", orig_p, attr_name); | |
1268 | ret = false; | |
1269 | } | |
1270 | else | |
94cdd3b7 JJ |
1271 | { |
1272 | p_strings[opt] = xstrdup (p + opt_len); | |
1273 | if (opt == IX86_FUNCTION_SPECIFIC_ARCH) | |
1274 | { | |
1275 | /* If arch= is set, clear all bits in x_ix86_isa_flags, | |
1276 | except for ISA_64BIT, ABI_64, ABI_X32, and CODE16 | |
1277 | and all bits in x_ix86_isa_flags2. */ | |
1278 | opts->x_ix86_isa_flags &= (OPTION_MASK_ISA_64BIT | |
1279 | | OPTION_MASK_ABI_64 | |
1280 | | OPTION_MASK_ABI_X32 | |
1281 | | OPTION_MASK_CODE16); | |
1282 | opts->x_ix86_isa_flags_explicit &= (OPTION_MASK_ISA_64BIT | |
1283 | | OPTION_MASK_ABI_64 | |
1284 | | OPTION_MASK_ABI_X32 | |
1285 | | OPTION_MASK_CODE16); | |
1286 | opts->x_ix86_isa_flags2 = 0; | |
1287 | opts->x_ix86_isa_flags2_explicit = 0; | |
1288 | } | |
1289 | } | |
2bf6d935 ML |
1290 | } |
1291 | ||
1292 | else if (type == ix86_opt_enum) | |
1293 | { | |
1294 | bool arg_ok; | |
1295 | int value; | |
1296 | ||
1297 | arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET); | |
1298 | if (arg_ok) | |
1299 | set_option (opts, enum_opts_set, opt, value, | |
1300 | p + opt_len, DK_UNSPECIFIED, input_location, | |
1301 | global_dc); | |
1302 | else | |
1303 | { | |
1304 | error_at (loc, "attribute value %qs is unknown in %qs attribute", | |
1305 | orig_p, attr_name); | |
1306 | ret = false; | |
1307 | } | |
1308 | } | |
1309 | ||
1310 | else | |
1311 | gcc_unreachable (); | |
1312 | } | |
1313 | ||
1314 | return ret; | |
1315 | } | |
1316 | ||
1317 | /* Release allocated strings. */ | |
1318 | static void | |
1319 | release_options_strings (char **option_strings) | |
1320 | { | |
1321 | /* Free up memory allocated to hold the strings */ | |
1322 | for (unsigned i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++) | |
1323 | free (option_strings[i]); | |
1324 | } | |
1325 | ||
1326 | /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */ | |
1327 | ||
1328 | tree | |
1329 | ix86_valid_target_attribute_tree (tree fndecl, tree args, | |
1330 | struct gcc_options *opts, | |
1331 | struct gcc_options *opts_set, | |
1332 | bool target_clone_attr) | |
1333 | { | |
1334 | const char *orig_arch_string = opts->x_ix86_arch_string; | |
1335 | const char *orig_tune_string = opts->x_ix86_tune_string; | |
1336 | enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath; | |
46e6341f | 1337 | enum prefer_vector_width orig_pvw_set = opts_set->x_prefer_vector_width_type; |
654cd743 L |
1338 | enum prefer_vector_width orig_ix86_move_max_set |
1339 | = opts_set->x_ix86_move_max; | |
1340 | enum prefer_vector_width orig_ix86_store_max_set | |
1341 | = opts_set->x_ix86_store_max; | |
2bf6d935 ML |
1342 | int orig_tune_defaulted = ix86_tune_defaulted; |
1343 | int orig_arch_specified = ix86_arch_specified; | |
1344 | char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL }; | |
1345 | tree t = NULL_TREE; | |
1346 | struct cl_target_option *def | |
1347 | = TREE_TARGET_OPTION (target_option_default_node); | |
1348 | struct gcc_options enum_opts_set; | |
1349 | ||
1350 | memset (&enum_opts_set, 0, sizeof (enum_opts_set)); | |
1351 | ||
1352 | /* Process each of the options on the chain. */ | |
1353 | if (!ix86_valid_target_attribute_inner_p (fndecl, args, option_strings, opts, | |
1354 | opts_set, &enum_opts_set, | |
1355 | target_clone_attr)) | |
1356 | return error_mark_node; | |
1357 | ||
1358 | /* If the changed options are different from the default, rerun | |
1359 | ix86_option_override_internal, and then save the options away. | |
1360 | The string options are attribute options, and will be undone | |
1361 | when we copy the save structure. */ | |
1362 | if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags | |
1363 | || opts->x_ix86_isa_flags2 != def->x_ix86_isa_flags2 | |
1364 | || opts->x_target_flags != def->x_target_flags | |
1365 | || option_strings[IX86_FUNCTION_SPECIFIC_ARCH] | |
1366 | || option_strings[IX86_FUNCTION_SPECIFIC_TUNE] | |
46e6341f JJ |
1367 | || enum_opts_set.x_ix86_fpmath |
1368 | || enum_opts_set.x_prefer_vector_width_type) | |
2bf6d935 ML |
1369 | { |
1370 | /* If we are using the default tune= or arch=, undo the string assigned, | |
1371 | and use the default. */ | |
1372 | if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]) | |
94cdd3b7 JJ |
1373 | opts->x_ix86_arch_string |
1374 | = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]); | |
2bf6d935 ML |
1375 | else if (!orig_arch_specified) |
1376 | opts->x_ix86_arch_string = NULL; | |
1377 | ||
1378 | if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE]) | |
1379 | opts->x_ix86_tune_string | |
1380 | = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_TUNE]); | |
1381 | else if (orig_tune_defaulted) | |
1382 | opts->x_ix86_tune_string = NULL; | |
1383 | ||
1384 | /* If fpmath= is not set, and we now have sse2 on 32-bit, use it. */ | |
1385 | if (enum_opts_set.x_ix86_fpmath) | |
1386 | opts_set->x_ix86_fpmath = (enum fpmath_unit) 1; | |
46e6341f JJ |
1387 | if (enum_opts_set.x_prefer_vector_width_type) |
1388 | opts_set->x_prefer_vector_width_type = (enum prefer_vector_width) 1; | |
2bf6d935 ML |
1389 | |
1390 | /* Do any overrides, such as arch=xxx, or tune=xxx support. */ | |
1391 | bool r = ix86_option_override_internal (false, opts, opts_set); | |
1392 | if (!r) | |
1393 | { | |
1394 | release_options_strings (option_strings); | |
1395 | return error_mark_node; | |
1396 | } | |
1397 | ||
1398 | /* Add any builtin functions with the new isa if any. */ | |
1399 | ix86_add_new_builtins (opts->x_ix86_isa_flags, opts->x_ix86_isa_flags2); | |
1400 | ||
e401db7b JJ |
1401 | enum excess_precision orig_ix86_excess_precision |
1402 | = opts->x_ix86_excess_precision; | |
1403 | bool orig_ix86_unsafe_math_optimizations | |
1404 | = opts->x_ix86_unsafe_math_optimizations; | |
1405 | opts->x_ix86_excess_precision = opts->x_flag_excess_precision; | |
1406 | opts->x_ix86_unsafe_math_optimizations | |
1407 | = opts->x_flag_unsafe_math_optimizations; | |
1408 | ||
2bf6d935 ML |
1409 | /* Save the current options unless we are validating options for |
1410 | #pragma. */ | |
ba948b37 | 1411 | t = build_target_option_node (opts, opts_set); |
2bf6d935 ML |
1412 | |
1413 | opts->x_ix86_arch_string = orig_arch_string; | |
1414 | opts->x_ix86_tune_string = orig_tune_string; | |
1415 | opts_set->x_ix86_fpmath = orig_fpmath_set; | |
46e6341f | 1416 | opts_set->x_prefer_vector_width_type = orig_pvw_set; |
654cd743 L |
1417 | opts_set->x_ix86_move_max = orig_ix86_move_max_set; |
1418 | opts_set->x_ix86_store_max = orig_ix86_store_max_set; | |
e401db7b JJ |
1419 | opts->x_ix86_excess_precision = orig_ix86_excess_precision; |
1420 | opts->x_ix86_unsafe_math_optimizations | |
1421 | = orig_ix86_unsafe_math_optimizations; | |
2bf6d935 ML |
1422 | |
1423 | release_options_strings (option_strings); | |
1424 | } | |
1425 | ||
1426 | return t; | |
1427 | } | |
1428 | ||
7e71909a JJ |
1429 | static GTY(()) tree target_attribute_cache[3]; |
1430 | ||
2bf6d935 ML |
1431 | /* Hook to validate attribute((target("string"))). */ |
1432 | ||
1433 | bool | |
1434 | ix86_valid_target_attribute_p (tree fndecl, | |
1435 | tree ARG_UNUSED (name), | |
1436 | tree args, | |
1437 | int flags) | |
1438 | { | |
ba948b37 | 1439 | struct gcc_options func_options, func_options_set; |
2bf6d935 ML |
1440 | tree new_target, new_optimize; |
1441 | bool ret = true; | |
1442 | ||
1443 | /* attribute((target("default"))) does nothing, beyond | |
1444 | affecting multi-versioning. */ | |
1445 | if (TREE_VALUE (args) | |
1446 | && TREE_CODE (TREE_VALUE (args)) == STRING_CST | |
1447 | && TREE_CHAIN (args) == NULL_TREE | |
1448 | && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0) | |
1449 | return true; | |
1450 | ||
7e71909a JJ |
1451 | if ((DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == target_attribute_cache[1] |
1452 | || DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == NULL_TREE) | |
1453 | && (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) | |
1454 | == target_attribute_cache[2] | |
1455 | || DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) == NULL_TREE) | |
1456 | && simple_cst_list_equal (args, target_attribute_cache[0])) | |
1457 | { | |
1458 | DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = target_attribute_cache[1]; | |
1459 | DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) | |
1460 | = target_attribute_cache[2]; | |
1461 | return true; | |
1462 | } | |
1463 | ||
ba948b37 JJ |
1464 | tree old_optimize = build_optimization_node (&global_options, |
1465 | &global_options_set); | |
2bf6d935 ML |
1466 | |
1467 | /* Get the optimization options of the current function. */ | |
1468 | tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl); | |
1469 | ||
1470 | if (!func_optimize) | |
1471 | func_optimize = old_optimize; | |
1472 | ||
1473 | /* Init func_options. */ | |
1474 | memset (&func_options, 0, sizeof (func_options)); | |
1475 | init_options_struct (&func_options, NULL); | |
1476 | lang_hooks.init_options_struct (&func_options); | |
ba948b37 JJ |
1477 | memset (&func_options_set, 0, sizeof (func_options_set)); |
1478 | ||
1479 | cl_optimization_restore (&func_options, &func_options_set, | |
2bf6d935 ML |
1480 | TREE_OPTIMIZATION (func_optimize)); |
1481 | ||
1482 | /* Initialize func_options to the default before its target options can | |
1483 | be set. */ | |
36453971 JJ |
1484 | tree old_target = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); |
1485 | if (old_target == NULL_TREE) | |
1486 | old_target = target_option_default_node; | |
ba948b37 | 1487 | cl_target_option_restore (&func_options, &func_options_set, |
36453971 | 1488 | TREE_TARGET_OPTION (old_target)); |
2bf6d935 ML |
1489 | |
1490 | /* FLAGS == 1 is used for target_clones attribute. */ | |
1491 | new_target | |
1492 | = ix86_valid_target_attribute_tree (fndecl, args, &func_options, | |
ba948b37 | 1493 | &func_options_set, flags == 1); |
2bf6d935 | 1494 | |
ba948b37 | 1495 | new_optimize = build_optimization_node (&func_options, &func_options_set); |
2bf6d935 ML |
1496 | |
1497 | if (new_target == error_mark_node) | |
1498 | ret = false; | |
1499 | ||
7e71909a | 1500 | else if (new_target) |
2bf6d935 | 1501 | { |
7e71909a JJ |
1502 | if (DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == NULL_TREE |
1503 | && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) == NULL_TREE) | |
1504 | { | |
1505 | target_attribute_cache[0] = copy_list (args); | |
1506 | target_attribute_cache[1] = new_target; | |
1507 | target_attribute_cache[2] | |
1508 | = old_optimize != new_optimize ? new_optimize : NULL_TREE; | |
1509 | } | |
1510 | ||
2bf6d935 ML |
1511 | DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target; |
1512 | ||
1513 | if (old_optimize != new_optimize) | |
1514 | DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize; | |
1515 | } | |
1516 | ||
2bf6d935 ML |
1517 | return ret; |
1518 | } | |
1519 | ||
1520 | const char *stringop_alg_names[] = { | |
2bf6d935 ML |
1521 | #define DEF_ALG(alg, name) #name, |
1522 | #include "stringop.def" | |
2bf6d935 ML |
1523 | #undef DEF_ALG |
1524 | }; | |
1525 | ||
1526 | /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=. | |
1527 | The string is of the following form (or comma separated list of it): | |
1528 | ||
1529 | strategy_alg:max_size:[align|noalign] | |
1530 | ||
1531 | where the full size range for the strategy is either [0, max_size] or | |
1532 | [min_size, max_size], in which min_size is the max_size + 1 of the | |
1533 | preceding range. The last size range must have max_size == -1. | |
1534 | ||
1535 | Examples: | |
1536 | ||
1537 | 1. | |
1538 | -mmemcpy-strategy=libcall:-1:noalign | |
1539 | ||
1540 | this is equivalent to (for known size memcpy) -mstringop-strategy=libcall | |
1541 | ||
1542 | ||
1543 | 2. | |
1544 | -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign | |
1545 | ||
1546 | This is to tell the compiler to use the following strategy for memset | |
1547 | 1) when the expected size is between [1, 16], use rep_8byte strategy; | |
1548 | 2) when the size is between [17, 2048], use vector_loop; | |
1549 | 3) when the size is > 2048, use libcall. */ | |
1550 | ||
1551 | struct stringop_size_range | |
1552 | { | |
1553 | int max; | |
1554 | stringop_alg alg; | |
1555 | bool noalign; | |
1556 | }; | |
1557 | ||
1558 | static void | |
1559 | ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset) | |
1560 | { | |
1561 | const struct stringop_algs *default_algs; | |
1562 | stringop_size_range input_ranges[MAX_STRINGOP_ALGS]; | |
1563 | char *curr_range_str, *next_range_str; | |
1564 | const char *opt = is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="; | |
1565 | int i = 0, n = 0; | |
1566 | ||
1567 | if (is_memset) | |
1568 | default_algs = &ix86_cost->memset[TARGET_64BIT != 0]; | |
1569 | else | |
1570 | default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0]; | |
1571 | ||
1572 | curr_range_str = strategy_str; | |
1573 | ||
1574 | do | |
1575 | { | |
1576 | int maxs; | |
1577 | char alg_name[128]; | |
1578 | char align[16]; | |
1579 | next_range_str = strchr (curr_range_str, ','); | |
1580 | if (next_range_str) | |
1581 | *next_range_str++ = '\0'; | |
1582 | ||
1583 | if (sscanf (curr_range_str, "%20[^:]:%d:%10s", alg_name, &maxs, | |
1584 | align) != 3) | |
1585 | { | |
1586 | error ("wrong argument %qs to option %qs", curr_range_str, opt); | |
1587 | return; | |
1588 | } | |
1589 | ||
1590 | if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1)) | |
1591 | { | |
1592 | error ("size ranges of option %qs should be increasing", opt); | |
1593 | return; | |
1594 | } | |
1595 | ||
1596 | for (i = 0; i < last_alg; i++) | |
1597 | if (!strcmp (alg_name, stringop_alg_names[i])) | |
1598 | break; | |
1599 | ||
1600 | if (i == last_alg) | |
1601 | { | |
1602 | error ("wrong strategy name %qs specified for option %qs", | |
1603 | alg_name, opt); | |
1604 | ||
1605 | auto_vec <const char *> candidates; | |
1606 | for (i = 0; i < last_alg; i++) | |
1607 | if ((stringop_alg) i != rep_prefix_8_byte || TARGET_64BIT) | |
1608 | candidates.safe_push (stringop_alg_names[i]); | |
1609 | ||
1610 | char *s; | |
1611 | const char *hint | |
1612 | = candidates_list_and_hint (alg_name, s, candidates); | |
1613 | if (hint) | |
1614 | inform (input_location, | |
1615 | "valid arguments to %qs are: %s; did you mean %qs?", | |
1616 | opt, s, hint); | |
1617 | else | |
1618 | inform (input_location, "valid arguments to %qs are: %s", | |
1619 | opt, s); | |
1620 | XDELETEVEC (s); | |
1621 | return; | |
1622 | } | |
1623 | ||
1624 | if ((stringop_alg) i == rep_prefix_8_byte | |
1625 | && !TARGET_64BIT) | |
1626 | { | |
1627 | /* rep; movq isn't available in 32-bit code. */ | |
1628 | error ("strategy name %qs specified for option %qs " | |
1629 | "not supported for 32-bit code", alg_name, opt); | |
1630 | return; | |
1631 | } | |
1632 | ||
1633 | input_ranges[n].max = maxs; | |
1634 | input_ranges[n].alg = (stringop_alg) i; | |
1635 | if (!strcmp (align, "align")) | |
1636 | input_ranges[n].noalign = false; | |
1637 | else if (!strcmp (align, "noalign")) | |
1638 | input_ranges[n].noalign = true; | |
1639 | else | |
1640 | { | |
1641 | error ("unknown alignment %qs specified for option %qs", align, opt); | |
1642 | return; | |
1643 | } | |
1644 | n++; | |
1645 | curr_range_str = next_range_str; | |
1646 | } | |
1647 | while (curr_range_str); | |
1648 | ||
1649 | if (input_ranges[n - 1].max != -1) | |
1650 | { | |
1651 | error ("the max value for the last size range should be -1" | |
1652 | " for option %qs", opt); | |
1653 | return; | |
1654 | } | |
1655 | ||
1656 | if (n > MAX_STRINGOP_ALGS) | |
1657 | { | |
1658 | error ("too many size ranges specified in option %qs", opt); | |
1659 | return; | |
1660 | } | |
1661 | ||
1662 | /* Now override the default algs array. */ | |
1663 | for (i = 0; i < n; i++) | |
1664 | { | |
1665 | *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max; | |
1666 | *const_cast<stringop_alg *>(&default_algs->size[i].alg) | |
1667 | = input_ranges[i].alg; | |
1668 | *const_cast<int *>(&default_algs->size[i].noalign) | |
1669 | = input_ranges[i].noalign; | |
1670 | } | |
1671 | } | |
1672 | ||
1673 | \f | |
1674 | /* parse -mtune-ctrl= option. When DUMP is true, | |
1675 | print the features that are explicitly set. */ | |
1676 | ||
1677 | static void | |
1e964774 | 1678 | parse_mtune_ctrl_str (struct gcc_options *opts, bool dump) |
2bf6d935 | 1679 | { |
1e964774 | 1680 | if (!opts->x_ix86_tune_ctrl_string) |
2bf6d935 ML |
1681 | return; |
1682 | ||
1683 | char *next_feature_string = NULL; | |
1e964774 | 1684 | char *curr_feature_string = xstrdup (opts->x_ix86_tune_ctrl_string); |
2bf6d935 ML |
1685 | char *orig = curr_feature_string; |
1686 | int i; | |
1687 | do | |
1688 | { | |
1689 | bool clear = false; | |
1690 | ||
1691 | next_feature_string = strchr (curr_feature_string, ','); | |
1692 | if (next_feature_string) | |
1693 | *next_feature_string++ = '\0'; | |
1694 | if (*curr_feature_string == '^') | |
1695 | { | |
1696 | curr_feature_string++; | |
1697 | clear = true; | |
1698 | } | |
1699 | for (i = 0; i < X86_TUNE_LAST; i++) | |
1700 | { | |
1701 | if (!strcmp (curr_feature_string, ix86_tune_feature_names[i])) | |
1702 | { | |
1703 | ix86_tune_features[i] = !clear; | |
1704 | if (dump) | |
1705 | fprintf (stderr, "Explicitly %s feature %s\n", | |
1706 | clear ? "clear" : "set", ix86_tune_feature_names[i]); | |
1707 | break; | |
1708 | } | |
1709 | } | |
1710 | if (i == X86_TUNE_LAST) | |
1711 | error ("unknown parameter to option %<-mtune-ctrl%>: %s", | |
1712 | clear ? curr_feature_string - 1 : curr_feature_string); | |
1713 | curr_feature_string = next_feature_string; | |
1714 | } | |
1715 | while (curr_feature_string); | |
1716 | free (orig); | |
1717 | } | |
1718 | ||
1719 | /* Helper function to set ix86_tune_features. IX86_TUNE is the | |
1720 | processor type. */ | |
1721 | ||
1722 | static void | |
1e964774 L |
1723 | set_ix86_tune_features (struct gcc_options *opts, |
1724 | enum processor_type ix86_tune, bool dump) | |
2bf6d935 ML |
1725 | { |
1726 | unsigned HOST_WIDE_INT ix86_tune_mask = HOST_WIDE_INT_1U << ix86_tune; | |
1727 | int i; | |
1728 | ||
1729 | for (i = 0; i < X86_TUNE_LAST; ++i) | |
1730 | { | |
1731 | if (ix86_tune_no_default) | |
1732 | ix86_tune_features[i] = 0; | |
1733 | else | |
1734 | ix86_tune_features[i] | |
1735 | = !!(initial_ix86_tune_features[i] & ix86_tune_mask); | |
1736 | } | |
1737 | ||
1738 | if (dump) | |
1739 | { | |
1740 | fprintf (stderr, "List of x86 specific tuning parameter names:\n"); | |
1741 | for (i = 0; i < X86_TUNE_LAST; i++) | |
1742 | fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i], | |
1743 | ix86_tune_features[i] ? "on" : "off"); | |
1744 | } | |
1745 | ||
1e964774 | 1746 | parse_mtune_ctrl_str (opts, dump); |
2bf6d935 ML |
1747 | } |
1748 | ||
1749 | ||
1750 | /* Default align_* from the processor table. */ | |
1751 | ||
1752 | static void | |
1753 | ix86_default_align (struct gcc_options *opts) | |
1754 | { | |
1755 | /* -falign-foo without argument: supply one. */ | |
1756 | if (opts->x_flag_align_loops && !opts->x_str_align_loops) | |
1757 | opts->x_str_align_loops = processor_cost_table[ix86_tune]->align_loop; | |
1758 | if (opts->x_flag_align_jumps && !opts->x_str_align_jumps) | |
1759 | opts->x_str_align_jumps = processor_cost_table[ix86_tune]->align_jump; | |
1760 | if (opts->x_flag_align_labels && !opts->x_str_align_labels) | |
1761 | opts->x_str_align_labels = processor_cost_table[ix86_tune]->align_label; | |
1762 | if (opts->x_flag_align_functions && !opts->x_str_align_functions) | |
1763 | opts->x_str_align_functions = processor_cost_table[ix86_tune]->align_func; | |
1764 | } | |
1765 | ||
6bc89193 AO |
1766 | #ifndef USE_IX86_FRAME_POINTER |
1767 | #define USE_IX86_FRAME_POINTER 0 | |
1768 | #endif | |
1769 | ||
1770 | /* (Re)compute option overrides affected by optimization levels in | |
1771 | target-specific ways. */ | |
1772 | ||
1773 | static void | |
1774 | ix86_recompute_optlev_based_flags (struct gcc_options *opts, | |
1775 | struct gcc_options *opts_set) | |
1776 | { | |
1777 | /* Set the default values for switches whose default depends on TARGET_64BIT | |
1778 | in case they weren't overwritten by command line options. */ | |
1779 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
1780 | { | |
6ed76044 ML |
1781 | if (opts->x_optimize >= 1) |
1782 | SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer, | |
1783 | !USE_IX86_FRAME_POINTER); | |
6bc89193 | 1784 | if (opts->x_flag_asynchronous_unwind_tables |
6bc89193 | 1785 | && TARGET_64BIT_MS_ABI) |
6ed76044 | 1786 | SET_OPTION_IF_UNSET (opts, opts_set, flag_unwind_tables, 1); |
6bc89193 AO |
1787 | if (opts->x_flag_asynchronous_unwind_tables == 2) |
1788 | opts->x_flag_unwind_tables | |
1789 | = opts->x_flag_asynchronous_unwind_tables = 1; | |
1790 | if (opts->x_flag_pcc_struct_return == 2) | |
1791 | opts->x_flag_pcc_struct_return = 0; | |
1792 | } | |
1793 | else | |
1794 | { | |
6ed76044 ML |
1795 | if (opts->x_optimize >= 1) |
1796 | SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer, | |
1797 | !(USE_IX86_FRAME_POINTER || opts->x_optimize_size)); | |
6bc89193 AO |
1798 | if (opts->x_flag_asynchronous_unwind_tables == 2) |
1799 | opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER; | |
1800 | if (opts->x_flag_pcc_struct_return == 2) | |
1801 | { | |
1802 | /* Intel MCU psABI specifies that -freg-struct-return should | |
c4f63307 | 1803 | be on. Instead of setting DEFAULT_PCC_STRUCT_RETURN to 0, |
6bc89193 AO |
1804 | we check -miamcu so that -freg-struct-return is always |
1805 | turned on if -miamcu is used. */ | |
1806 | if (TARGET_IAMCU_P (opts->x_target_flags)) | |
1807 | opts->x_flag_pcc_struct_return = 0; | |
1808 | else | |
1809 | opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN; | |
1810 | } | |
1811 | } | |
1812 | } | |
1813 | ||
2bf6d935 ML |
1814 | /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook. */ |
1815 | ||
1816 | void | |
1817 | ix86_override_options_after_change (void) | |
1818 | { | |
1819 | ix86_default_align (&global_options); | |
6bc89193 | 1820 | ix86_recompute_optlev_based_flags (&global_options, &global_options_set); |
2bf6d935 ML |
1821 | } |
1822 | ||
1823 | /* Clear stack slot assignments remembered from previous functions. | |
1824 | This is called from INIT_EXPANDERS once before RTL is emitted for each | |
1825 | function. */ | |
1826 | ||
1827 | static struct machine_function * | |
1828 | ix86_init_machine_status (void) | |
1829 | { | |
1830 | struct machine_function *f; | |
1831 | ||
1832 | f = ggc_cleared_alloc<machine_function> (); | |
1833 | f->call_abi = ix86_abi; | |
c2080a1f | 1834 | f->stack_frame_required = true; |
5e2eabe1 | 1835 | f->silent_p = true; |
2bf6d935 ML |
1836 | |
1837 | return f; | |
1838 | } | |
1839 | ||
1840 | /* Override various settings based on options. If MAIN_ARGS_P, the | |
1841 | options are from the command line, otherwise they are from | |
1842 | attributes. Return true if there's an error related to march | |
1843 | option. */ | |
1844 | ||
1845 | static bool | |
1846 | ix86_option_override_internal (bool main_args_p, | |
1847 | struct gcc_options *opts, | |
1848 | struct gcc_options *opts_set) | |
1849 | { | |
5ebdd535 | 1850 | unsigned int i; |
2bf6d935 ML |
1851 | unsigned HOST_WIDE_INT ix86_arch_mask; |
1852 | const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL); | |
1853 | ||
1854 | /* -mrecip options. */ | |
1855 | static struct | |
1856 | { | |
1857 | const char *string; /* option name */ | |
1858 | unsigned int mask; /* mask bits to set */ | |
1859 | } | |
1860 | const recip_options[] = | |
1861 | { | |
1862 | { "all", RECIP_MASK_ALL }, | |
1863 | { "none", RECIP_MASK_NONE }, | |
1864 | { "div", RECIP_MASK_DIV }, | |
1865 | { "sqrt", RECIP_MASK_SQRT }, | |
1866 | { "vec-div", RECIP_MASK_VEC_DIV }, | |
1867 | { "vec-sqrt", RECIP_MASK_VEC_SQRT }, | |
1868 | }; | |
1869 | ||
1870 | ||
1871 | /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if | |
1872 | TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false. */ | |
1873 | if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
1874 | opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32); | |
1875 | #ifdef TARGET_BI_ARCH | |
1876 | else | |
1877 | { | |
1878 | #if TARGET_BI_ARCH == 1 | |
1879 | /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64 | |
1880 | is on and OPTION_MASK_ABI_X32 is off. We turn off | |
1881 | OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by | |
1882 | -mx32. */ | |
1883 | if (TARGET_X32_P (opts->x_ix86_isa_flags)) | |
1884 | opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64; | |
1885 | #else | |
1886 | /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is | |
1887 | on and OPTION_MASK_ABI_64 is off. We turn off | |
1888 | OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by | |
1889 | -m64 or OPTION_MASK_CODE16 is turned on by -m16. */ | |
1890 | if (TARGET_LP64_P (opts->x_ix86_isa_flags) | |
1891 | || TARGET_16BIT_P (opts->x_ix86_isa_flags)) | |
1892 | opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32; | |
1893 | #endif | |
1894 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
1895 | && TARGET_IAMCU_P (opts->x_target_flags)) | |
1896 | sorry ("Intel MCU psABI isn%'t supported in %s mode", | |
1897 | TARGET_X32_P (opts->x_ix86_isa_flags) ? "x32" : "64-bit"); | |
1898 | } | |
1899 | #endif | |
1900 | ||
1901 | if (TARGET_X32_P (opts->x_ix86_isa_flags)) | |
1902 | { | |
1903 | /* Always turn on OPTION_MASK_ISA_64BIT and turn off | |
1904 | OPTION_MASK_ABI_64 for TARGET_X32. */ | |
1905 | opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT; | |
1906 | opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64; | |
1907 | } | |
1908 | else if (TARGET_16BIT_P (opts->x_ix86_isa_flags)) | |
1909 | opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT | |
1910 | | OPTION_MASK_ABI_X32 | |
1911 | | OPTION_MASK_ABI_64); | |
1912 | else if (TARGET_LP64_P (opts->x_ix86_isa_flags)) | |
1913 | { | |
1914 | /* Always turn on OPTION_MASK_ISA_64BIT and turn off | |
1915 | OPTION_MASK_ABI_X32 for TARGET_LP64. */ | |
1916 | opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT; | |
1917 | opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32; | |
1918 | } | |
1919 | ||
1920 | #ifdef SUBTARGET_OVERRIDE_OPTIONS | |
1921 | SUBTARGET_OVERRIDE_OPTIONS; | |
1922 | #endif | |
1923 | ||
1924 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
1925 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
1926 | #endif | |
1927 | ||
a49a96f6 JJ |
1928 | #ifdef HAVE_LD_BROKEN_PE_DWARF5 |
1929 | /* If the PE linker has broken DWARF 5 support, make | |
1930 | DWARF 4 the default. */ | |
1931 | if (TARGET_PECOFF) | |
1932 | SET_OPTION_IF_UNSET (opts, opts_set, dwarf_version, 4); | |
1933 | #endif | |
1934 | ||
2bf6d935 ML |
1935 | /* -fPIC is the default for x86_64. */ |
1936 | if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
1937 | opts->x_flag_pic = 2; | |
1938 | ||
1939 | /* Need to check -mtune=generic first. */ | |
1940 | if (opts->x_ix86_tune_string) | |
1941 | { | |
1942 | /* As special support for cross compilers we read -mtune=native | |
1943 | as -mtune=generic. With native compilers we won't see the | |
1944 | -mtune=native, as it was changed by the driver. */ | |
1945 | if (!strcmp (opts->x_ix86_tune_string, "native")) | |
69bd5d47 | 1946 | opts->x_ix86_tune_string = "generic"; |
2bf6d935 ML |
1947 | else if (!strcmp (opts->x_ix86_tune_string, "x86-64")) |
1948 | warning (OPT_Wdeprecated, | |
1949 | main_args_p | |
1950 | ? G_("%<-mtune=x86-64%> is deprecated; use %<-mtune=k8%> " | |
1951 | "or %<-mtune=generic%> instead as appropriate") | |
1952 | : G_("%<target(\"tune=x86-64\")%> is deprecated; use " | |
1953 | "%<target(\"tune=k8\")%> or %<target(\"tune=generic\")%>" | |
1954 | " instead as appropriate")); | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | if (opts->x_ix86_arch_string) | |
1959 | opts->x_ix86_tune_string = opts->x_ix86_arch_string; | |
1960 | if (!opts->x_ix86_tune_string) | |
1961 | { | |
1962 | opts->x_ix86_tune_string = processor_names[TARGET_CPU_DEFAULT]; | |
1963 | ix86_tune_defaulted = 1; | |
1964 | } | |
1965 | ||
1966 | /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string | |
1967 | or defaulted. We need to use a sensible tune option. */ | |
c0129e2d | 1968 | if (startswith (opts->x_ix86_tune_string, "x86-64") |
69bd5d47 JJ |
1969 | && (opts->x_ix86_tune_string[6] == '\0' |
1970 | || (!strcmp (opts->x_ix86_tune_string + 6, "-v2") | |
1971 | || !strcmp (opts->x_ix86_tune_string + 6, "-v3") | |
1972 | || !strcmp (opts->x_ix86_tune_string + 6, "-v4")))) | |
1973 | opts->x_ix86_tune_string = "generic"; | |
2bf6d935 ML |
1974 | } |
1975 | ||
1976 | if (opts->x_ix86_stringop_alg == rep_prefix_8_byte | |
1977 | && !TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
1978 | { | |
1979 | /* rep; movq isn't available in 32-bit code. */ | |
1980 | error ("%<-mstringop-strategy=rep_8byte%> not supported for 32-bit code"); | |
1981 | opts->x_ix86_stringop_alg = no_stringop; | |
1982 | } | |
1983 | ||
299a53d7 | 1984 | if (TARGET_UINTR && !TARGET_64BIT) |
1985 | error ("%<-muintr%> not supported for 32-bit code"); | |
1986 | ||
2bf6d935 ML |
1987 | if (!opts->x_ix86_arch_string) |
1988 | opts->x_ix86_arch_string | |
1989 | = TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
1990 | ? "x86-64" : SUBTARGET32_DEFAULT_CPU; | |
1991 | else | |
1992 | ix86_arch_specified = 1; | |
1993 | ||
1994 | if (opts_set->x_ix86_pmode) | |
1995 | { | |
1996 | if ((TARGET_LP64_P (opts->x_ix86_isa_flags) | |
1997 | && opts->x_ix86_pmode == PMODE_SI) | |
1998 | || (!TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
1999 | && opts->x_ix86_pmode == PMODE_DI)) | |
2000 | error ("address mode %qs not supported in the %s bit mode", | |
2001 | TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long", | |
2002 | TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32"); | |
2003 | } | |
2004 | else | |
2005 | opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags) | |
2006 | ? PMODE_DI : PMODE_SI; | |
2007 | ||
6ed76044 | 2008 | SET_OPTION_IF_UNSET (opts, opts_set, ix86_abi, DEFAULT_ABI); |
2bf6d935 ML |
2009 | |
2010 | if (opts->x_ix86_abi == MS_ABI && TARGET_X32_P (opts->x_ix86_isa_flags)) | |
2011 | error ("%<-mabi=ms%> not supported with X32 ABI"); | |
2012 | gcc_assert (opts->x_ix86_abi == SYSV_ABI || opts->x_ix86_abi == MS_ABI); | |
2013 | ||
080629d3 ML |
2014 | const char *abi_name = opts->x_ix86_abi == MS_ABI ? "ms" : "sysv"; |
2015 | if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) | |
2016 | && opts->x_ix86_abi != DEFAULT_ABI) | |
2017 | error ("%<-mabi=%s%> not supported with %<-fsanitize=address%>", abi_name); | |
2018 | if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) | |
2019 | && opts->x_ix86_abi != DEFAULT_ABI) | |
2020 | error ("%<-mabi=%s%> not supported with %<-fsanitize=kernel-address%>", | |
2021 | abi_name); | |
2022 | if ((opts->x_flag_sanitize & SANITIZE_THREAD) | |
2023 | && opts->x_ix86_abi != DEFAULT_ABI) | |
2024 | error ("%<-mabi=%s%> not supported with %<-fsanitize=thread%>", abi_name); | |
2bf6d935 ML |
2025 | |
2026 | /* For targets using ms ABI enable ms-extensions, if not | |
2027 | explicit turned off. For non-ms ABI we turn off this | |
2028 | option. */ | |
6ed76044 ML |
2029 | SET_OPTION_IF_UNSET (opts, opts_set, flag_ms_extensions, |
2030 | (MS_ABI == DEFAULT_ABI)); | |
2bf6d935 ML |
2031 | |
2032 | if (opts_set->x_ix86_cmodel) | |
2033 | { | |
2034 | switch (opts->x_ix86_cmodel) | |
2035 | { | |
2036 | case CM_SMALL: | |
2037 | case CM_SMALL_PIC: | |
2038 | if (opts->x_flag_pic) | |
2039 | opts->x_ix86_cmodel = CM_SMALL_PIC; | |
2040 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2041 | error ("code model %qs not supported in the %s bit mode", | |
2042 | "small", "32"); | |
2043 | break; | |
2044 | ||
2045 | case CM_MEDIUM: | |
2046 | case CM_MEDIUM_PIC: | |
2047 | if (opts->x_flag_pic) | |
2048 | opts->x_ix86_cmodel = CM_MEDIUM_PIC; | |
2049 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2050 | error ("code model %qs not supported in the %s bit mode", | |
2051 | "medium", "32"); | |
2052 | else if (TARGET_X32_P (opts->x_ix86_isa_flags)) | |
2053 | error ("code model %qs not supported in x32 mode", | |
2054 | "medium"); | |
2055 | break; | |
2056 | ||
2057 | case CM_LARGE: | |
2058 | case CM_LARGE_PIC: | |
2059 | if (opts->x_flag_pic) | |
2060 | opts->x_ix86_cmodel = CM_LARGE_PIC; | |
2061 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2062 | error ("code model %qs not supported in the %s bit mode", | |
2063 | "large", "32"); | |
2064 | else if (TARGET_X32_P (opts->x_ix86_isa_flags)) | |
2065 | error ("code model %qs not supported in x32 mode", | |
2066 | "large"); | |
2067 | break; | |
2068 | ||
2069 | case CM_32: | |
2070 | if (opts->x_flag_pic) | |
2071 | error ("code model %s does not support PIC mode", "32"); | |
2072 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2073 | error ("code model %qs not supported in the %s bit mode", | |
2074 | "32", "64"); | |
2075 | break; | |
2076 | ||
2077 | case CM_KERNEL: | |
2078 | if (opts->x_flag_pic) | |
2079 | { | |
2080 | error ("code model %s does not support PIC mode", "kernel"); | |
2081 | opts->x_ix86_cmodel = CM_32; | |
2082 | } | |
2083 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2084 | error ("code model %qs not supported in the %s bit mode", | |
2085 | "kernel", "32"); | |
2086 | break; | |
2087 | ||
2088 | default: | |
2089 | gcc_unreachable (); | |
2090 | } | |
2091 | } | |
2092 | else | |
2093 | { | |
2094 | /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the | |
2095 | use of rip-relative addressing. This eliminates fixups that | |
2096 | would otherwise be needed if this object is to be placed in a | |
2097 | DLL, and is essentially just as efficient as direct addressing. */ | |
2098 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
2099 | && (TARGET_RDOS || TARGET_PECOFF)) | |
2100 | opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1; | |
2101 | else if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2102 | opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL; | |
2103 | else | |
2104 | opts->x_ix86_cmodel = CM_32; | |
2105 | } | |
2106 | if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL) | |
2107 | { | |
2108 | error ("%<-masm=intel%> not supported in this configuration"); | |
2109 | opts->x_ix86_asm_dialect = ASM_ATT; | |
2110 | } | |
2111 | if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0) | |
2112 | != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0)) | |
2113 | sorry ("%i-bit mode not compiled in", | |
2114 | (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32); | |
2115 | ||
4f00c4d4 ML |
2116 | /* Last processor_alias_table must point to "generic" entry. */ |
2117 | gcc_checking_assert (strcmp (processor_alias_table[pta_size - 1].name, | |
2118 | "generic") == 0); | |
2bf6d935 ML |
2119 | for (i = 0; i < pta_size; i++) |
2120 | if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name)) | |
2121 | { | |
2122 | if (!strcmp (opts->x_ix86_arch_string, "generic")) | |
2123 | { | |
2124 | error (main_args_p | |
2125 | ? G_("%<generic%> CPU can be used only for %<-mtune=%> " | |
2126 | "switch") | |
2127 | : G_("%<generic%> CPU can be used only for " | |
2128 | "%<target(\"tune=\")%> attribute")); | |
2129 | return false; | |
2130 | } | |
2131 | else if (!strcmp (opts->x_ix86_arch_string, "intel")) | |
2132 | { | |
2133 | error (main_args_p | |
2134 | ? G_("%<intel%> CPU can be used only for %<-mtune=%> " | |
2135 | "switch") | |
2136 | : G_("%<intel%> CPU can be used only for " | |
2137 | "%<target(\"tune=\")%> attribute")); | |
2138 | return false; | |
2139 | } | |
2140 | ||
2141 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
2142 | && !((processor_alias_table[i].flags & PTA_64BIT) != 0)) | |
2143 | { | |
2144 | error ("CPU you selected does not support x86-64 " | |
2145 | "instruction set"); | |
2146 | return false; | |
2147 | } | |
2148 | ||
2149 | ix86_schedule = processor_alias_table[i].schedule; | |
2150 | ix86_arch = processor_alias_table[i].processor; | |
324bec55 FW |
2151 | |
2152 | /* Default cpu tuning to the architecture, unless the table | |
2153 | entry requests not to do this. Used by the x86-64 psABI | |
2154 | micro-architecture levels. */ | |
2155 | if ((processor_alias_table[i].flags & PTA_NO_TUNE) == 0) | |
2156 | ix86_tune = ix86_arch; | |
2157 | else | |
2158 | ix86_tune = PROCESSOR_GENERIC; | |
2bf6d935 | 2159 | |
1751bec0 ML |
2160 | /* Enable PTA flags that are enabled by default by a -march option. */ |
2161 | #define TARGET_EXPLICIT_NO_SAHF_P(opts) (false) | |
2162 | #define SET_TARGET_NO_SAHF(opts) {} | |
2163 | #define TARGET_EXPLICIT_PREFETCH_SSE_P(opts) (false) | |
2164 | #define SET_TARGET_PREFETCH_SSE(opts) {} | |
2165 | #define TARGET_EXPLICIT_NO_TUNE_P(opts) (false) | |
2166 | #define SET_TARGET_NO_TUNE(opts) {} | |
2167 | #define TARGET_EXPLICIT_NO_80387_P(opts) (false) | |
2168 | #define SET_TARGET_NO_80387(opts) {} | |
2169 | ||
2170 | #define DEF_PTA(NAME) \ | |
2171 | if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \ | |
2172 | && PTA_ ## NAME != PTA_64BIT \ | |
cc11b924 | 2173 | && (TARGET_64BIT || PTA_ ## NAME != PTA_UINTR) \ |
1751bec0 ML |
2174 | && !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \ |
2175 | SET_TARGET_ ## NAME (opts); | |
2176 | #include "i386-isa.def" | |
2177 | #undef DEF_PTA | |
2178 | ||
2179 | ||
2180 | if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
2181 | && ((processor_alias_table[i].flags & PTA_NO_SAHF) != 0)) | |
2182 | && !TARGET_EXPLICIT_SAHF_P (opts)) | |
2183 | SET_TARGET_SAHF (opts); | |
2184 | ||
2bf6d935 | 2185 | if (((processor_alias_table[i].flags & PTA_ABM) != 0) |
1751bec0 ML |
2186 | && !TARGET_EXPLICIT_ABM_P (opts)) |
2187 | { | |
854ef6e5 L |
2188 | if (!TARGET_EXPLICIT_LZCNT_P (opts)) |
2189 | SET_TARGET_LZCNT (opts); | |
2190 | if (!TARGET_EXPLICIT_POPCNT_P (opts)) | |
2191 | SET_TARGET_POPCNT (opts); | |
1751bec0 | 2192 | } |
2bf6d935 ML |
2193 | |
2194 | if ((processor_alias_table[i].flags | |
2195 | & (PTA_PREFETCH_SSE | PTA_SSE)) != 0) | |
08a4adcf | 2196 | ix86_prefetch_sse = true; |
2bf6d935 | 2197 | |
87c753ac L |
2198 | /* Don't enable x87 instructions if only general registers are |
2199 | allowed by target("general-regs-only") function attribute or | |
2200 | -mgeneral-regs-only. */ | |
2201 | if (!(opts->x_ix86_target_flags & OPTION_MASK_GENERAL_REGS_ONLY) | |
2bf6d935 ML |
2202 | && !(opts_set->x_target_flags & MASK_80387)) |
2203 | { | |
2204 | if (((processor_alias_table[i].flags & PTA_NO_80387) != 0)) | |
2205 | opts->x_target_flags &= ~MASK_80387; | |
2206 | else | |
2207 | opts->x_target_flags |= MASK_80387; | |
2208 | } | |
2209 | break; | |
2210 | } | |
2211 | ||
2212 | if (i == pta_size) | |
2213 | { | |
2214 | error (main_args_p | |
2215 | ? G_("bad value (%qs) for %<-march=%> switch") | |
2216 | : G_("bad value (%qs) for %<target(\"arch=\")%> attribute"), | |
2217 | opts->x_ix86_arch_string); | |
2218 | ||
2219 | auto_vec <const char *> candidates; | |
2220 | for (i = 0; i < pta_size; i++) | |
2221 | if (strcmp (processor_alias_table[i].name, "generic") | |
2222 | && strcmp (processor_alias_table[i].name, "intel") | |
2223 | && (!TARGET_64BIT_P (opts->x_ix86_isa_flags) | |
2224 | || ((processor_alias_table[i].flags & PTA_64BIT) != 0))) | |
2225 | candidates.safe_push (processor_alias_table[i].name); | |
2226 | ||
2227 | #ifdef HAVE_LOCAL_CPU_DETECT | |
2228 | /* Add also "native" as possible value. */ | |
2229 | candidates.safe_push ("native"); | |
2230 | #endif | |
2231 | ||
2232 | char *s; | |
2233 | const char *hint | |
2234 | = candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates); | |
2235 | if (hint) | |
2236 | inform (input_location, | |
2237 | main_args_p | |
2238 | ? G_("valid arguments to %<-march=%> switch are: " | |
2239 | "%s; did you mean %qs?") | |
2240 | : G_("valid arguments to %<target(\"arch=\")%> attribute are: " | |
2241 | "%s; did you mean %qs?"), s, hint); | |
2242 | else | |
2243 | inform (input_location, | |
2244 | main_args_p | |
2245 | ? G_("valid arguments to %<-march=%> switch are: %s") | |
2246 | : G_("valid arguments to %<target(\"arch=\")%> attribute " | |
2247 | "are: %s"), s); | |
2248 | XDELETEVEC (s); | |
2249 | } | |
2250 | ||
2251 | ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch; | |
2252 | for (i = 0; i < X86_ARCH_LAST; ++i) | |
2253 | ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask); | |
2254 | ||
2255 | for (i = 0; i < pta_size; i++) | |
324bec55 FW |
2256 | if (! strcmp (opts->x_ix86_tune_string, processor_alias_table[i].name) |
2257 | && (processor_alias_table[i].flags & PTA_NO_TUNE) == 0) | |
2bf6d935 ML |
2258 | { |
2259 | ix86_schedule = processor_alias_table[i].schedule; | |
2260 | ix86_tune = processor_alias_table[i].processor; | |
2261 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2262 | { | |
2263 | if (!((processor_alias_table[i].flags & PTA_64BIT) != 0)) | |
2264 | { | |
2265 | if (ix86_tune_defaulted) | |
2266 | { | |
2267 | opts->x_ix86_tune_string = "x86-64"; | |
2268 | for (i = 0; i < pta_size; i++) | |
2269 | if (! strcmp (opts->x_ix86_tune_string, | |
2270 | processor_alias_table[i].name)) | |
2271 | break; | |
2272 | ix86_schedule = processor_alias_table[i].schedule; | |
2273 | ix86_tune = processor_alias_table[i].processor; | |
2274 | } | |
2275 | else | |
2276 | error ("CPU you selected does not support x86-64 " | |
2277 | "instruction set"); | |
2278 | } | |
2279 | } | |
2280 | /* Intel CPUs have always interpreted SSE prefetch instructions as | |
2281 | NOPs; so, we can enable SSE prefetch instructions even when | |
2282 | -mtune (rather than -march) points us to a processor that has them. | |
2283 | However, the VIA C3 gives a SIGILL, so we only do that for i686 and | |
2284 | higher processors. */ | |
2285 | if (TARGET_CMOV | |
2286 | && ((processor_alias_table[i].flags | |
2287 | & (PTA_PREFETCH_SSE | PTA_SSE)) != 0)) | |
08a4adcf | 2288 | ix86_prefetch_sse = true; |
2bf6d935 ML |
2289 | break; |
2290 | } | |
2291 | ||
2292 | if (ix86_tune_specified && i == pta_size) | |
2293 | { | |
2294 | error (main_args_p | |
2295 | ? G_("bad value (%qs) for %<-mtune=%> switch") | |
2296 | : G_("bad value (%qs) for %<target(\"tune=\")%> attribute"), | |
2297 | opts->x_ix86_tune_string); | |
2298 | ||
2299 | auto_vec <const char *> candidates; | |
2300 | for (i = 0; i < pta_size; i++) | |
324bec55 FW |
2301 | if ((!TARGET_64BIT_P (opts->x_ix86_isa_flags) |
2302 | || ((processor_alias_table[i].flags & PTA_64BIT) != 0)) | |
2303 | && (processor_alias_table[i].flags & PTA_NO_TUNE) == 0) | |
2bf6d935 ML |
2304 | candidates.safe_push (processor_alias_table[i].name); |
2305 | ||
2306 | #ifdef HAVE_LOCAL_CPU_DETECT | |
2307 | /* Add also "native" as possible value. */ | |
2308 | candidates.safe_push ("native"); | |
2309 | #endif | |
2310 | ||
2311 | char *s; | |
2312 | const char *hint | |
2313 | = candidates_list_and_hint (opts->x_ix86_tune_string, s, candidates); | |
2314 | if (hint) | |
2315 | inform (input_location, | |
2316 | main_args_p | |
2317 | ? G_("valid arguments to %<-mtune=%> switch are: " | |
2318 | "%s; did you mean %qs?") | |
2319 | : G_("valid arguments to %<target(\"tune=\")%> attribute are: " | |
2320 | "%s; did you mean %qs?"), s, hint); | |
2321 | else | |
2322 | inform (input_location, | |
2323 | main_args_p | |
2324 | ? G_("valid arguments to %<-mtune=%> switch are: %s") | |
2325 | : G_("valid arguments to %<target(\"tune=\")%> attribute " | |
2326 | "are: %s"), s); | |
2327 | XDELETEVEC (s); | |
2328 | } | |
2329 | ||
1e964774 | 2330 | set_ix86_tune_features (opts, ix86_tune, opts->x_ix86_dump_tunes); |
2bf6d935 | 2331 | |
6bc89193 | 2332 | ix86_recompute_optlev_based_flags (opts, opts_set); |
2bf6d935 ML |
2333 | |
2334 | ix86_tune_cost = processor_cost_table[ix86_tune]; | |
2335 | /* TODO: ix86_cost should be chosen at instruction or function granuality | |
2336 | so for cold code we use size_cost even in !optimize_size compilation. */ | |
2337 | if (opts->x_optimize_size) | |
2338 | ix86_cost = &ix86_size_cost; | |
2339 | else | |
2340 | ix86_cost = ix86_tune_cost; | |
2341 | ||
2342 | /* Arrange to set up i386_stack_locals for all functions. */ | |
2343 | init_machine_status = ix86_init_machine_status; | |
2344 | ||
2345 | /* Validate -mregparm= value. */ | |
2346 | if (opts_set->x_ix86_regparm) | |
2347 | { | |
2348 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2349 | warning (0, "%<-mregparm%> is ignored in 64-bit mode"); | |
2350 | else if (TARGET_IAMCU_P (opts->x_target_flags)) | |
2351 | warning (0, "%<-mregparm%> is ignored for Intel MCU psABI"); | |
2352 | if (opts->x_ix86_regparm > REGPARM_MAX) | |
2353 | { | |
2354 | error ("%<-mregparm=%d%> is not between 0 and %d", | |
2355 | opts->x_ix86_regparm, REGPARM_MAX); | |
2356 | opts->x_ix86_regparm = 0; | |
2357 | } | |
2358 | } | |
2359 | if (TARGET_IAMCU_P (opts->x_target_flags) | |
2360 | || TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2361 | opts->x_ix86_regparm = REGPARM_MAX; | |
2362 | ||
2363 | /* Default align_* from the processor table. */ | |
2364 | ix86_default_align (opts); | |
2365 | ||
2366 | /* Provide default for -mbranch-cost= value. */ | |
6ed76044 ML |
2367 | SET_OPTION_IF_UNSET (opts, opts_set, ix86_branch_cost, |
2368 | ix86_tune_cost->branch_cost); | |
2bf6d935 ML |
2369 | |
2370 | if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2371 | { | |
2372 | opts->x_target_flags | |
2373 | |= TARGET_SUBTARGET64_DEFAULT & ~opts_set->x_target_flags; | |
2374 | ||
2375 | if (!ix86_arch_specified) | |
2376 | opts->x_ix86_isa_flags | |
2377 | |= TARGET_SUBTARGET64_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit; | |
2378 | ||
716bb02b UB |
2379 | if (!TARGET_128BIT_LONG_DOUBLE_P (opts->x_target_flags)) |
2380 | error ("%<-m96bit-long-double%> is not compatible with this target"); | |
2381 | ||
2bf6d935 ML |
2382 | if (TARGET_RTD_P (opts->x_target_flags)) |
2383 | warning (0, | |
2384 | main_args_p | |
2385 | ? G_("%<-mrtd%> is ignored in 64bit mode") | |
2386 | : G_("%<target(\"rtd\")%> is ignored in 64bit mode")); | |
2387 | } | |
2388 | else | |
2389 | { | |
2390 | opts->x_target_flags | |
2391 | |= TARGET_SUBTARGET32_DEFAULT & ~opts_set->x_target_flags; | |
2392 | ||
2393 | if (!ix86_arch_specified) | |
2394 | opts->x_ix86_isa_flags | |
2395 | |= TARGET_SUBTARGET32_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit; | |
2396 | ||
2397 | /* i386 ABI does not specify red zone. It still makes sense to use it | |
2398 | when programmer takes care to stack from being destroyed. */ | |
2399 | if (!(opts_set->x_target_flags & MASK_NO_RED_ZONE)) | |
2400 | opts->x_target_flags |= MASK_NO_RED_ZONE; | |
2401 | } | |
2402 | ||
2403 | /* Keep nonleaf frame pointers. */ | |
2404 | if (opts->x_flag_omit_frame_pointer) | |
2405 | opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER; | |
2406 | else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags)) | |
2407 | opts->x_flag_omit_frame_pointer = 1; | |
2408 | ||
2409 | /* If we're doing fast math, we don't care about comparison order | |
2410 | wrt NaNs. This lets us use a shorter comparison sequence. */ | |
2411 | if (opts->x_flag_finite_math_only) | |
2412 | opts->x_target_flags &= ~MASK_IEEE_FP; | |
2413 | ||
2414 | /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387, | |
2415 | since the insns won't need emulation. */ | |
2416 | if (ix86_tune_features [X86_TUNE_ALWAYS_FANCY_MATH_387]) | |
2417 | opts->x_target_flags &= ~MASK_NO_FANCY_MATH_387; | |
2418 | ||
2419 | /* Likewise, if the target doesn't have a 387, or we've specified | |
2420 | software floating point, don't use 387 inline intrinsics. */ | |
2421 | if (!TARGET_80387_P (opts->x_target_flags)) | |
2422 | opts->x_target_flags |= MASK_NO_FANCY_MATH_387; | |
2423 | ||
2424 | /* Turn on MMX builtins for -msse. */ | |
2425 | if (TARGET_SSE_P (opts->x_ix86_isa_flags)) | |
2426 | opts->x_ix86_isa_flags | |
2427 | |= OPTION_MASK_ISA_MMX & ~opts->x_ix86_isa_flags_explicit; | |
2428 | ||
2429 | /* Enable SSE prefetch. */ | |
2430 | if (TARGET_SSE_P (opts->x_ix86_isa_flags) | |
2431 | || (TARGET_PRFCHW_P (opts->x_ix86_isa_flags) | |
2432 | && !TARGET_3DNOW_P (opts->x_ix86_isa_flags)) | |
2433 | || TARGET_PREFETCHWT1_P (opts->x_ix86_isa_flags)) | |
08a4adcf | 2434 | ix86_prefetch_sse = true; |
2bf6d935 | 2435 | |
d8c6cc2c L |
2436 | /* Enable mwait/monitor instructions for -msse3. */ |
2437 | if (TARGET_SSE3_P (opts->x_ix86_isa_flags)) | |
2438 | opts->x_ix86_isa_flags2 | |
2439 | |= OPTION_MASK_ISA2_MWAIT & ~opts->x_ix86_isa_flags2_explicit; | |
2440 | ||
2bf6d935 ML |
2441 | /* Enable popcnt instruction for -msse4.2 or -mabm. */ |
2442 | if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags) | |
2443 | || TARGET_ABM_P (opts->x_ix86_isa_flags)) | |
2444 | opts->x_ix86_isa_flags | |
2445 | |= OPTION_MASK_ISA_POPCNT & ~opts->x_ix86_isa_flags_explicit; | |
2446 | ||
39671f87 L |
2447 | /* Enable crc32 instruction for -msse4.2. */ |
2448 | if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags)) | |
2449 | opts->x_ix86_isa_flags | |
2450 | |= OPTION_MASK_ISA_CRC32 & ~opts->x_ix86_isa_flags_explicit; | |
2451 | ||
2bf6d935 ML |
2452 | /* Enable lzcnt instruction for -mabm. */ |
2453 | if (TARGET_ABM_P(opts->x_ix86_isa_flags)) | |
2454 | opts->x_ix86_isa_flags | |
2455 | |= OPTION_MASK_ISA_LZCNT & ~opts->x_ix86_isa_flags_explicit; | |
2456 | ||
2457 | /* Disable BMI, BMI2 and TBM instructions for -m16. */ | |
2458 | if (TARGET_16BIT_P(opts->x_ix86_isa_flags)) | |
2459 | opts->x_ix86_isa_flags | |
2460 | &= ~((OPTION_MASK_ISA_BMI | OPTION_MASK_ISA_BMI2 | OPTION_MASK_ISA_TBM) | |
2461 | & ~opts->x_ix86_isa_flags_explicit); | |
2462 | ||
2463 | /* Validate -mpreferred-stack-boundary= value or default it to | |
2464 | PREFERRED_STACK_BOUNDARY_DEFAULT. */ | |
2465 | ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT; | |
2466 | if (opts_set->x_ix86_preferred_stack_boundary_arg) | |
2467 | { | |
2468 | int min = TARGET_64BIT_P (opts->x_ix86_isa_flags)? 3 : 2; | |
2469 | int max = TARGET_SEH ? 4 : 12; | |
2470 | ||
2471 | if (opts->x_ix86_preferred_stack_boundary_arg < min | |
2472 | || opts->x_ix86_preferred_stack_boundary_arg > max) | |
2473 | { | |
2474 | if (min == max) | |
2475 | error ("%<-mpreferred-stack-boundary%> is not supported " | |
2476 | "for this target"); | |
2477 | else | |
2478 | error ("%<-mpreferred-stack-boundary=%d%> is not between %d and %d", | |
2479 | opts->x_ix86_preferred_stack_boundary_arg, min, max); | |
2480 | } | |
2481 | else | |
2482 | ix86_preferred_stack_boundary | |
2483 | = (1 << opts->x_ix86_preferred_stack_boundary_arg) * BITS_PER_UNIT; | |
2484 | } | |
2485 | ||
2486 | /* Set the default value for -mstackrealign. */ | |
6ed76044 ML |
2487 | SET_OPTION_IF_UNSET (opts, opts_set, ix86_force_align_arg_pointer, |
2488 | STACK_REALIGN_DEFAULT); | |
2bf6d935 ML |
2489 | |
2490 | ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY; | |
2491 | ||
2492 | /* Validate -mincoming-stack-boundary= value or default it to | |
2493 | MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY. */ | |
2494 | ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary; | |
2495 | if (opts_set->x_ix86_incoming_stack_boundary_arg) | |
2496 | { | |
2497 | int min = TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 3 : 2; | |
2498 | ||
2499 | if (opts->x_ix86_incoming_stack_boundary_arg < min | |
2500 | || opts->x_ix86_incoming_stack_boundary_arg > 12) | |
2501 | error ("%<-mincoming-stack-boundary=%d%> is not between %d and 12", | |
2502 | opts->x_ix86_incoming_stack_boundary_arg, min); | |
2503 | else | |
2504 | { | |
2505 | ix86_user_incoming_stack_boundary | |
2506 | = (1 << opts->x_ix86_incoming_stack_boundary_arg) * BITS_PER_UNIT; | |
2507 | ix86_incoming_stack_boundary | |
2508 | = ix86_user_incoming_stack_boundary; | |
2509 | } | |
2510 | } | |
2511 | ||
2512 | #ifndef NO_PROFILE_COUNTERS | |
2513 | if (flag_nop_mcount) | |
2514 | error ("%<-mnop-mcount%> is not compatible with this target"); | |
2515 | #endif | |
2516 | if (flag_nop_mcount && flag_pic) | |
2517 | error ("%<-mnop-mcount%> is not implemented for %<-fPIC%>"); | |
2518 | ||
2519 | /* Accept -msseregparm only if at least SSE support is enabled. */ | |
2520 | if (TARGET_SSEREGPARM_P (opts->x_target_flags) | |
2521 | && ! TARGET_SSE_P (opts->x_ix86_isa_flags)) | |
2522 | error (main_args_p | |
2523 | ? G_("%<-msseregparm%> used without SSE enabled") | |
2524 | : G_("%<target(\"sseregparm\")%> used without SSE enabled")); | |
2525 | ||
2526 | if (opts_set->x_ix86_fpmath) | |
2527 | { | |
2528 | if (opts->x_ix86_fpmath & FPMATH_SSE) | |
2529 | { | |
2530 | if (!TARGET_SSE_P (opts->x_ix86_isa_flags)) | |
2531 | { | |
2532 | if (TARGET_80387_P (opts->x_target_flags)) | |
2533 | { | |
2534 | warning (0, "SSE instruction set disabled, using 387 arithmetics"); | |
2535 | opts->x_ix86_fpmath = FPMATH_387; | |
2536 | } | |
2537 | } | |
2538 | else if ((opts->x_ix86_fpmath & FPMATH_387) | |
2539 | && !TARGET_80387_P (opts->x_target_flags)) | |
2540 | { | |
2541 | warning (0, "387 instruction set disabled, using SSE arithmetics"); | |
2542 | opts->x_ix86_fpmath = FPMATH_SSE; | |
2543 | } | |
2544 | } | |
2545 | } | |
2546 | /* For all chips supporting SSE2, -mfpmath=sse performs better than | |
2547 | fpmath=387. The second is however default at many targets since the | |
2548 | extra 80bit precision of temporaries is considered to be part of ABI. | |
2549 | Overwrite the default at least for -ffast-math. | |
2550 | TODO: -mfpmath=both seems to produce same performing code with bit | |
2551 | smaller binaries. It is however not clear if register allocation is | |
2552 | ready for this setting. | |
2553 | Also -mfpmath=387 is overall a lot more compact (bout 4-5%) than SSE | |
2554 | codegen. We may switch to 387 with -ffast-math for size optimized | |
2555 | functions. */ | |
2556 | else if (fast_math_flags_set_p (&global_options) | |
2557 | && TARGET_SSE2_P (opts->x_ix86_isa_flags)) | |
2558 | opts->x_ix86_fpmath = FPMATH_SSE; | |
2559 | else | |
2560 | opts->x_ix86_fpmath = TARGET_FPMATH_DEFAULT_P (opts->x_ix86_isa_flags); | |
2561 | ||
2562 | /* Use external vectorized library in vectorizing intrinsics. */ | |
2563 | if (opts_set->x_ix86_veclibabi_type) | |
2564 | switch (opts->x_ix86_veclibabi_type) | |
2565 | { | |
2566 | case ix86_veclibabi_type_svml: | |
2567 | ix86_veclib_handler = &ix86_veclibabi_svml; | |
2568 | break; | |
2569 | ||
2570 | case ix86_veclibabi_type_acml: | |
2571 | ix86_veclib_handler = &ix86_veclibabi_acml; | |
2572 | break; | |
2573 | ||
2574 | default: | |
2575 | gcc_unreachable (); | |
2576 | } | |
2577 | ||
2578 | if (ix86_tune_features [X86_TUNE_ACCUMULATE_OUTGOING_ARGS] | |
2579 | && !(opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)) | |
2580 | opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS; | |
2581 | ||
2582 | /* If stack probes are required, the space used for large function | |
2583 | arguments on the stack must also be probed, so enable | |
2584 | -maccumulate-outgoing-args so this happens in the prologue. */ | |
2585 | if (TARGET_STACK_PROBE_P (opts->x_target_flags) | |
2586 | && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)) | |
2587 | { | |
2588 | if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS) | |
2589 | warning (0, | |
2590 | main_args_p | |
2591 | ? G_("stack probing requires %<-maccumulate-outgoing-args%> " | |
2592 | "for correctness") | |
2593 | : G_("stack probing requires " | |
2594 | "%<target(\"accumulate-outgoing-args\")%> for " | |
2595 | "correctness")); | |
2596 | opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS; | |
2597 | } | |
2598 | ||
2599 | /* Stack realignment without -maccumulate-outgoing-args requires %ebp, | |
2600 | so enable -maccumulate-outgoing-args when %ebp is fixed. */ | |
2601 | if (fixed_regs[BP_REG] | |
2602 | && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)) | |
2603 | { | |
2604 | if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS) | |
2605 | warning (0, | |
2606 | main_args_p | |
2607 | ? G_("fixed ebp register requires " | |
2608 | "%<-maccumulate-outgoing-args%>") | |
2609 | : G_("fixed ebp register requires " | |
2610 | "%<target(\"accumulate-outgoing-args\")%>")); | |
2611 | opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS; | |
2612 | } | |
2613 | ||
2614 | /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix. */ | |
2615 | { | |
2616 | char *p; | |
2617 | ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0); | |
2618 | p = strchr (internal_label_prefix, 'X'); | |
2619 | internal_label_prefix_len = p - internal_label_prefix; | |
2620 | *p = '\0'; | |
2621 | } | |
2622 | ||
2623 | /* When scheduling description is not available, disable scheduler pass | |
2624 | so it won't slow down the compilation and make x87 code slower. */ | |
2625 | if (!TARGET_SCHEDULE) | |
2626 | opts->x_flag_schedule_insns_after_reload = opts->x_flag_schedule_insns = 0; | |
2627 | ||
028d4092 ML |
2628 | SET_OPTION_IF_UNSET (opts, opts_set, param_simultaneous_prefetches, |
2629 | ix86_tune_cost->simultaneous_prefetches); | |
2630 | SET_OPTION_IF_UNSET (opts, opts_set, param_l1_cache_line_size, | |
2631 | ix86_tune_cost->prefetch_block); | |
2632 | SET_OPTION_IF_UNSET (opts, opts_set, param_l1_cache_size, | |
2633 | ix86_tune_cost->l1_cache_size); | |
2634 | SET_OPTION_IF_UNSET (opts, opts_set, param_l2_cache_size, | |
2635 | ix86_tune_cost->l2_cache_size); | |
2bf6d935 | 2636 | |
76b75018 JM |
2637 | /* 64B is the accepted value for these for all x86. */ |
2638 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, | |
2639 | param_destruct_interfere_size, 64); | |
2640 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, | |
2641 | param_construct_interfere_size, 64); | |
2642 | ||
2bf6d935 ML |
2643 | /* Enable sw prefetching at -O3 for CPUS that prefetching is helpful. */ |
2644 | if (opts->x_flag_prefetch_loop_arrays < 0 | |
2645 | && HAVE_prefetch | |
2646 | && (opts->x_optimize >= 3 || opts->x_flag_profile_use) | |
2647 | && !opts->x_optimize_size | |
2648 | && TARGET_SOFTWARE_PREFETCHING_BENEFICIAL) | |
2649 | opts->x_flag_prefetch_loop_arrays = 1; | |
2650 | ||
2651 | /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0) | |
2652 | can be opts->x_optimized to ap = __builtin_next_arg (0). */ | |
2653 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && !opts->x_flag_split_stack) | |
2654 | targetm.expand_builtin_va_start = NULL; | |
2655 | ||
2bf6d935 ML |
2656 | #ifdef USE_IX86_CLD |
2657 | /* Use -mcld by default for 32-bit code if configured with --enable-cld. */ | |
2658 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)) | |
2659 | opts->x_target_flags |= MASK_CLD & ~opts_set->x_target_flags; | |
2660 | #endif | |
2661 | ||
2662 | /* Set the default value for -mfentry. */ | |
2663 | if (!opts_set->x_flag_fentry) | |
2664 | opts->x_flag_fentry = TARGET_SEH; | |
2665 | else | |
2666 | { | |
2667 | if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic | |
2668 | && opts->x_flag_fentry) | |
2669 | sorry ("%<-mfentry%> isn%'t supported for 32-bit in combination " | |
2670 | "with %<-fpic%>"); | |
2671 | else if (TARGET_SEH && !opts->x_flag_fentry) | |
2672 | sorry ("%<-mno-fentry%> isn%'t compatible with SEH"); | |
2673 | } | |
2674 | ||
2675 | if (TARGET_SEH && TARGET_CALL_MS2SYSV_XLOGUES) | |
2676 | sorry ("%<-mcall-ms2sysv-xlogues%> isn%'t currently supported with SEH"); | |
2677 | ||
2678 | if (!(opts_set->x_target_flags & MASK_VZEROUPPER) | |
2679 | && TARGET_EMIT_VZEROUPPER) | |
2680 | opts->x_target_flags |= MASK_VZEROUPPER; | |
2681 | if (!(opts_set->x_target_flags & MASK_STV)) | |
2682 | opts->x_target_flags |= MASK_STV; | |
2683 | /* Disable STV if -mpreferred-stack-boundary={2,3} or | |
2684 | -mincoming-stack-boundary={2,3} or -mstackrealign - the needed | |
2685 | stack realignment will be extra cost the pass doesn't take into | |
2686 | account and the pass can't realign the stack. */ | |
2687 | if (ix86_preferred_stack_boundary < 128 | |
2688 | || ix86_incoming_stack_boundary < 128 | |
2689 | || opts->x_ix86_force_align_arg_pointer) | |
2690 | opts->x_target_flags &= ~MASK_STV; | |
2691 | if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL] | |
2692 | && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_LOAD)) | |
2693 | opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_LOAD; | |
342de04d | 2694 | else if (!main_args_p |
2695 | && ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL]) | |
2696 | opts->x_target_flags &= ~MASK_AVX256_SPLIT_UNALIGNED_LOAD; | |
2697 | ||
2bf6d935 ML |
2698 | if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL] |
2699 | && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_STORE)) | |
2700 | opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_STORE; | |
342de04d | 2701 | else if (!main_args_p |
2702 | && ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL]) | |
2703 | opts->x_target_flags &= ~MASK_AVX256_SPLIT_UNALIGNED_STORE; | |
2bf6d935 ML |
2704 | |
2705 | /* Enable 128-bit AVX instruction generation | |
2706 | for the auto-vectorizer. */ | |
586bbef1 | 2707 | if (ix86_tune_features[X86_TUNE_AVX128_OPTIMAL] |
2bf6d935 ML |
2708 | && (opts_set->x_prefer_vector_width_type == PVW_NONE)) |
2709 | opts->x_prefer_vector_width_type = PVW_AVX128; | |
2710 | ||
2711 | /* Use 256-bit AVX instruction generation | |
2712 | in the auto-vectorizer. */ | |
2713 | if (ix86_tune_features[X86_TUNE_AVX256_OPTIMAL] | |
2714 | && (opts_set->x_prefer_vector_width_type == PVW_NONE)) | |
2715 | opts->x_prefer_vector_width_type = PVW_AVX256; | |
2716 | ||
654cd743 L |
2717 | if (opts_set->x_ix86_move_max == PVW_NONE) |
2718 | { | |
2719 | /* Set the maximum number of bits can be moved from memory to | |
2720 | memory efficiently. */ | |
2721 | if (ix86_tune_features[X86_TUNE_AVX512_MOVE_BY_PIECES]) | |
2722 | opts->x_ix86_move_max = PVW_AVX512; | |
2723 | else if (ix86_tune_features[X86_TUNE_AVX256_MOVE_BY_PIECES]) | |
2724 | opts->x_ix86_move_max = PVW_AVX256; | |
2725 | else | |
2726 | { | |
2727 | opts->x_ix86_move_max = opts->x_prefer_vector_width_type; | |
2728 | if (opts_set->x_ix86_move_max == PVW_NONE) | |
2729 | { | |
2730 | if (TARGET_AVX512F_P (opts->x_ix86_isa_flags)) | |
2731 | opts->x_ix86_move_max = PVW_AVX512; | |
2732 | else | |
2733 | opts->x_ix86_move_max = PVW_AVX128; | |
2734 | } | |
2735 | } | |
2736 | } | |
2737 | ||
2738 | if (opts_set->x_ix86_store_max == PVW_NONE) | |
2739 | { | |
2740 | /* Set the maximum number of bits can be stored to memory | |
2741 | efficiently. */ | |
2742 | if (ix86_tune_features[X86_TUNE_AVX512_STORE_BY_PIECES]) | |
2743 | opts->x_ix86_store_max = PVW_AVX512; | |
2744 | else if (ix86_tune_features[X86_TUNE_AVX256_STORE_BY_PIECES]) | |
2745 | opts->x_ix86_store_max = PVW_AVX256; | |
2746 | else | |
2747 | { | |
2748 | opts->x_ix86_store_max = opts->x_prefer_vector_width_type; | |
2749 | if (opts_set->x_ix86_store_max == PVW_NONE) | |
2750 | { | |
2751 | if (TARGET_AVX512F_P (opts->x_ix86_isa_flags)) | |
2752 | opts->x_ix86_store_max = PVW_AVX512; | |
2753 | else | |
2754 | opts->x_ix86_store_max = PVW_AVX128; | |
2755 | } | |
2756 | } | |
2757 | } | |
2758 | ||
2bf6d935 ML |
2759 | if (opts->x_ix86_recip_name) |
2760 | { | |
2761 | char *p = ASTRDUP (opts->x_ix86_recip_name); | |
2762 | char *q; | |
5ebdd535 | 2763 | unsigned int mask; |
2bf6d935 ML |
2764 | bool invert; |
2765 | ||
2766 | while ((q = strtok (p, ",")) != NULL) | |
2767 | { | |
2768 | p = NULL; | |
2769 | if (*q == '!') | |
2770 | { | |
2771 | invert = true; | |
2772 | q++; | |
2773 | } | |
2774 | else | |
2775 | invert = false; | |
2776 | ||
2777 | if (!strcmp (q, "default")) | |
2778 | mask = RECIP_MASK_ALL; | |
2779 | else | |
2780 | { | |
2781 | for (i = 0; i < ARRAY_SIZE (recip_options); i++) | |
2782 | if (!strcmp (q, recip_options[i].string)) | |
2783 | { | |
2784 | mask = recip_options[i].mask; | |
2785 | break; | |
2786 | } | |
2787 | ||
2788 | if (i == ARRAY_SIZE (recip_options)) | |
2789 | { | |
2790 | error ("unknown option for %<-mrecip=%s%>", q); | |
2791 | invert = false; | |
2792 | mask = RECIP_MASK_NONE; | |
2793 | } | |
2794 | } | |
2795 | ||
2796 | opts->x_recip_mask_explicit |= mask; | |
2797 | if (invert) | |
2798 | opts->x_recip_mask &= ~mask; | |
2799 | else | |
2800 | opts->x_recip_mask |= mask; | |
2801 | } | |
2802 | } | |
2803 | ||
2804 | if (TARGET_RECIP_P (opts->x_target_flags)) | |
2805 | opts->x_recip_mask |= RECIP_MASK_ALL & ~opts->x_recip_mask_explicit; | |
2806 | else if (opts_set->x_target_flags & MASK_RECIP) | |
2807 | opts->x_recip_mask &= ~(RECIP_MASK_ALL & ~opts->x_recip_mask_explicit); | |
2808 | ||
2809 | /* Default long double to 64-bit for 32-bit Bionic and to __float128 | |
2810 | for 64-bit Bionic. Also default long double to 64-bit for Intel | |
2811 | MCU psABI. */ | |
2812 | if ((TARGET_HAS_BIONIC || TARGET_IAMCU) | |
2813 | && !(opts_set->x_target_flags | |
2814 | & (MASK_LONG_DOUBLE_64 | MASK_LONG_DOUBLE_128))) | |
2815 | opts->x_target_flags |= (TARGET_64BIT | |
2816 | ? MASK_LONG_DOUBLE_128 | |
2817 | : MASK_LONG_DOUBLE_64); | |
2818 | ||
2819 | /* Only one of them can be active. */ | |
2820 | gcc_assert ((opts->x_target_flags & MASK_LONG_DOUBLE_64) == 0 | |
2821 | || (opts->x_target_flags & MASK_LONG_DOUBLE_128) == 0); | |
2822 | ||
2823 | /* Handle stack protector */ | |
2824 | if (!opts_set->x_ix86_stack_protector_guard) | |
2825 | { | |
2826 | #ifdef TARGET_THREAD_SSP_OFFSET | |
2827 | if (!TARGET_HAS_BIONIC) | |
2828 | opts->x_ix86_stack_protector_guard = SSP_TLS; | |
2829 | else | |
2830 | #endif | |
2831 | opts->x_ix86_stack_protector_guard = SSP_GLOBAL; | |
2832 | } | |
2833 | ||
2834 | if (opts_set->x_ix86_stack_protector_guard_offset_str) | |
2835 | { | |
2836 | char *endp; | |
2837 | const char *str = opts->x_ix86_stack_protector_guard_offset_str; | |
2838 | ||
2839 | errno = 0; | |
2840 | int64_t offset; | |
2841 | ||
2842 | #if defined(INT64_T_IS_LONG) | |
2843 | offset = strtol (str, &endp, 0); | |
2844 | #else | |
2845 | offset = strtoll (str, &endp, 0); | |
2846 | #endif | |
2847 | ||
2848 | if (!*str || *endp || errno) | |
2849 | error ("%qs is not a valid number " | |
2850 | "in %<-mstack-protector-guard-offset=%>", str); | |
2851 | ||
2852 | if (!IN_RANGE (offset, HOST_WIDE_INT_C (-0x80000000), | |
2853 | HOST_WIDE_INT_C (0x7fffffff))) | |
2854 | error ("%qs is not a valid offset " | |
2855 | "in %<-mstack-protector-guard-offset=%>", str); | |
2856 | ||
2857 | opts->x_ix86_stack_protector_guard_offset = offset; | |
2858 | } | |
2859 | #ifdef TARGET_THREAD_SSP_OFFSET | |
2860 | else | |
2861 | opts->x_ix86_stack_protector_guard_offset = TARGET_THREAD_SSP_OFFSET; | |
2862 | #endif | |
2863 | ||
2864 | if (opts_set->x_ix86_stack_protector_guard_reg_str) | |
2865 | { | |
2866 | const char *str = opts->x_ix86_stack_protector_guard_reg_str; | |
2867 | addr_space_t seg = ADDR_SPACE_GENERIC; | |
2868 | ||
2869 | /* Discard optional register prefix. */ | |
2870 | if (str[0] == '%') | |
2871 | str++; | |
2872 | ||
2873 | if (strlen (str) == 2 && str[1] == 's') | |
2874 | { | |
2875 | if (str[0] == 'f') | |
2876 | seg = ADDR_SPACE_SEG_FS; | |
2877 | else if (str[0] == 'g') | |
2878 | seg = ADDR_SPACE_SEG_GS; | |
2879 | } | |
2880 | ||
2881 | if (seg == ADDR_SPACE_GENERIC) | |
2882 | error ("%qs is not a valid base register " | |
2883 | "in %<-mstack-protector-guard-reg=%>", | |
2884 | opts->x_ix86_stack_protector_guard_reg_str); | |
2885 | ||
2886 | opts->x_ix86_stack_protector_guard_reg = seg; | |
2887 | } | |
2888 | else | |
2889 | { | |
2890 | opts->x_ix86_stack_protector_guard_reg = DEFAULT_TLS_SEG_REG; | |
2891 | ||
2892 | /* The kernel uses a different segment register for performance | |
2893 | reasons; a system call would not have to trash the userspace | |
2894 | segment register, which would be expensive. */ | |
2895 | if (opts->x_ix86_cmodel == CM_KERNEL) | |
2896 | opts->x_ix86_stack_protector_guard_reg = ADDR_SPACE_SEG_GS; | |
2897 | } | |
2898 | ||
2899 | /* Handle -mmemcpy-strategy= and -mmemset-strategy= */ | |
2900 | if (opts->x_ix86_tune_memcpy_strategy) | |
2901 | { | |
2902 | char *str = xstrdup (opts->x_ix86_tune_memcpy_strategy); | |
2903 | ix86_parse_stringop_strategy_string (str, false); | |
2904 | free (str); | |
2905 | } | |
2906 | ||
2907 | if (opts->x_ix86_tune_memset_strategy) | |
2908 | { | |
2909 | char *str = xstrdup (opts->x_ix86_tune_memset_strategy); | |
2910 | ix86_parse_stringop_strategy_string (str, true); | |
2911 | free (str); | |
2912 | } | |
2913 | ||
2914 | /* Save the initial options in case the user does function specific | |
2915 | options. */ | |
2916 | if (main_args_p) | |
e401db7b JJ |
2917 | { |
2918 | opts->x_ix86_excess_precision | |
2919 | = opts->x_flag_excess_precision; | |
2920 | opts->x_ix86_unsafe_math_optimizations | |
2921 | = opts->x_flag_unsafe_math_optimizations; | |
2922 | target_option_default_node = target_option_current_node | |
2923 | = build_target_option_node (opts, opts_set); | |
2924 | } | |
2bf6d935 ML |
2925 | |
2926 | if (opts->x_flag_cf_protection != CF_NONE) | |
77d372ab L |
2927 | { |
2928 | if ((opts->x_flag_cf_protection & CF_BRANCH) == CF_BRANCH | |
2929 | && !TARGET_64BIT && !TARGET_CMOV) | |
2930 | error ("%<-fcf-protection%> is not compatible with this target"); | |
2931 | ||
2932 | opts->x_flag_cf_protection | |
2bf6d935 | 2933 | = (cf_protection_level) (opts->x_flag_cf_protection | CF_SET); |
77d372ab | 2934 | } |
2bf6d935 | 2935 | |
105c2795 | 2936 | if (ix86_tune_features [X86_TUNE_AVOID_256FMA_CHAINS]) |
028d4092 | 2937 | SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 256); |
105c2795 | 2938 | else if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS]) |
028d4092 | 2939 | SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 128); |
2bf6d935 ML |
2940 | |
2941 | /* PR86952: jump table usage with retpolines is slow. | |
2942 | The PR provides some numbers about the slowness. */ | |
6ed76044 ML |
2943 | if (ix86_indirect_branch != indirect_branch_keep) |
2944 | SET_OPTION_IF_UNSET (opts, opts_set, flag_jump_tables, 0); | |
2bf6d935 | 2945 | |
c64d1522 KL |
2946 | SET_OPTION_IF_UNSET (opts, opts_set, param_ira_consider_dup_in_all_alts, 0); |
2947 | ||
a314d503 RB |
2948 | /* Fully masking the main or the epilogue vectorized loop is not |
2949 | profitable generally so leave it disabled until we get more | |
2950 | fine grained control & costing. */ | |
2951 | SET_OPTION_IF_UNSET (opts, opts_set, param_vect_partial_vector_usage, 0); | |
2952 | ||
2bf6d935 ML |
2953 | return true; |
2954 | } | |
2955 | ||
2956 | /* Implement the TARGET_OPTION_OVERRIDE hook. */ | |
2957 | ||
2958 | void | |
2959 | ix86_option_override (void) | |
2960 | { | |
2961 | ix86_option_override_internal (true, &global_options, &global_options_set); | |
2962 | } | |
2963 | ||
2964 | /* Remember the last target of ix86_set_current_function. */ | |
2965 | static GTY(()) tree ix86_previous_fndecl; | |
2966 | ||
2967 | /* Set targets globals to the default (or current #pragma GCC target | |
2968 | if active). Invalidate ix86_previous_fndecl cache. */ | |
2969 | ||
2970 | void | |
2971 | ix86_reset_previous_fndecl (void) | |
2972 | { | |
2973 | tree new_tree = target_option_current_node; | |
ba948b37 JJ |
2974 | cl_target_option_restore (&global_options, &global_options_set, |
2975 | TREE_TARGET_OPTION (new_tree)); | |
2bf6d935 ML |
2976 | if (TREE_TARGET_GLOBALS (new_tree)) |
2977 | restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); | |
2978 | else if (new_tree == target_option_default_node) | |
2979 | restore_target_globals (&default_target_globals); | |
2980 | else | |
2981 | TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); | |
2982 | ix86_previous_fndecl = NULL_TREE; | |
2983 | } | |
2984 | ||
2985 | /* Add target attribute to SIMD clone NODE if needed. */ | |
2986 | ||
2987 | void | |
2988 | ix86_simd_clone_adjust (struct cgraph_node *node) | |
2989 | { | |
2990 | const char *str = NULL; | |
2991 | ||
2992 | /* Attributes need to be adjusted for definitions, not declarations. */ | |
2993 | if (!node->definition) | |
2994 | return; | |
2995 | ||
2996 | gcc_assert (node->decl == cfun->decl); | |
2997 | switch (node->simdclone->vecsize_mangle) | |
2998 | { | |
2999 | case 'b': | |
3000 | if (!TARGET_SSE2) | |
3001 | str = "sse2"; | |
3002 | break; | |
3003 | case 'c': | |
1609bedd JJ |
3004 | if (TARGET_PREFER_AVX128) |
3005 | { | |
3006 | if (!TARGET_AVX) | |
3007 | str = "avx,prefer-vector-width=256"; | |
3008 | else | |
3009 | str = "prefer-vector-width=256"; | |
3010 | } | |
3011 | else if (!TARGET_AVX) | |
2bf6d935 ML |
3012 | str = "avx"; |
3013 | break; | |
3014 | case 'd': | |
1609bedd JJ |
3015 | if (TARGET_PREFER_AVX128) |
3016 | { | |
3017 | if (!TARGET_AVX2) | |
3018 | str = "avx2,prefer-vector-width=256"; | |
3019 | else | |
3020 | str = "prefer-vector-width=256"; | |
3021 | } | |
3022 | else if (!TARGET_AVX2) | |
2bf6d935 ML |
3023 | str = "avx2"; |
3024 | break; | |
3025 | case 'e': | |
1609bedd JJ |
3026 | if (TARGET_PREFER_AVX256) |
3027 | { | |
3028 | if (!TARGET_AVX512F) | |
3029 | str = "avx512f,prefer-vector-width=512"; | |
3030 | else | |
3031 | str = "prefer-vector-width=512"; | |
3032 | } | |
3033 | else if (!TARGET_AVX512F) | |
2bf6d935 ML |
3034 | str = "avx512f"; |
3035 | break; | |
3036 | default: | |
3037 | gcc_unreachable (); | |
3038 | } | |
3039 | if (str == NULL) | |
3040 | return; | |
3041 | push_cfun (NULL); | |
3042 | tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str)); | |
3043 | bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0); | |
3044 | gcc_assert (ok); | |
3045 | pop_cfun (); | |
3046 | ix86_reset_previous_fndecl (); | |
3047 | ix86_set_current_function (node->decl); | |
3048 | } | |
3049 | ||
3050 | ||
3051 | ||
3052 | /* Set the func_type field from the function FNDECL. */ | |
3053 | ||
3054 | static void | |
3055 | ix86_set_func_type (tree fndecl) | |
3056 | { | |
3057 | if (cfun->machine->func_type == TYPE_UNKNOWN) | |
3058 | { | |
3059 | if (lookup_attribute ("interrupt", | |
3060 | TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))) | |
3061 | { | |
3062 | if (ix86_function_naked (fndecl)) | |
3063 | error_at (DECL_SOURCE_LOCATION (fndecl), | |
3064 | "interrupt and naked attributes are not compatible"); | |
3065 | ||
3066 | int nargs = 0; | |
3067 | for (tree arg = DECL_ARGUMENTS (fndecl); | |
3068 | arg; | |
3069 | arg = TREE_CHAIN (arg)) | |
3070 | nargs++; | |
3071 | cfun->machine->no_caller_saved_registers = true; | |
3072 | cfun->machine->func_type | |
3073 | = nargs == 2 ? TYPE_EXCEPTION : TYPE_INTERRUPT; | |
3074 | ||
3075 | ix86_optimize_mode_switching[X86_DIRFLAG] = 1; | |
3076 | ||
3077 | /* Only dwarf2out.c can handle -WORD(AP) as a pointer argument. */ | |
3078 | if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG) | |
3079 | sorry ("only DWARF debug format is supported for interrupt " | |
3080 | "service routine"); | |
3081 | } | |
3082 | else | |
3083 | { | |
3084 | cfun->machine->func_type = TYPE_NORMAL; | |
3085 | if (lookup_attribute ("no_caller_saved_registers", | |
3086 | TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))) | |
3087 | cfun->machine->no_caller_saved_registers = true; | |
3088 | } | |
3089 | } | |
3090 | } | |
3091 | ||
3092 | /* Set the indirect_branch_type field from the function FNDECL. */ | |
3093 | ||
3094 | static void | |
3095 | ix86_set_indirect_branch_type (tree fndecl) | |
3096 | { | |
3097 | if (cfun->machine->indirect_branch_type == indirect_branch_unset) | |
3098 | { | |
3099 | tree attr = lookup_attribute ("indirect_branch", | |
3100 | DECL_ATTRIBUTES (fndecl)); | |
3101 | if (attr != NULL) | |
3102 | { | |
3103 | tree args = TREE_VALUE (attr); | |
3104 | if (args == NULL) | |
3105 | gcc_unreachable (); | |
3106 | tree cst = TREE_VALUE (args); | |
3107 | if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0) | |
3108 | cfun->machine->indirect_branch_type = indirect_branch_keep; | |
3109 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0) | |
3110 | cfun->machine->indirect_branch_type = indirect_branch_thunk; | |
3111 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0) | |
3112 | cfun->machine->indirect_branch_type = indirect_branch_thunk_inline; | |
3113 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0) | |
3114 | cfun->machine->indirect_branch_type = indirect_branch_thunk_extern; | |
3115 | else | |
3116 | gcc_unreachable (); | |
3117 | } | |
3118 | else | |
3119 | cfun->machine->indirect_branch_type = ix86_indirect_branch; | |
3120 | ||
3121 | /* -mcmodel=large is not compatible with -mindirect-branch=thunk | |
3122 | nor -mindirect-branch=thunk-extern. */ | |
3123 | if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) | |
3124 | && ((cfun->machine->indirect_branch_type | |
3125 | == indirect_branch_thunk_extern) | |
3126 | || (cfun->machine->indirect_branch_type | |
3127 | == indirect_branch_thunk))) | |
3128 | error ("%<-mindirect-branch=%s%> and %<-mcmodel=large%> are not " | |
3129 | "compatible", | |
3130 | ((cfun->machine->indirect_branch_type | |
3131 | == indirect_branch_thunk_extern) | |
3132 | ? "thunk-extern" : "thunk")); | |
3133 | ||
3134 | if (cfun->machine->indirect_branch_type != indirect_branch_keep | |
9be3bb2c L |
3135 | && (cfun->machine->indirect_branch_type |
3136 | != indirect_branch_thunk_extern) | |
2bf6d935 ML |
3137 | && (flag_cf_protection & CF_RETURN)) |
3138 | error ("%<-mindirect-branch%> and %<-fcf-protection%> are not " | |
3139 | "compatible"); | |
3140 | } | |
3141 | ||
3142 | if (cfun->machine->function_return_type == indirect_branch_unset) | |
3143 | { | |
3144 | tree attr = lookup_attribute ("function_return", | |
3145 | DECL_ATTRIBUTES (fndecl)); | |
3146 | if (attr != NULL) | |
3147 | { | |
3148 | tree args = TREE_VALUE (attr); | |
3149 | if (args == NULL) | |
3150 | gcc_unreachable (); | |
3151 | tree cst = TREE_VALUE (args); | |
3152 | if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0) | |
3153 | cfun->machine->function_return_type = indirect_branch_keep; | |
3154 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0) | |
3155 | cfun->machine->function_return_type = indirect_branch_thunk; | |
3156 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0) | |
3157 | cfun->machine->function_return_type = indirect_branch_thunk_inline; | |
3158 | else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0) | |
3159 | cfun->machine->function_return_type = indirect_branch_thunk_extern; | |
3160 | else | |
3161 | gcc_unreachable (); | |
3162 | } | |
3163 | else | |
3164 | cfun->machine->function_return_type = ix86_function_return; | |
3165 | ||
3166 | /* -mcmodel=large is not compatible with -mfunction-return=thunk | |
3167 | nor -mfunction-return=thunk-extern. */ | |
3168 | if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) | |
3169 | && ((cfun->machine->function_return_type | |
3170 | == indirect_branch_thunk_extern) | |
3171 | || (cfun->machine->function_return_type | |
3172 | == indirect_branch_thunk))) | |
3173 | error ("%<-mfunction-return=%s%> and %<-mcmodel=large%> are not " | |
3174 | "compatible", | |
3175 | ((cfun->machine->function_return_type | |
3176 | == indirect_branch_thunk_extern) | |
3177 | ? "thunk-extern" : "thunk")); | |
3178 | ||
3179 | if (cfun->machine->function_return_type != indirect_branch_keep | |
9be3bb2c L |
3180 | && (cfun->machine->function_return_type |
3181 | != indirect_branch_thunk_extern) | |
2bf6d935 ML |
3182 | && (flag_cf_protection & CF_RETURN)) |
3183 | error ("%<-mfunction-return%> and %<-fcf-protection%> are not " | |
3184 | "compatible"); | |
3185 | } | |
3186 | } | |
3187 | ||
3188 | /* Establish appropriate back-end context for processing the function | |
3189 | FNDECL. The argument might be NULL to indicate processing at top | |
3190 | level, outside of any function scope. */ | |
3191 | void | |
3192 | ix86_set_current_function (tree fndecl) | |
3193 | { | |
3194 | /* Only change the context if the function changes. This hook is called | |
3195 | several times in the course of compiling a function, and we don't want to | |
3196 | slow things down too much or call target_reinit when it isn't safe. */ | |
3197 | if (fndecl == ix86_previous_fndecl) | |
3198 | { | |
3199 | /* There may be 2 function bodies for the same function FNDECL, | |
3200 | one is extern inline and one isn't. Call ix86_set_func_type | |
3201 | to set the func_type field. */ | |
3202 | if (fndecl != NULL_TREE) | |
3203 | { | |
3204 | ix86_set_func_type (fndecl); | |
3205 | ix86_set_indirect_branch_type (fndecl); | |
3206 | } | |
3207 | return; | |
3208 | } | |
3209 | ||
3210 | tree old_tree; | |
3211 | if (ix86_previous_fndecl == NULL_TREE) | |
3212 | old_tree = target_option_current_node; | |
3213 | else if (DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)) | |
3214 | old_tree = DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl); | |
3215 | else | |
3216 | old_tree = target_option_default_node; | |
3217 | ||
3218 | if (fndecl == NULL_TREE) | |
3219 | { | |
3220 | if (old_tree != target_option_current_node) | |
3221 | ix86_reset_previous_fndecl (); | |
3222 | return; | |
3223 | } | |
3224 | ||
3225 | ix86_set_func_type (fndecl); | |
3226 | ix86_set_indirect_branch_type (fndecl); | |
3227 | ||
3228 | tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); | |
3229 | if (new_tree == NULL_TREE) | |
3230 | new_tree = target_option_default_node; | |
3231 | ||
3232 | if (old_tree != new_tree) | |
3233 | { | |
ba948b37 JJ |
3234 | cl_target_option_restore (&global_options, &global_options_set, |
3235 | TREE_TARGET_OPTION (new_tree)); | |
2bf6d935 ML |
3236 | if (TREE_TARGET_GLOBALS (new_tree)) |
3237 | restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); | |
3238 | else if (new_tree == target_option_default_node) | |
3239 | restore_target_globals (&default_target_globals); | |
3240 | else | |
3241 | TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); | |
3242 | } | |
e401db7b JJ |
3243 | else if (flag_unsafe_math_optimizations |
3244 | != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations | |
3245 | || (flag_excess_precision | |
3246 | != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision)) | |
3247 | { | |
3248 | cl_target_option_restore (&global_options, &global_options_set, | |
3249 | TREE_TARGET_OPTION (new_tree)); | |
3250 | ix86_excess_precision = flag_excess_precision; | |
3251 | ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations; | |
3252 | DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree | |
3253 | = build_target_option_node (&global_options, &global_options_set); | |
3254 | if (TREE_TARGET_GLOBALS (new_tree)) | |
3255 | restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); | |
3256 | else if (new_tree == target_option_default_node) | |
3257 | restore_target_globals (&default_target_globals); | |
3258 | else | |
3259 | TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); | |
3260 | } | |
2bf6d935 ML |
3261 | ix86_previous_fndecl = fndecl; |
3262 | ||
3263 | static bool prev_no_caller_saved_registers; | |
3264 | ||
3265 | /* 64-bit MS and SYSV ABI have different set of call used registers. | |
3266 | Avoid expensive re-initialization of init_regs each time we switch | |
3267 | function context. */ | |
3268 | if (TARGET_64BIT | |
a365fa06 | 3269 | && (call_used_or_fixed_reg_p (SI_REG) |
2bf6d935 ML |
3270 | == (cfun->machine->call_abi == MS_ABI))) |
3271 | reinit_regs (); | |
3272 | /* Need to re-initialize init_regs if caller-saved registers are | |
3273 | changed. */ | |
3274 | else if (prev_no_caller_saved_registers | |
3275 | != cfun->machine->no_caller_saved_registers) | |
3276 | reinit_regs (); | |
3277 | ||
3278 | if (cfun->machine->func_type != TYPE_NORMAL | |
3279 | || cfun->machine->no_caller_saved_registers) | |
3280 | { | |
3281 | /* Don't allow SSE, MMX nor x87 instructions since they | |
3282 | may change processor state. */ | |
3283 | const char *isa; | |
3284 | if (TARGET_SSE) | |
3285 | isa = "SSE"; | |
3286 | else if (TARGET_MMX) | |
3287 | isa = "MMX/3Dnow"; | |
3288 | else if (TARGET_80387) | |
3289 | isa = "80387"; | |
3290 | else | |
3291 | isa = NULL; | |
3292 | if (isa != NULL) | |
3293 | { | |
3294 | if (cfun->machine->func_type != TYPE_NORMAL) | |
3295 | sorry (cfun->machine->func_type == TYPE_EXCEPTION | |
3296 | ? G_("%s instructions aren%'t allowed in an" | |
3297 | " exception service routine") | |
3298 | : G_("%s instructions aren%'t allowed in an" | |
3299 | " interrupt service routine"), | |
3300 | isa); | |
3301 | else | |
3302 | sorry ("%s instructions aren%'t allowed in a function with " | |
3303 | "the %<no_caller_saved_registers%> attribute", isa); | |
3304 | /* Don't issue the same error twice. */ | |
3305 | cfun->machine->func_type = TYPE_NORMAL; | |
3306 | cfun->machine->no_caller_saved_registers = false; | |
3307 | } | |
3308 | } | |
3309 | ||
3310 | prev_no_caller_saved_registers | |
3311 | = cfun->machine->no_caller_saved_registers; | |
3312 | } | |
3313 | ||
3314 | /* Implement the TARGET_OFFLOAD_OPTIONS hook. */ | |
3315 | char * | |
3316 | ix86_offload_options (void) | |
3317 | { | |
3318 | if (TARGET_LP64) | |
3319 | return xstrdup ("-foffload-abi=lp64"); | |
3320 | return xstrdup ("-foffload-abi=ilp32"); | |
3321 | } | |
3322 | ||
3323 | /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall", | |
3324 | and "sseregparm" calling convention attributes; | |
3325 | arguments as in struct attribute_spec.handler. */ | |
3326 | ||
3327 | static tree | |
3328 | ix86_handle_cconv_attribute (tree *node, tree name, tree args, int, | |
3329 | bool *no_add_attrs) | |
3330 | { | |
3331 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
3332 | && TREE_CODE (*node) != METHOD_TYPE | |
3333 | && TREE_CODE (*node) != FIELD_DECL | |
3334 | && TREE_CODE (*node) != TYPE_DECL) | |
3335 | { | |
3336 | warning (OPT_Wattributes, "%qE attribute only applies to functions", | |
3337 | name); | |
3338 | *no_add_attrs = true; | |
3339 | return NULL_TREE; | |
3340 | } | |
3341 | ||
3342 | /* Can combine regparm with all attributes but fastcall, and thiscall. */ | |
3343 | if (is_attribute_p ("regparm", name)) | |
3344 | { | |
3345 | tree cst; | |
3346 | ||
3347 | if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node))) | |
3348 | { | |
3349 | error ("fastcall and regparm attributes are not compatible"); | |
3350 | } | |
3351 | ||
3352 | if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node))) | |
3353 | { | |
3354 | error ("regparam and thiscall attributes are not compatible"); | |
3355 | } | |
3356 | ||
3357 | cst = TREE_VALUE (args); | |
3358 | if (TREE_CODE (cst) != INTEGER_CST) | |
3359 | { | |
3360 | warning (OPT_Wattributes, | |
3361 | "%qE attribute requires an integer constant argument", | |
3362 | name); | |
3363 | *no_add_attrs = true; | |
3364 | } | |
3365 | else if (compare_tree_int (cst, REGPARM_MAX) > 0) | |
3366 | { | |
3367 | warning (OPT_Wattributes, "argument to %qE attribute larger than %d", | |
3368 | name, REGPARM_MAX); | |
3369 | *no_add_attrs = true; | |
3370 | } | |
3371 | ||
3372 | return NULL_TREE; | |
3373 | } | |
3374 | ||
3375 | if (TARGET_64BIT) | |
3376 | { | |
3377 | /* Do not warn when emulating the MS ABI. */ | |
3378 | if ((TREE_CODE (*node) != FUNCTION_TYPE | |
3379 | && TREE_CODE (*node) != METHOD_TYPE) | |
3380 | || ix86_function_type_abi (*node) != MS_ABI) | |
3381 | warning (OPT_Wattributes, "%qE attribute ignored", | |
3382 | name); | |
3383 | *no_add_attrs = true; | |
3384 | return NULL_TREE; | |
3385 | } | |
3386 | ||
3387 | /* Can combine fastcall with stdcall (redundant) and sseregparm. */ | |
3388 | if (is_attribute_p ("fastcall", name)) | |
3389 | { | |
3390 | if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node))) | |
3391 | { | |
3392 | error ("fastcall and cdecl attributes are not compatible"); | |
3393 | } | |
3394 | if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node))) | |
3395 | { | |
3396 | error ("fastcall and stdcall attributes are not compatible"); | |
3397 | } | |
3398 | if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node))) | |
3399 | { | |
3400 | error ("fastcall and regparm attributes are not compatible"); | |
3401 | } | |
3402 | if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node))) | |
3403 | { | |
3404 | error ("fastcall and thiscall attributes are not compatible"); | |
3405 | } | |
3406 | } | |
3407 | ||
3408 | /* Can combine stdcall with fastcall (redundant), regparm and | |
3409 | sseregparm. */ | |
3410 | else if (is_attribute_p ("stdcall", name)) | |
3411 | { | |
3412 | if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node))) | |
3413 | { | |
3414 | error ("stdcall and cdecl attributes are not compatible"); | |
3415 | } | |
3416 | if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node))) | |
3417 | { | |
3418 | error ("stdcall and fastcall attributes are not compatible"); | |
3419 | } | |
3420 | if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node))) | |
3421 | { | |
3422 | error ("stdcall and thiscall attributes are not compatible"); | |
3423 | } | |
3424 | } | |
3425 | ||
3426 | /* Can combine cdecl with regparm and sseregparm. */ | |
3427 | else if (is_attribute_p ("cdecl", name)) | |
3428 | { | |
3429 | if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node))) | |
3430 | { | |
3431 | error ("stdcall and cdecl attributes are not compatible"); | |
3432 | } | |
3433 | if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node))) | |
3434 | { | |
3435 | error ("fastcall and cdecl attributes are not compatible"); | |
3436 | } | |
3437 | if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node))) | |
3438 | { | |
3439 | error ("cdecl and thiscall attributes are not compatible"); | |
3440 | } | |
3441 | } | |
3442 | else if (is_attribute_p ("thiscall", name)) | |
3443 | { | |
3444 | if (TREE_CODE (*node) != METHOD_TYPE && pedantic) | |
3445 | warning (OPT_Wattributes, "%qE attribute is used for non-class method", | |
3446 | name); | |
3447 | if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node))) | |
3448 | { | |
3449 | error ("stdcall and thiscall attributes are not compatible"); | |
3450 | } | |
3451 | if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node))) | |
3452 | { | |
3453 | error ("fastcall and thiscall attributes are not compatible"); | |
3454 | } | |
3455 | if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node))) | |
3456 | { | |
3457 | error ("cdecl and thiscall attributes are not compatible"); | |
3458 | } | |
3459 | } | |
3460 | ||
3461 | /* Can combine sseregparm with all attributes. */ | |
3462 | ||
3463 | return NULL_TREE; | |
3464 | } | |
3465 | ||
3466 | #ifndef CHECK_STACK_LIMIT | |
3467 | #define CHECK_STACK_LIMIT (-1) | |
3468 | #endif | |
3469 | ||
3470 | /* The transactional memory builtins are implicitly regparm or fastcall | |
3471 | depending on the ABI. Override the generic do-nothing attribute that | |
3472 | these builtins were declared with, and replace it with one of the two | |
3473 | attributes that we expect elsewhere. */ | |
3474 | ||
3475 | static tree | |
3476 | ix86_handle_tm_regparm_attribute (tree *node, tree, tree, | |
3477 | int flags, bool *no_add_attrs) | |
3478 | { | |
3479 | tree alt; | |
3480 | ||
3481 | /* In no case do we want to add the placeholder attribute. */ | |
3482 | *no_add_attrs = true; | |
3483 | ||
3484 | /* The 64-bit ABI is unchanged for transactional memory. */ | |
3485 | if (TARGET_64BIT) | |
3486 | return NULL_TREE; | |
3487 | ||
3488 | /* ??? Is there a better way to validate 32-bit windows? We have | |
3489 | cfun->machine->call_abi, but that seems to be set only for 64-bit. */ | |
3490 | if (CHECK_STACK_LIMIT > 0) | |
3491 | alt = tree_cons (get_identifier ("fastcall"), NULL, NULL); | |
3492 | else | |
3493 | { | |
3494 | alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL); | |
3495 | alt = tree_cons (get_identifier ("regparm"), alt, NULL); | |
3496 | } | |
3497 | decl_attributes (node, alt, flags); | |
3498 | ||
3499 | return NULL_TREE; | |
3500 | } | |
3501 | ||
3502 | /* Handle a "force_align_arg_pointer" attribute. */ | |
3503 | ||
3504 | static tree | |
3505 | ix86_handle_force_align_arg_pointer_attribute (tree *node, tree name, | |
3506 | tree, int, bool *no_add_attrs) | |
3507 | { | |
3508 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
3509 | && TREE_CODE (*node) != METHOD_TYPE | |
3510 | && TREE_CODE (*node) != FIELD_DECL | |
3511 | && TREE_CODE (*node) != TYPE_DECL) | |
3512 | { | |
3513 | warning (OPT_Wattributes, "%qE attribute only applies to functions", | |
3514 | name); | |
3515 | *no_add_attrs = true; | |
3516 | } | |
3517 | ||
3518 | return NULL_TREE; | |
3519 | } | |
3520 | ||
3521 | /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in | |
3522 | struct attribute_spec.handler. */ | |
3523 | ||
3524 | static tree | |
3525 | ix86_handle_struct_attribute (tree *node, tree name, tree, int, | |
3526 | bool *no_add_attrs) | |
3527 | { | |
3528 | tree *type = NULL; | |
3529 | if (DECL_P (*node)) | |
3530 | { | |
3531 | if (TREE_CODE (*node) == TYPE_DECL) | |
3532 | type = &TREE_TYPE (*node); | |
3533 | } | |
3534 | else | |
3535 | type = node; | |
3536 | ||
3537 | if (!(type && RECORD_OR_UNION_TYPE_P (*type))) | |
3538 | { | |
3539 | warning (OPT_Wattributes, "%qE attribute ignored", | |
3540 | name); | |
3541 | *no_add_attrs = true; | |
3542 | } | |
3543 | ||
3544 | else if ((is_attribute_p ("ms_struct", name) | |
3545 | && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type))) | |
3546 | || ((is_attribute_p ("gcc_struct", name) | |
3547 | && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type))))) | |
3548 | { | |
3549 | warning (OPT_Wattributes, "%qE incompatible attribute ignored", | |
3550 | name); | |
3551 | *no_add_attrs = true; | |
3552 | } | |
3553 | ||
3554 | return NULL_TREE; | |
3555 | } | |
3556 | ||
3557 | /* Handle a "callee_pop_aggregate_return" attribute; arguments as | |
3558 | in struct attribute_spec handler. */ | |
3559 | ||
3560 | static tree | |
3561 | ix86_handle_callee_pop_aggregate_return (tree *node, tree name, tree args, int, | |
3562 | bool *no_add_attrs) | |
3563 | { | |
3564 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
3565 | && TREE_CODE (*node) != METHOD_TYPE | |
3566 | && TREE_CODE (*node) != FIELD_DECL | |
3567 | && TREE_CODE (*node) != TYPE_DECL) | |
3568 | { | |
3569 | warning (OPT_Wattributes, "%qE attribute only applies to functions", | |
3570 | name); | |
3571 | *no_add_attrs = true; | |
3572 | return NULL_TREE; | |
3573 | } | |
3574 | if (TARGET_64BIT) | |
3575 | { | |
3576 | warning (OPT_Wattributes, "%qE attribute only available for 32-bit", | |
3577 | name); | |
3578 | *no_add_attrs = true; | |
3579 | return NULL_TREE; | |
3580 | } | |
3581 | if (is_attribute_p ("callee_pop_aggregate_return", name)) | |
3582 | { | |
3583 | tree cst; | |
3584 | ||
3585 | cst = TREE_VALUE (args); | |
3586 | if (TREE_CODE (cst) != INTEGER_CST) | |
3587 | { | |
3588 | warning (OPT_Wattributes, | |
3589 | "%qE attribute requires an integer constant argument", | |
3590 | name); | |
3591 | *no_add_attrs = true; | |
3592 | } | |
3593 | else if (compare_tree_int (cst, 0) != 0 | |
3594 | && compare_tree_int (cst, 1) != 0) | |
3595 | { | |
3596 | warning (OPT_Wattributes, | |
3597 | "argument to %qE attribute is neither zero, nor one", | |
3598 | name); | |
3599 | *no_add_attrs = true; | |
3600 | } | |
3601 | ||
3602 | return NULL_TREE; | |
3603 | } | |
3604 | ||
3605 | return NULL_TREE; | |
3606 | } | |
3607 | ||
3608 | /* Handle a "ms_abi" or "sysv" attribute; arguments as in | |
3609 | struct attribute_spec.handler. */ | |
3610 | ||
3611 | static tree | |
3612 | ix86_handle_abi_attribute (tree *node, tree name, tree, int, | |
3613 | bool *no_add_attrs) | |
3614 | { | |
3615 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
3616 | && TREE_CODE (*node) != METHOD_TYPE | |
3617 | && TREE_CODE (*node) != FIELD_DECL | |
3618 | && TREE_CODE (*node) != TYPE_DECL) | |
3619 | { | |
3620 | warning (OPT_Wattributes, "%qE attribute only applies to functions", | |
3621 | name); | |
3622 | *no_add_attrs = true; | |
3623 | return NULL_TREE; | |
3624 | } | |
3625 | ||
3626 | /* Can combine regparm with all attributes but fastcall. */ | |
3627 | if (is_attribute_p ("ms_abi", name)) | |
3628 | { | |
3629 | if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node))) | |
3630 | { | |
a9c697b8 MS |
3631 | error ("%qs and %qs attributes are not compatible", |
3632 | "ms_abi", "sysv_abi"); | |
2bf6d935 ML |
3633 | } |
3634 | ||
3635 | return NULL_TREE; | |
3636 | } | |
3637 | else if (is_attribute_p ("sysv_abi", name)) | |
3638 | { | |
3639 | if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node))) | |
3640 | { | |
a9c697b8 MS |
3641 | error ("%qs and %qs attributes are not compatible", |
3642 | "ms_abi", "sysv_abi"); | |
2bf6d935 ML |
3643 | } |
3644 | ||
3645 | return NULL_TREE; | |
3646 | } | |
3647 | ||
3648 | return NULL_TREE; | |
3649 | } | |
3650 | ||
3651 | static tree | |
3652 | ix86_handle_fndecl_attribute (tree *node, tree name, tree args, int, | |
3653 | bool *no_add_attrs) | |
3654 | { | |
3655 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
3656 | { | |
3657 | warning (OPT_Wattributes, "%qE attribute only applies to functions", | |
3658 | name); | |
3659 | *no_add_attrs = true; | |
3660 | } | |
3661 | ||
3662 | if (is_attribute_p ("indirect_branch", name)) | |
3663 | { | |
3664 | tree cst = TREE_VALUE (args); | |
3665 | if (TREE_CODE (cst) != STRING_CST) | |
3666 | { | |
3667 | warning (OPT_Wattributes, | |
3668 | "%qE attribute requires a string constant argument", | |
3669 | name); | |
3670 | *no_add_attrs = true; | |
3671 | } | |
3672 | else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0 | |
3673 | && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0 | |
3674 | && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0 | |
3675 | && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0) | |
3676 | { | |
3677 | warning (OPT_Wattributes, | |
3678 | "argument to %qE attribute is not " | |
3679 | "(keep|thunk|thunk-inline|thunk-extern)", name); | |
3680 | *no_add_attrs = true; | |
3681 | } | |
3682 | } | |
3683 | ||
3684 | if (is_attribute_p ("function_return", name)) | |
3685 | { | |
3686 | tree cst = TREE_VALUE (args); | |
3687 | if (TREE_CODE (cst) != STRING_CST) | |
3688 | { | |
3689 | warning (OPT_Wattributes, | |
3690 | "%qE attribute requires a string constant argument", | |
3691 | name); | |
3692 | *no_add_attrs = true; | |
3693 | } | |
3694 | else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0 | |
3695 | && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0 | |
3696 | && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0 | |
3697 | && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0) | |
3698 | { | |
3699 | warning (OPT_Wattributes, | |
3700 | "argument to %qE attribute is not " | |
3701 | "(keep|thunk|thunk-inline|thunk-extern)", name); | |
3702 | *no_add_attrs = true; | |
3703 | } | |
3704 | } | |
3705 | ||
3706 | return NULL_TREE; | |
3707 | } | |
3708 | ||
3709 | static tree | |
3710 | ix86_handle_no_caller_saved_registers_attribute (tree *, tree, tree, | |
3711 | int, bool *) | |
3712 | { | |
3713 | return NULL_TREE; | |
3714 | } | |
3715 | ||
3716 | static tree | |
3717 | ix86_handle_interrupt_attribute (tree *node, tree, tree, int, bool *) | |
3718 | { | |
3719 | /* DECL_RESULT and DECL_ARGUMENTS do not exist there yet, | |
3720 | but the function type contains args and return type data. */ | |
3721 | tree func_type = *node; | |
3722 | tree return_type = TREE_TYPE (func_type); | |
3723 | ||
3724 | int nargs = 0; | |
3725 | tree current_arg_type = TYPE_ARG_TYPES (func_type); | |
3726 | while (current_arg_type | |
3727 | && ! VOID_TYPE_P (TREE_VALUE (current_arg_type))) | |
3728 | { | |
3729 | if (nargs == 0) | |
3730 | { | |
3731 | if (! POINTER_TYPE_P (TREE_VALUE (current_arg_type))) | |
3732 | error ("interrupt service routine should have a pointer " | |
3733 | "as the first argument"); | |
3734 | } | |
3735 | else if (nargs == 1) | |
3736 | { | |
3737 | if (TREE_CODE (TREE_VALUE (current_arg_type)) != INTEGER_TYPE | |
3738 | || TYPE_MODE (TREE_VALUE (current_arg_type)) != word_mode) | |
3739 | error ("interrupt service routine should have %qs " | |
3740 | "as the second argument", | |
3741 | TARGET_64BIT | |
3742 | ? (TARGET_X32 ? "unsigned long long int" | |
3743 | : "unsigned long int") | |
3744 | : "unsigned int"); | |
3745 | } | |
3746 | nargs++; | |
3747 | current_arg_type = TREE_CHAIN (current_arg_type); | |
3748 | } | |
3749 | if (!nargs || nargs > 2) | |
3750 | error ("interrupt service routine can only have a pointer argument " | |
3751 | "and an optional integer argument"); | |
3752 | if (! VOID_TYPE_P (return_type)) | |
a9c697b8 | 3753 | error ("interrupt service routine must return %<void%>"); |
2bf6d935 ML |
3754 | |
3755 | return NULL_TREE; | |
3756 | } | |
3757 | ||
3758 | /* Handle fentry_name / fentry_section attribute. */ | |
3759 | ||
3760 | static tree | |
3761 | ix86_handle_fentry_name (tree *node, tree name, tree args, | |
3762 | int, bool *no_add_attrs) | |
3763 | { | |
3764 | if (TREE_CODE (*node) == FUNCTION_DECL | |
3765 | && TREE_CODE (TREE_VALUE (args)) == STRING_CST) | |
3766 | /* Do nothing else, just set the attribute. We'll get at | |
3767 | it later with lookup_attribute. */ | |
3768 | ; | |
3769 | else | |
3770 | { | |
3771 | warning (OPT_Wattributes, "%qE attribute ignored", name); | |
3772 | *no_add_attrs = true; | |
3773 | } | |
3774 | ||
3775 | return NULL_TREE; | |
3776 | } | |
3777 | ||
3778 | /* Table of valid machine attributes. */ | |
3779 | const struct attribute_spec ix86_attribute_table[] = | |
3780 | { | |
3781 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, | |
3782 | affects_type_identity, handler, exclude } */ | |
3783 | /* Stdcall attribute says callee is responsible for popping arguments | |
3784 | if they are not variable. */ | |
3785 | { "stdcall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute, | |
3786 | NULL }, | |
3787 | /* Fastcall attribute says callee is responsible for popping arguments | |
3788 | if they are not variable. */ | |
3789 | { "fastcall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute, | |
3790 | NULL }, | |
3791 | /* Thiscall attribute says callee is responsible for popping arguments | |
3792 | if they are not variable. */ | |
3793 | { "thiscall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute, | |
3794 | NULL }, | |
3795 | /* Cdecl attribute says the callee is a normal C declaration */ | |
3796 | { "cdecl", 0, 0, false, true, true, true, ix86_handle_cconv_attribute, | |
3797 | NULL }, | |
3798 | /* Regparm attribute specifies how many integer arguments are to be | |
3799 | passed in registers. */ | |
3800 | { "regparm", 1, 1, false, true, true, true, ix86_handle_cconv_attribute, | |
3801 | NULL }, | |
3802 | /* Sseregparm attribute says we are using x86_64 calling conventions | |
3803 | for FP arguments. */ | |
3804 | { "sseregparm", 0, 0, false, true, true, true, ix86_handle_cconv_attribute, | |
3805 | NULL }, | |
3806 | /* The transactional memory builtins are implicitly regparm or fastcall | |
3807 | depending on the ABI. Override the generic do-nothing attribute that | |
3808 | these builtins were declared with. */ | |
3809 | { "*tm regparm", 0, 0, false, true, true, true, | |
3810 | ix86_handle_tm_regparm_attribute, NULL }, | |
3811 | /* force_align_arg_pointer says this function realigns the stack at entry. */ | |
3812 | { "force_align_arg_pointer", 0, 0, | |
3813 | false, true, true, false, ix86_handle_force_align_arg_pointer_attribute, | |
3814 | NULL }, | |
3815 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES | |
3816 | { "dllimport", 0, 0, false, false, false, false, handle_dll_attribute, | |
3817 | NULL }, | |
3818 | { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute, | |
3819 | NULL }, | |
3820 | { "shared", 0, 0, true, false, false, false, | |
3821 | ix86_handle_shared_attribute, NULL }, | |
3822 | #endif | |
3823 | { "ms_struct", 0, 0, false, false, false, false, | |
3824 | ix86_handle_struct_attribute, NULL }, | |
3825 | { "gcc_struct", 0, 0, false, false, false, false, | |
3826 | ix86_handle_struct_attribute, NULL }, | |
3827 | #ifdef SUBTARGET_ATTRIBUTE_TABLE | |
3828 | SUBTARGET_ATTRIBUTE_TABLE, | |
3829 | #endif | |
3830 | /* ms_abi and sysv_abi calling convention function attributes. */ | |
3831 | { "ms_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute, NULL }, | |
3832 | { "sysv_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute, | |
3833 | NULL }, | |
3834 | { "ms_abi va_list", 0, 0, false, false, false, false, NULL, NULL }, | |
3835 | { "sysv_abi va_list", 0, 0, false, false, false, false, NULL, NULL }, | |
3836 | { "ms_hook_prologue", 0, 0, true, false, false, false, | |
3837 | ix86_handle_fndecl_attribute, NULL }, | |
3838 | { "callee_pop_aggregate_return", 1, 1, false, true, true, true, | |
3839 | ix86_handle_callee_pop_aggregate_return, NULL }, | |
3840 | { "interrupt", 0, 0, false, true, true, false, | |
3841 | ix86_handle_interrupt_attribute, NULL }, | |
3842 | { "no_caller_saved_registers", 0, 0, false, true, true, false, | |
3843 | ix86_handle_no_caller_saved_registers_attribute, NULL }, | |
3844 | { "naked", 0, 0, true, false, false, false, | |
3845 | ix86_handle_fndecl_attribute, NULL }, | |
3846 | { "indirect_branch", 1, 1, true, false, false, false, | |
3847 | ix86_handle_fndecl_attribute, NULL }, | |
3848 | { "function_return", 1, 1, true, false, false, false, | |
3849 | ix86_handle_fndecl_attribute, NULL }, | |
3850 | { "indirect_return", 0, 0, false, true, true, false, | |
3851 | NULL, NULL }, | |
3852 | { "fentry_name", 1, 1, true, false, false, false, | |
3853 | ix86_handle_fentry_name, NULL }, | |
3854 | { "fentry_section", 1, 1, true, false, false, false, | |
3855 | ix86_handle_fentry_name, NULL }, | |
3856 | { "cf_check", 0, 0, true, false, false, false, | |
3857 | ix86_handle_fndecl_attribute, NULL }, | |
3858 | ||
3859 | /* End element. */ | |
3860 | { NULL, 0, 0, false, false, false, false, NULL, NULL } | |
3861 | }; | |
3862 | ||
3863 | #include "gt-i386-options.h" |