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