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