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