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