]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/i386/i386-options.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / i386 / i386-options.c
1 /* Copyright (C) 1988-2021 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 enum excess_precision orig_ix86_excess_precision
1378 = opts->x_ix86_excess_precision;
1379 bool orig_ix86_unsafe_math_optimizations
1380 = opts->x_ix86_unsafe_math_optimizations;
1381 opts->x_ix86_excess_precision = opts->x_flag_excess_precision;
1382 opts->x_ix86_unsafe_math_optimizations
1383 = opts->x_flag_unsafe_math_optimizations;
1384
1385 /* Save the current options unless we are validating options for
1386 #pragma. */
1387 t = build_target_option_node (opts, opts_set);
1388
1389 opts->x_ix86_arch_string = orig_arch_string;
1390 opts->x_ix86_tune_string = orig_tune_string;
1391 opts_set->x_ix86_fpmath = orig_fpmath_set;
1392 opts_set->x_prefer_vector_width_type = orig_pvw_set;
1393 opts->x_ix86_excess_precision = orig_ix86_excess_precision;
1394 opts->x_ix86_unsafe_math_optimizations
1395 = orig_ix86_unsafe_math_optimizations;
1396
1397 release_options_strings (option_strings);
1398 }
1399
1400 return t;
1401 }
1402
1403 /* Hook to validate attribute((target("string"))). */
1404
1405 bool
1406 ix86_valid_target_attribute_p (tree fndecl,
1407 tree ARG_UNUSED (name),
1408 tree args,
1409 int flags)
1410 {
1411 struct gcc_options func_options, func_options_set;
1412 tree new_target, new_optimize;
1413 bool ret = true;
1414
1415 /* attribute((target("default"))) does nothing, beyond
1416 affecting multi-versioning. */
1417 if (TREE_VALUE (args)
1418 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
1419 && TREE_CHAIN (args) == NULL_TREE
1420 && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0)
1421 return true;
1422
1423 tree old_optimize = build_optimization_node (&global_options,
1424 &global_options_set);
1425
1426 /* Get the optimization options of the current function. */
1427 tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
1428
1429 if (!func_optimize)
1430 func_optimize = old_optimize;
1431
1432 /* Init func_options. */
1433 memset (&func_options, 0, sizeof (func_options));
1434 init_options_struct (&func_options, NULL);
1435 lang_hooks.init_options_struct (&func_options);
1436 memset (&func_options_set, 0, sizeof (func_options_set));
1437
1438 cl_optimization_restore (&func_options, &func_options_set,
1439 TREE_OPTIMIZATION (func_optimize));
1440
1441 /* Initialize func_options to the default before its target options can
1442 be set. */
1443 cl_target_option_restore (&func_options, &func_options_set,
1444 TREE_TARGET_OPTION (target_option_default_node));
1445
1446 /* FLAGS == 1 is used for target_clones attribute. */
1447 new_target
1448 = ix86_valid_target_attribute_tree (fndecl, args, &func_options,
1449 &func_options_set, flags == 1);
1450
1451 new_optimize = build_optimization_node (&func_options, &func_options_set);
1452
1453 if (new_target == error_mark_node)
1454 ret = false;
1455
1456 else if (fndecl && new_target)
1457 {
1458 DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
1459
1460 if (old_optimize != new_optimize)
1461 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
1462 }
1463
1464 return ret;
1465 }
1466
1467 const char *stringop_alg_names[] = {
1468 #define DEF_ENUM
1469 #define DEF_ALG(alg, name) #name,
1470 #include "stringop.def"
1471 #undef DEF_ENUM
1472 #undef DEF_ALG
1473 };
1474
1475 /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=.
1476 The string is of the following form (or comma separated list of it):
1477
1478 strategy_alg:max_size:[align|noalign]
1479
1480 where the full size range for the strategy is either [0, max_size] or
1481 [min_size, max_size], in which min_size is the max_size + 1 of the
1482 preceding range. The last size range must have max_size == -1.
1483
1484 Examples:
1485
1486 1.
1487 -mmemcpy-strategy=libcall:-1:noalign
1488
1489 this is equivalent to (for known size memcpy) -mstringop-strategy=libcall
1490
1491
1492 2.
1493 -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign
1494
1495 This is to tell the compiler to use the following strategy for memset
1496 1) when the expected size is between [1, 16], use rep_8byte strategy;
1497 2) when the size is between [17, 2048], use vector_loop;
1498 3) when the size is > 2048, use libcall. */
1499
1500 struct stringop_size_range
1501 {
1502 int max;
1503 stringop_alg alg;
1504 bool noalign;
1505 };
1506
1507 static void
1508 ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset)
1509 {
1510 const struct stringop_algs *default_algs;
1511 stringop_size_range input_ranges[MAX_STRINGOP_ALGS];
1512 char *curr_range_str, *next_range_str;
1513 const char *opt = is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=";
1514 int i = 0, n = 0;
1515
1516 if (is_memset)
1517 default_algs = &ix86_cost->memset[TARGET_64BIT != 0];
1518 else
1519 default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
1520
1521 curr_range_str = strategy_str;
1522
1523 do
1524 {
1525 int maxs;
1526 char alg_name[128];
1527 char align[16];
1528 next_range_str = strchr (curr_range_str, ',');
1529 if (next_range_str)
1530 *next_range_str++ = '\0';
1531
1532 if (sscanf (curr_range_str, "%20[^:]:%d:%10s", alg_name, &maxs,
1533 align) != 3)
1534 {
1535 error ("wrong argument %qs to option %qs", curr_range_str, opt);
1536 return;
1537 }
1538
1539 if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1))
1540 {
1541 error ("size ranges of option %qs should be increasing", opt);
1542 return;
1543 }
1544
1545 for (i = 0; i < last_alg; i++)
1546 if (!strcmp (alg_name, stringop_alg_names[i]))
1547 break;
1548
1549 if (i == last_alg)
1550 {
1551 error ("wrong strategy name %qs specified for option %qs",
1552 alg_name, opt);
1553
1554 auto_vec <const char *> candidates;
1555 for (i = 0; i < last_alg; i++)
1556 if ((stringop_alg) i != rep_prefix_8_byte || TARGET_64BIT)
1557 candidates.safe_push (stringop_alg_names[i]);
1558
1559 char *s;
1560 const char *hint
1561 = candidates_list_and_hint (alg_name, s, candidates);
1562 if (hint)
1563 inform (input_location,
1564 "valid arguments to %qs are: %s; did you mean %qs?",
1565 opt, s, hint);
1566 else
1567 inform (input_location, "valid arguments to %qs are: %s",
1568 opt, s);
1569 XDELETEVEC (s);
1570 return;
1571 }
1572
1573 if ((stringop_alg) i == rep_prefix_8_byte
1574 && !TARGET_64BIT)
1575 {
1576 /* rep; movq isn't available in 32-bit code. */
1577 error ("strategy name %qs specified for option %qs "
1578 "not supported for 32-bit code", alg_name, opt);
1579 return;
1580 }
1581
1582 input_ranges[n].max = maxs;
1583 input_ranges[n].alg = (stringop_alg) i;
1584 if (!strcmp (align, "align"))
1585 input_ranges[n].noalign = false;
1586 else if (!strcmp (align, "noalign"))
1587 input_ranges[n].noalign = true;
1588 else
1589 {
1590 error ("unknown alignment %qs specified for option %qs", align, opt);
1591 return;
1592 }
1593 n++;
1594 curr_range_str = next_range_str;
1595 }
1596 while (curr_range_str);
1597
1598 if (input_ranges[n - 1].max != -1)
1599 {
1600 error ("the max value for the last size range should be -1"
1601 " for option %qs", opt);
1602 return;
1603 }
1604
1605 if (n > MAX_STRINGOP_ALGS)
1606 {
1607 error ("too many size ranges specified in option %qs", opt);
1608 return;
1609 }
1610
1611 /* Now override the default algs array. */
1612 for (i = 0; i < n; i++)
1613 {
1614 *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max;
1615 *const_cast<stringop_alg *>(&default_algs->size[i].alg)
1616 = input_ranges[i].alg;
1617 *const_cast<int *>(&default_algs->size[i].noalign)
1618 = input_ranges[i].noalign;
1619 }
1620 }
1621
1622 \f
1623 /* parse -mtune-ctrl= option. When DUMP is true,
1624 print the features that are explicitly set. */
1625
1626 static void
1627 parse_mtune_ctrl_str (struct gcc_options *opts, bool dump)
1628 {
1629 if (!opts->x_ix86_tune_ctrl_string)
1630 return;
1631
1632 char *next_feature_string = NULL;
1633 char *curr_feature_string = xstrdup (opts->x_ix86_tune_ctrl_string);
1634 char *orig = curr_feature_string;
1635 int i;
1636 do
1637 {
1638 bool clear = false;
1639
1640 next_feature_string = strchr (curr_feature_string, ',');
1641 if (next_feature_string)
1642 *next_feature_string++ = '\0';
1643 if (*curr_feature_string == '^')
1644 {
1645 curr_feature_string++;
1646 clear = true;
1647 }
1648 for (i = 0; i < X86_TUNE_LAST; i++)
1649 {
1650 if (!strcmp (curr_feature_string, ix86_tune_feature_names[i]))
1651 {
1652 ix86_tune_features[i] = !clear;
1653 if (dump)
1654 fprintf (stderr, "Explicitly %s feature %s\n",
1655 clear ? "clear" : "set", ix86_tune_feature_names[i]);
1656 break;
1657 }
1658 }
1659 if (i == X86_TUNE_LAST)
1660 error ("unknown parameter to option %<-mtune-ctrl%>: %s",
1661 clear ? curr_feature_string - 1 : curr_feature_string);
1662 curr_feature_string = next_feature_string;
1663 }
1664 while (curr_feature_string);
1665 free (orig);
1666 }
1667
1668 /* Helper function to set ix86_tune_features. IX86_TUNE is the
1669 processor type. */
1670
1671 static void
1672 set_ix86_tune_features (struct gcc_options *opts,
1673 enum processor_type ix86_tune, bool dump)
1674 {
1675 unsigned HOST_WIDE_INT ix86_tune_mask = HOST_WIDE_INT_1U << ix86_tune;
1676 int i;
1677
1678 for (i = 0; i < X86_TUNE_LAST; ++i)
1679 {
1680 if (ix86_tune_no_default)
1681 ix86_tune_features[i] = 0;
1682 else
1683 ix86_tune_features[i]
1684 = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
1685 }
1686
1687 if (dump)
1688 {
1689 fprintf (stderr, "List of x86 specific tuning parameter names:\n");
1690 for (i = 0; i < X86_TUNE_LAST; i++)
1691 fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i],
1692 ix86_tune_features[i] ? "on" : "off");
1693 }
1694
1695 parse_mtune_ctrl_str (opts, dump);
1696 }
1697
1698
1699 /* Default align_* from the processor table. */
1700
1701 static void
1702 ix86_default_align (struct gcc_options *opts)
1703 {
1704 /* -falign-foo without argument: supply one. */
1705 if (opts->x_flag_align_loops && !opts->x_str_align_loops)
1706 opts->x_str_align_loops = processor_cost_table[ix86_tune]->align_loop;
1707 if (opts->x_flag_align_jumps && !opts->x_str_align_jumps)
1708 opts->x_str_align_jumps = processor_cost_table[ix86_tune]->align_jump;
1709 if (opts->x_flag_align_labels && !opts->x_str_align_labels)
1710 opts->x_str_align_labels = processor_cost_table[ix86_tune]->align_label;
1711 if (opts->x_flag_align_functions && !opts->x_str_align_functions)
1712 opts->x_str_align_functions = processor_cost_table[ix86_tune]->align_func;
1713 }
1714
1715 #ifndef USE_IX86_FRAME_POINTER
1716 #define USE_IX86_FRAME_POINTER 0
1717 #endif
1718
1719 /* (Re)compute option overrides affected by optimization levels in
1720 target-specific ways. */
1721
1722 static void
1723 ix86_recompute_optlev_based_flags (struct gcc_options *opts,
1724 struct gcc_options *opts_set)
1725 {
1726 /* Set the default values for switches whose default depends on TARGET_64BIT
1727 in case they weren't overwritten by command line options. */
1728 if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
1729 {
1730 if (opts->x_optimize >= 1)
1731 SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer,
1732 !USE_IX86_FRAME_POINTER);
1733 if (opts->x_flag_asynchronous_unwind_tables
1734 && TARGET_64BIT_MS_ABI)
1735 SET_OPTION_IF_UNSET (opts, opts_set, flag_unwind_tables, 1);
1736 if (opts->x_flag_asynchronous_unwind_tables == 2)
1737 opts->x_flag_unwind_tables
1738 = opts->x_flag_asynchronous_unwind_tables = 1;
1739 if (opts->x_flag_pcc_struct_return == 2)
1740 opts->x_flag_pcc_struct_return = 0;
1741 }
1742 else
1743 {
1744 if (opts->x_optimize >= 1)
1745 SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer,
1746 !(USE_IX86_FRAME_POINTER || opts->x_optimize_size));
1747 if (opts->x_flag_asynchronous_unwind_tables == 2)
1748 opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
1749 if (opts->x_flag_pcc_struct_return == 2)
1750 {
1751 /* Intel MCU psABI specifies that -freg-struct-return should
1752 be on. Instead of setting DEFAULT_PCC_STRUCT_RETURN to 0,
1753 we check -miamcu so that -freg-struct-return is always
1754 turned on if -miamcu is used. */
1755 if (TARGET_IAMCU_P (opts->x_target_flags))
1756 opts->x_flag_pcc_struct_return = 0;
1757 else
1758 opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
1759 }
1760 }
1761 }
1762
1763 /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook. */
1764
1765 void
1766 ix86_override_options_after_change (void)
1767 {
1768 ix86_default_align (&global_options);
1769 ix86_recompute_optlev_based_flags (&global_options, &global_options_set);
1770 }
1771
1772 /* Clear stack slot assignments remembered from previous functions.
1773 This is called from INIT_EXPANDERS once before RTL is emitted for each
1774 function. */
1775
1776 static struct machine_function *
1777 ix86_init_machine_status (void)
1778 {
1779 struct machine_function *f;
1780
1781 f = ggc_cleared_alloc<machine_function> ();
1782 f->call_abi = ix86_abi;
1783 f->stack_frame_required = true;
1784
1785 return f;
1786 }
1787
1788 /* Override various settings based on options. If MAIN_ARGS_P, the
1789 options are from the command line, otherwise they are from
1790 attributes. Return true if there's an error related to march
1791 option. */
1792
1793 static bool
1794 ix86_option_override_internal (bool main_args_p,
1795 struct gcc_options *opts,
1796 struct gcc_options *opts_set)
1797 {
1798 int i;
1799 unsigned HOST_WIDE_INT ix86_arch_mask;
1800 const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL);
1801
1802 /* -mrecip options. */
1803 static struct
1804 {
1805 const char *string; /* option name */
1806 unsigned int mask; /* mask bits to set */
1807 }
1808 const recip_options[] =
1809 {
1810 { "all", RECIP_MASK_ALL },
1811 { "none", RECIP_MASK_NONE },
1812 { "div", RECIP_MASK_DIV },
1813 { "sqrt", RECIP_MASK_SQRT },
1814 { "vec-div", RECIP_MASK_VEC_DIV },
1815 { "vec-sqrt", RECIP_MASK_VEC_SQRT },
1816 };
1817
1818
1819 /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
1820 TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false. */
1821 if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
1822 opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
1823 #ifdef TARGET_BI_ARCH
1824 else
1825 {
1826 #if TARGET_BI_ARCH == 1
1827 /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
1828 is on and OPTION_MASK_ABI_X32 is off. We turn off
1829 OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
1830 -mx32. */
1831 if (TARGET_X32_P (opts->x_ix86_isa_flags))
1832 opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
1833 #else
1834 /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
1835 on and OPTION_MASK_ABI_64 is off. We turn off
1836 OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
1837 -m64 or OPTION_MASK_CODE16 is turned on by -m16. */
1838 if (TARGET_LP64_P (opts->x_ix86_isa_flags)
1839 || TARGET_16BIT_P (opts->x_ix86_isa_flags))
1840 opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
1841 #endif
1842 if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
1843 && TARGET_IAMCU_P (opts->x_target_flags))
1844 sorry ("Intel MCU psABI isn%'t supported in %s mode",
1845 TARGET_X32_P (opts->x_ix86_isa_flags) ? "x32" : "64-bit");
1846 }
1847 #endif
1848
1849 if (TARGET_X32_P (opts->x_ix86_isa_flags))
1850 {
1851 /* Always turn on OPTION_MASK_ISA_64BIT and turn off
1852 OPTION_MASK_ABI_64 for TARGET_X32. */
1853 opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
1854 opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
1855 }
1856 else if (TARGET_16BIT_P (opts->x_ix86_isa_flags))
1857 opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT
1858 | OPTION_MASK_ABI_X32
1859 | OPTION_MASK_ABI_64);
1860 else if (TARGET_LP64_P (opts->x_ix86_isa_flags))
1861 {
1862 /* Always turn on OPTION_MASK_ISA_64BIT and turn off
1863 OPTION_MASK_ABI_X32 for TARGET_LP64. */
1864 opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
1865 opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
1866 }
1867
1868 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1869 SUBTARGET_OVERRIDE_OPTIONS;
1870 #endif
1871
1872 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1873 SUBSUBTARGET_OVERRIDE_OPTIONS;
1874 #endif
1875
1876 /* -fPIC is the default for x86_64. */
1877 if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags))
1878 opts->x_flag_pic = 2;
1879
1880 /* Need to check -mtune=generic first. */
1881 if (opts->x_ix86_tune_string)
1882 {
1883 /* As special support for cross compilers we read -mtune=native
1884 as -mtune=generic. With native compilers we won't see the
1885 -mtune=native, as it was changed by the driver. */
1886 if (!strcmp (opts->x_ix86_tune_string, "native"))
1887 opts->x_ix86_tune_string = "generic";
1888 else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
1889 warning (OPT_Wdeprecated,
1890 main_args_p
1891 ? G_("%<-mtune=x86-64%> is deprecated; use %<-mtune=k8%> "
1892 "or %<-mtune=generic%> instead as appropriate")
1893 : G_("%<target(\"tune=x86-64\")%> is deprecated; use "
1894 "%<target(\"tune=k8\")%> or %<target(\"tune=generic\")%>"
1895 " instead as appropriate"));
1896 }
1897 else
1898 {
1899 if (opts->x_ix86_arch_string)
1900 opts->x_ix86_tune_string = opts->x_ix86_arch_string;
1901 if (!opts->x_ix86_tune_string)
1902 {
1903 opts->x_ix86_tune_string = processor_names[TARGET_CPU_DEFAULT];
1904 ix86_tune_defaulted = 1;
1905 }
1906
1907 /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
1908 or defaulted. We need to use a sensible tune option. */
1909 if (!strncmp (opts->x_ix86_tune_string, "x86-64", 6)
1910 && (opts->x_ix86_tune_string[6] == '\0'
1911 || (!strcmp (opts->x_ix86_tune_string + 6, "-v2")
1912 || !strcmp (opts->x_ix86_tune_string + 6, "-v3")
1913 || !strcmp (opts->x_ix86_tune_string + 6, "-v4"))))
1914 opts->x_ix86_tune_string = "generic";
1915 }
1916
1917 if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
1918 && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
1919 {
1920 /* rep; movq isn't available in 32-bit code. */
1921 error ("%<-mstringop-strategy=rep_8byte%> not supported for 32-bit code");
1922 opts->x_ix86_stringop_alg = no_stringop;
1923 }
1924
1925 if (TARGET_UINTR && !TARGET_64BIT)
1926 error ("%<-muintr%> not supported for 32-bit code");
1927
1928 if (!opts->x_ix86_arch_string)
1929 opts->x_ix86_arch_string
1930 = TARGET_64BIT_P (opts->x_ix86_isa_flags)
1931 ? "x86-64" : SUBTARGET32_DEFAULT_CPU;
1932 else
1933 ix86_arch_specified = 1;
1934
1935 if (opts_set->x_ix86_pmode)
1936 {
1937 if ((TARGET_LP64_P (opts->x_ix86_isa_flags)
1938 && opts->x_ix86_pmode == PMODE_SI)
1939 || (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
1940 && opts->x_ix86_pmode == PMODE_DI))
1941 error ("address mode %qs not supported in the %s bit mode",
1942 TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long",
1943 TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32");
1944 }
1945 else
1946 opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags)
1947 ? PMODE_DI : PMODE_SI;
1948
1949 SET_OPTION_IF_UNSET (opts, opts_set, ix86_abi, DEFAULT_ABI);
1950
1951 if (opts->x_ix86_abi == MS_ABI && TARGET_X32_P (opts->x_ix86_isa_flags))
1952 error ("%<-mabi=ms%> not supported with X32 ABI");
1953 gcc_assert (opts->x_ix86_abi == SYSV_ABI || opts->x_ix86_abi == MS_ABI);
1954
1955 const char *abi_name = opts->x_ix86_abi == MS_ABI ? "ms" : "sysv";
1956 if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
1957 && opts->x_ix86_abi != DEFAULT_ABI)
1958 error ("%<-mabi=%s%> not supported with %<-fsanitize=address%>", abi_name);
1959 if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1960 && opts->x_ix86_abi != DEFAULT_ABI)
1961 error ("%<-mabi=%s%> not supported with %<-fsanitize=kernel-address%>",
1962 abi_name);
1963 if ((opts->x_flag_sanitize & SANITIZE_THREAD)
1964 && opts->x_ix86_abi != DEFAULT_ABI)
1965 error ("%<-mabi=%s%> not supported with %<-fsanitize=thread%>", abi_name);
1966
1967 /* For targets using ms ABI enable ms-extensions, if not
1968 explicit turned off. For non-ms ABI we turn off this
1969 option. */
1970 SET_OPTION_IF_UNSET (opts, opts_set, flag_ms_extensions,
1971 (MS_ABI == DEFAULT_ABI));
1972
1973 if (opts_set->x_ix86_cmodel)
1974 {
1975 switch (opts->x_ix86_cmodel)
1976 {
1977 case CM_SMALL:
1978 case CM_SMALL_PIC:
1979 if (opts->x_flag_pic)
1980 opts->x_ix86_cmodel = CM_SMALL_PIC;
1981 if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
1982 error ("code model %qs not supported in the %s bit mode",
1983 "small", "32");
1984 break;
1985
1986 case CM_MEDIUM:
1987 case CM_MEDIUM_PIC:
1988 if (opts->x_flag_pic)
1989 opts->x_ix86_cmodel = CM_MEDIUM_PIC;
1990 if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
1991 error ("code model %qs not supported in the %s bit mode",
1992 "medium", "32");
1993 else if (TARGET_X32_P (opts->x_ix86_isa_flags))
1994 error ("code model %qs not supported in x32 mode",
1995 "medium");
1996 break;
1997
1998 case CM_LARGE:
1999 case CM_LARGE_PIC:
2000 if (opts->x_flag_pic)
2001 opts->x_ix86_cmodel = CM_LARGE_PIC;
2002 if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
2003 error ("code model %qs not supported in the %s bit mode",
2004 "large", "32");
2005 else if (TARGET_X32_P (opts->x_ix86_isa_flags))
2006 error ("code model %qs not supported in x32 mode",
2007 "large");
2008 break;
2009
2010 case CM_32:
2011 if (opts->x_flag_pic)
2012 error ("code model %s does not support PIC mode", "32");
2013 if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
2014 error ("code model %qs not supported in the %s bit mode",
2015 "32", "64");
2016 break;
2017
2018 case CM_KERNEL:
2019 if (opts->x_flag_pic)
2020 {
2021 error ("code model %s does not support PIC mode", "kernel");
2022 opts->x_ix86_cmodel = CM_32;
2023 }
2024 if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
2025 error ("code model %qs not supported in the %s bit mode",
2026 "kernel", "32");
2027 break;
2028
2029 default:
2030 gcc_unreachable ();
2031 }
2032 }
2033 else
2034 {
2035 /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2036 use of rip-relative addressing. This eliminates fixups that
2037 would otherwise be needed if this object is to be placed in a
2038 DLL, and is essentially just as efficient as direct addressing. */
2039 if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
2040 && (TARGET_RDOS || TARGET_PECOFF))
2041 opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1;
2042 else if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
2043 opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL;
2044 else
2045 opts->x_ix86_cmodel = CM_32;
2046 }
2047 if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL)
2048 {
2049 error ("%<-masm=intel%> not supported in this configuration");
2050 opts->x_ix86_asm_dialect = ASM_ATT;
2051 }
2052 if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0)
2053 != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2054 sorry ("%i-bit mode not compiled in",
2055 (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2056
2057 for (i = 0; i < pta_size; i++)
2058 if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name))
2059 {
2060 if (!strcmp (opts->x_ix86_arch_string, "generic"))
2061 {
2062 error (main_args_p
2063 ? G_("%<generic%> CPU can be used only for %<-mtune=%> "
2064 "switch")
2065 : G_("%<generic%> CPU can be used only for "
2066 "%<target(\"tune=\")%> attribute"));
2067 return false;
2068 }
2069 else if (!strcmp (opts->x_ix86_arch_string, "intel"))
2070 {
2071 error (main_args_p
2072 ? G_("%<intel%> CPU can be used only for %<-mtune=%> "
2073 "switch")
2074 : G_("%<intel%> CPU can be used only for "
2075 "%<target(\"tune=\")%> attribute"));
2076 return false;
2077 }
2078
2079 if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
2080 && !((processor_alias_table[i].flags & PTA_64BIT) != 0))
2081 {
2082 error ("CPU you selected does not support x86-64 "
2083 "instruction set");
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 {
3023 opts->x_ix86_excess_precision
3024 = opts->x_flag_excess_precision;
3025 opts->x_ix86_unsafe_math_optimizations
3026 = opts->x_flag_unsafe_math_optimizations;
3027 target_option_default_node = target_option_current_node
3028 = build_target_option_node (opts, opts_set);
3029 }
3030
3031 if (opts->x_flag_cf_protection != CF_NONE)
3032 opts->x_flag_cf_protection
3033 = (cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
3034
3035 if (ix86_tune_features [X86_TUNE_AVOID_256FMA_CHAINS])
3036 SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 256);
3037 else if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])
3038 SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 128);
3039
3040 /* PR86952: jump table usage with retpolines is slow.
3041 The PR provides some numbers about the slowness. */
3042 if (ix86_indirect_branch != indirect_branch_keep)
3043 SET_OPTION_IF_UNSET (opts, opts_set, flag_jump_tables, 0);
3044
3045 return true;
3046 }
3047
3048 /* Implement the TARGET_OPTION_OVERRIDE hook. */
3049
3050 void
3051 ix86_option_override (void)
3052 {
3053 ix86_option_override_internal (true, &global_options, &global_options_set);
3054 }
3055
3056 /* Remember the last target of ix86_set_current_function. */
3057 static GTY(()) tree ix86_previous_fndecl;
3058
3059 /* Set targets globals to the default (or current #pragma GCC target
3060 if active). Invalidate ix86_previous_fndecl cache. */
3061
3062 void
3063 ix86_reset_previous_fndecl (void)
3064 {
3065 tree new_tree = target_option_current_node;
3066 cl_target_option_restore (&global_options, &global_options_set,
3067 TREE_TARGET_OPTION (new_tree));
3068 if (TREE_TARGET_GLOBALS (new_tree))
3069 restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
3070 else if (new_tree == target_option_default_node)
3071 restore_target_globals (&default_target_globals);
3072 else
3073 TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
3074 ix86_previous_fndecl = NULL_TREE;
3075 }
3076
3077 /* Add target attribute to SIMD clone NODE if needed. */
3078
3079 void
3080 ix86_simd_clone_adjust (struct cgraph_node *node)
3081 {
3082 const char *str = NULL;
3083
3084 /* Attributes need to be adjusted for definitions, not declarations. */
3085 if (!node->definition)
3086 return;
3087
3088 gcc_assert (node->decl == cfun->decl);
3089 switch (node->simdclone->vecsize_mangle)
3090 {
3091 case 'b':
3092 if (!TARGET_SSE2)
3093 str = "sse2";
3094 break;
3095 case 'c':
3096 if (TARGET_PREFER_AVX128)
3097 {
3098 if (!TARGET_AVX)
3099 str = "avx,prefer-vector-width=256";
3100 else
3101 str = "prefer-vector-width=256";
3102 }
3103 else if (!TARGET_AVX)
3104 str = "avx";
3105 break;
3106 case 'd':
3107 if (TARGET_PREFER_AVX128)
3108 {
3109 if (!TARGET_AVX2)
3110 str = "avx2,prefer-vector-width=256";
3111 else
3112 str = "prefer-vector-width=256";
3113 }
3114 else if (!TARGET_AVX2)
3115 str = "avx2";
3116 break;
3117 case 'e':
3118 if (TARGET_PREFER_AVX256)
3119 {
3120 if (!TARGET_AVX512F)
3121 str = "avx512f,prefer-vector-width=512";
3122 else
3123 str = "prefer-vector-width=512";
3124 }
3125 else if (!TARGET_AVX512F)
3126 str = "avx512f";
3127 break;
3128 default:
3129 gcc_unreachable ();
3130 }
3131 if (str == NULL)
3132 return;
3133 push_cfun (NULL);
3134 tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str));
3135 bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0);
3136 gcc_assert (ok);
3137 pop_cfun ();
3138 ix86_reset_previous_fndecl ();
3139 ix86_set_current_function (node->decl);
3140 }
3141
3142
3143
3144 /* Set the func_type field from the function FNDECL. */
3145
3146 static void
3147 ix86_set_func_type (tree fndecl)
3148 {
3149 if (cfun->machine->func_type == TYPE_UNKNOWN)
3150 {
3151 if (lookup_attribute ("interrupt",
3152 TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
3153 {
3154 if (ix86_function_naked (fndecl))
3155 error_at (DECL_SOURCE_LOCATION (fndecl),
3156 "interrupt and naked attributes are not compatible");
3157
3158 int nargs = 0;
3159 for (tree arg = DECL_ARGUMENTS (fndecl);
3160 arg;
3161 arg = TREE_CHAIN (arg))
3162 nargs++;
3163 cfun->machine->no_caller_saved_registers = true;
3164 cfun->machine->func_type
3165 = nargs == 2 ? TYPE_EXCEPTION : TYPE_INTERRUPT;
3166
3167 ix86_optimize_mode_switching[X86_DIRFLAG] = 1;
3168
3169 /* Only dwarf2out.c can handle -WORD(AP) as a pointer argument. */
3170 if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
3171 sorry ("only DWARF debug format is supported for interrupt "
3172 "service routine");
3173 }
3174 else
3175 {
3176 cfun->machine->func_type = TYPE_NORMAL;
3177 if (lookup_attribute ("no_caller_saved_registers",
3178 TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
3179 cfun->machine->no_caller_saved_registers = true;
3180 }
3181 }
3182 }
3183
3184 /* Set the indirect_branch_type field from the function FNDECL. */
3185
3186 static void
3187 ix86_set_indirect_branch_type (tree fndecl)
3188 {
3189 if (cfun->machine->indirect_branch_type == indirect_branch_unset)
3190 {
3191 tree attr = lookup_attribute ("indirect_branch",
3192 DECL_ATTRIBUTES (fndecl));
3193 if (attr != NULL)
3194 {
3195 tree args = TREE_VALUE (attr);
3196 if (args == NULL)
3197 gcc_unreachable ();
3198 tree cst = TREE_VALUE (args);
3199 if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0)
3200 cfun->machine->indirect_branch_type = indirect_branch_keep;
3201 else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0)
3202 cfun->machine->indirect_branch_type = indirect_branch_thunk;
3203 else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0)
3204 cfun->machine->indirect_branch_type = indirect_branch_thunk_inline;
3205 else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0)
3206 cfun->machine->indirect_branch_type = indirect_branch_thunk_extern;
3207 else
3208 gcc_unreachable ();
3209 }
3210 else
3211 cfun->machine->indirect_branch_type = ix86_indirect_branch;
3212
3213 /* -mcmodel=large is not compatible with -mindirect-branch=thunk
3214 nor -mindirect-branch=thunk-extern. */
3215 if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
3216 && ((cfun->machine->indirect_branch_type
3217 == indirect_branch_thunk_extern)
3218 || (cfun->machine->indirect_branch_type
3219 == indirect_branch_thunk)))
3220 error ("%<-mindirect-branch=%s%> and %<-mcmodel=large%> are not "
3221 "compatible",
3222 ((cfun->machine->indirect_branch_type
3223 == indirect_branch_thunk_extern)
3224 ? "thunk-extern" : "thunk"));
3225
3226 if (cfun->machine->indirect_branch_type != indirect_branch_keep
3227 && (cfun->machine->indirect_branch_type
3228 != indirect_branch_thunk_extern)
3229 && (flag_cf_protection & CF_RETURN))
3230 error ("%<-mindirect-branch%> and %<-fcf-protection%> are not "
3231 "compatible");
3232 }
3233
3234 if (cfun->machine->function_return_type == indirect_branch_unset)
3235 {
3236 tree attr = lookup_attribute ("function_return",
3237 DECL_ATTRIBUTES (fndecl));
3238 if (attr != NULL)
3239 {
3240 tree args = TREE_VALUE (attr);
3241 if (args == NULL)
3242 gcc_unreachable ();
3243 tree cst = TREE_VALUE (args);
3244 if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0)
3245 cfun->machine->function_return_type = indirect_branch_keep;
3246 else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0)
3247 cfun->machine->function_return_type = indirect_branch_thunk;
3248 else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0)
3249 cfun->machine->function_return_type = indirect_branch_thunk_inline;
3250 else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0)
3251 cfun->machine->function_return_type = indirect_branch_thunk_extern;
3252 else
3253 gcc_unreachable ();
3254 }
3255 else
3256 cfun->machine->function_return_type = ix86_function_return;
3257
3258 /* -mcmodel=large is not compatible with -mfunction-return=thunk
3259 nor -mfunction-return=thunk-extern. */
3260 if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
3261 && ((cfun->machine->function_return_type
3262 == indirect_branch_thunk_extern)
3263 || (cfun->machine->function_return_type
3264 == indirect_branch_thunk)))
3265 error ("%<-mfunction-return=%s%> and %<-mcmodel=large%> are not "
3266 "compatible",
3267 ((cfun->machine->function_return_type
3268 == indirect_branch_thunk_extern)
3269 ? "thunk-extern" : "thunk"));
3270
3271 if (cfun->machine->function_return_type != indirect_branch_keep
3272 && (cfun->machine->function_return_type
3273 != indirect_branch_thunk_extern)
3274 && (flag_cf_protection & CF_RETURN))
3275 error ("%<-mfunction-return%> and %<-fcf-protection%> are not "
3276 "compatible");
3277 }
3278 }
3279
3280 /* Establish appropriate back-end context for processing the function
3281 FNDECL. The argument might be NULL to indicate processing at top
3282 level, outside of any function scope. */
3283 void
3284 ix86_set_current_function (tree fndecl)
3285 {
3286 /* Only change the context if the function changes. This hook is called
3287 several times in the course of compiling a function, and we don't want to
3288 slow things down too much or call target_reinit when it isn't safe. */
3289 if (fndecl == ix86_previous_fndecl)
3290 {
3291 /* There may be 2 function bodies for the same function FNDECL,
3292 one is extern inline and one isn't. Call ix86_set_func_type
3293 to set the func_type field. */
3294 if (fndecl != NULL_TREE)
3295 {
3296 ix86_set_func_type (fndecl);
3297 ix86_set_indirect_branch_type (fndecl);
3298 }
3299 return;
3300 }
3301
3302 tree old_tree;
3303 if (ix86_previous_fndecl == NULL_TREE)
3304 old_tree = target_option_current_node;
3305 else if (DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl))
3306 old_tree = DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl);
3307 else
3308 old_tree = target_option_default_node;
3309
3310 if (fndecl == NULL_TREE)
3311 {
3312 if (old_tree != target_option_current_node)
3313 ix86_reset_previous_fndecl ();
3314 return;
3315 }
3316
3317 ix86_set_func_type (fndecl);
3318 ix86_set_indirect_branch_type (fndecl);
3319
3320 tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
3321 if (new_tree == NULL_TREE)
3322 new_tree = target_option_default_node;
3323
3324 if (old_tree != new_tree)
3325 {
3326 cl_target_option_restore (&global_options, &global_options_set,
3327 TREE_TARGET_OPTION (new_tree));
3328 if (TREE_TARGET_GLOBALS (new_tree))
3329 restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
3330 else if (new_tree == target_option_default_node)
3331 restore_target_globals (&default_target_globals);
3332 else
3333 TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
3334 }
3335 else if (flag_unsafe_math_optimizations
3336 != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations
3337 || (flag_excess_precision
3338 != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision))
3339 {
3340 cl_target_option_restore (&global_options, &global_options_set,
3341 TREE_TARGET_OPTION (new_tree));
3342 ix86_excess_precision = flag_excess_precision;
3343 ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations;
3344 DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree
3345 = build_target_option_node (&global_options, &global_options_set);
3346 if (TREE_TARGET_GLOBALS (new_tree))
3347 restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
3348 else if (new_tree == target_option_default_node)
3349 restore_target_globals (&default_target_globals);
3350 else
3351 TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
3352 }
3353 ix86_previous_fndecl = fndecl;
3354
3355 static bool prev_no_caller_saved_registers;
3356
3357 /* 64-bit MS and SYSV ABI have different set of call used registers.
3358 Avoid expensive re-initialization of init_regs each time we switch
3359 function context. */
3360 if (TARGET_64BIT
3361 && (call_used_or_fixed_reg_p (SI_REG)
3362 == (cfun->machine->call_abi == MS_ABI)))
3363 reinit_regs ();
3364 /* Need to re-initialize init_regs if caller-saved registers are
3365 changed. */
3366 else if (prev_no_caller_saved_registers
3367 != cfun->machine->no_caller_saved_registers)
3368 reinit_regs ();
3369
3370 if (cfun->machine->func_type != TYPE_NORMAL
3371 || cfun->machine->no_caller_saved_registers)
3372 {
3373 /* Don't allow SSE, MMX nor x87 instructions since they
3374 may change processor state. */
3375 const char *isa;
3376 if (TARGET_SSE)
3377 isa = "SSE";
3378 else if (TARGET_MMX)
3379 isa = "MMX/3Dnow";
3380 else if (TARGET_80387)
3381 isa = "80387";
3382 else
3383 isa = NULL;
3384 if (isa != NULL)
3385 {
3386 if (cfun->machine->func_type != TYPE_NORMAL)
3387 sorry (cfun->machine->func_type == TYPE_EXCEPTION
3388 ? G_("%s instructions aren%'t allowed in an"
3389 " exception service routine")
3390 : G_("%s instructions aren%'t allowed in an"
3391 " interrupt service routine"),
3392 isa);
3393 else
3394 sorry ("%s instructions aren%'t allowed in a function with "
3395 "the %<no_caller_saved_registers%> attribute", isa);
3396 /* Don't issue the same error twice. */
3397 cfun->machine->func_type = TYPE_NORMAL;
3398 cfun->machine->no_caller_saved_registers = false;
3399 }
3400 }
3401
3402 prev_no_caller_saved_registers
3403 = cfun->machine->no_caller_saved_registers;
3404 }
3405
3406 /* Implement the TARGET_OFFLOAD_OPTIONS hook. */
3407 char *
3408 ix86_offload_options (void)
3409 {
3410 if (TARGET_LP64)
3411 return xstrdup ("-foffload-abi=lp64");
3412 return xstrdup ("-foffload-abi=ilp32");
3413 }
3414
3415 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
3416 and "sseregparm" calling convention attributes;
3417 arguments as in struct attribute_spec.handler. */
3418
3419 static tree
3420 ix86_handle_cconv_attribute (tree *node, tree name, tree args, int,
3421 bool *no_add_attrs)
3422 {
3423 if (TREE_CODE (*node) != FUNCTION_TYPE
3424 && TREE_CODE (*node) != METHOD_TYPE
3425 && TREE_CODE (*node) != FIELD_DECL
3426 && TREE_CODE (*node) != TYPE_DECL)
3427 {
3428 warning (OPT_Wattributes, "%qE attribute only applies to functions",
3429 name);
3430 *no_add_attrs = true;
3431 return NULL_TREE;
3432 }
3433
3434 /* Can combine regparm with all attributes but fastcall, and thiscall. */
3435 if (is_attribute_p ("regparm", name))
3436 {
3437 tree cst;
3438
3439 if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3440 {
3441 error ("fastcall and regparm attributes are not compatible");
3442 }
3443
3444 if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
3445 {
3446 error ("regparam and thiscall attributes are not compatible");
3447 }
3448
3449 cst = TREE_VALUE (args);
3450 if (TREE_CODE (cst) != INTEGER_CST)
3451 {
3452 warning (OPT_Wattributes,
3453 "%qE attribute requires an integer constant argument",
3454 name);
3455 *no_add_attrs = true;
3456 }
3457 else if (compare_tree_int (cst, REGPARM_MAX) > 0)
3458 {
3459 warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
3460 name, REGPARM_MAX);
3461 *no_add_attrs = true;
3462 }
3463
3464 return NULL_TREE;
3465 }
3466
3467 if (TARGET_64BIT)
3468 {
3469 /* Do not warn when emulating the MS ABI. */
3470 if ((TREE_CODE (*node) != FUNCTION_TYPE
3471 && TREE_CODE (*node) != METHOD_TYPE)
3472 || ix86_function_type_abi (*node) != MS_ABI)
3473 warning (OPT_Wattributes, "%qE attribute ignored",
3474 name);
3475 *no_add_attrs = true;
3476 return NULL_TREE;
3477 }
3478
3479 /* Can combine fastcall with stdcall (redundant) and sseregparm. */
3480 if (is_attribute_p ("fastcall", name))
3481 {
3482 if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
3483 {
3484 error ("fastcall and cdecl attributes are not compatible");
3485 }
3486 if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
3487 {
3488 error ("fastcall and stdcall attributes are not compatible");
3489 }
3490 if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
3491 {
3492 error ("fastcall and regparm attributes are not compatible");
3493 }
3494 if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
3495 {
3496 error ("fastcall and thiscall attributes are not compatible");
3497 }
3498 }
3499
3500 /* Can combine stdcall with fastcall (redundant), regparm and
3501 sseregparm. */
3502 else if (is_attribute_p ("stdcall", name))
3503 {
3504 if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
3505 {
3506 error ("stdcall and cdecl attributes are not compatible");
3507 }
3508 if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3509 {
3510 error ("stdcall and fastcall attributes are not compatible");
3511 }
3512 if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
3513 {
3514 error ("stdcall and thiscall attributes are not compatible");
3515 }
3516 }
3517
3518 /* Can combine cdecl with regparm and sseregparm. */
3519 else if (is_attribute_p ("cdecl", name))
3520 {
3521 if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
3522 {
3523 error ("stdcall and cdecl attributes are not compatible");
3524 }
3525 if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3526 {
3527 error ("fastcall and cdecl attributes are not compatible");
3528 }
3529 if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
3530 {
3531 error ("cdecl and thiscall attributes are not compatible");
3532 }
3533 }
3534 else if (is_attribute_p ("thiscall", name))
3535 {
3536 if (TREE_CODE (*node) != METHOD_TYPE && pedantic)
3537 warning (OPT_Wattributes, "%qE attribute is used for non-class method",
3538 name);
3539 if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
3540 {
3541 error ("stdcall and thiscall attributes are not compatible");
3542 }
3543 if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
3544 {
3545 error ("fastcall and thiscall attributes are not compatible");
3546 }
3547 if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
3548 {
3549 error ("cdecl and thiscall attributes are not compatible");
3550 }
3551 }
3552
3553 /* Can combine sseregparm with all attributes. */
3554
3555 return NULL_TREE;
3556 }
3557
3558 #ifndef CHECK_STACK_LIMIT
3559 #define CHECK_STACK_LIMIT (-1)
3560 #endif
3561
3562 /* The transactional memory builtins are implicitly regparm or fastcall
3563 depending on the ABI. Override the generic do-nothing attribute that
3564 these builtins were declared with, and replace it with one of the two
3565 attributes that we expect elsewhere. */
3566
3567 static tree
3568 ix86_handle_tm_regparm_attribute (tree *node, tree, tree,
3569 int flags, bool *no_add_attrs)
3570 {
3571 tree alt;
3572
3573 /* In no case do we want to add the placeholder attribute. */
3574 *no_add_attrs = true;
3575
3576 /* The 64-bit ABI is unchanged for transactional memory. */
3577 if (TARGET_64BIT)
3578 return NULL_TREE;
3579
3580 /* ??? Is there a better way to validate 32-bit windows? We have
3581 cfun->machine->call_abi, but that seems to be set only for 64-bit. */
3582 if (CHECK_STACK_LIMIT > 0)
3583 alt = tree_cons (get_identifier ("fastcall"), NULL, NULL);
3584 else
3585 {
3586 alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL);
3587 alt = tree_cons (get_identifier ("regparm"), alt, NULL);
3588 }
3589 decl_attributes (node, alt, flags);
3590
3591 return NULL_TREE;
3592 }
3593
3594 /* Handle a "force_align_arg_pointer" attribute. */
3595
3596 static tree
3597 ix86_handle_force_align_arg_pointer_attribute (tree *node, tree name,
3598 tree, int, bool *no_add_attrs)
3599 {
3600 if (TREE_CODE (*node) != FUNCTION_TYPE
3601 && TREE_CODE (*node) != METHOD_TYPE
3602 && TREE_CODE (*node) != FIELD_DECL
3603 && TREE_CODE (*node) != TYPE_DECL)
3604 {
3605 warning (OPT_Wattributes, "%qE attribute only applies to functions",
3606 name);
3607 *no_add_attrs = true;
3608 }
3609
3610 return NULL_TREE;
3611 }
3612
3613 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
3614 struct attribute_spec.handler. */
3615
3616 static tree
3617 ix86_handle_struct_attribute (tree *node, tree name, tree, int,
3618 bool *no_add_attrs)
3619 {
3620 tree *type = NULL;
3621 if (DECL_P (*node))
3622 {
3623 if (TREE_CODE (*node) == TYPE_DECL)
3624 type = &TREE_TYPE (*node);
3625 }
3626 else
3627 type = node;
3628
3629 if (!(type && RECORD_OR_UNION_TYPE_P (*type)))
3630 {
3631 warning (OPT_Wattributes, "%qE attribute ignored",
3632 name);
3633 *no_add_attrs = true;
3634 }
3635
3636 else if ((is_attribute_p ("ms_struct", name)
3637 && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
3638 || ((is_attribute_p ("gcc_struct", name)
3639 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
3640 {
3641 warning (OPT_Wattributes, "%qE incompatible attribute ignored",
3642 name);
3643 *no_add_attrs = true;
3644 }
3645
3646 return NULL_TREE;
3647 }
3648
3649 /* Handle a "callee_pop_aggregate_return" attribute; arguments as
3650 in struct attribute_spec handler. */
3651
3652 static tree
3653 ix86_handle_callee_pop_aggregate_return (tree *node, tree name, tree args, int,
3654 bool *no_add_attrs)
3655 {
3656 if (TREE_CODE (*node) != FUNCTION_TYPE
3657 && TREE_CODE (*node) != METHOD_TYPE
3658 && TREE_CODE (*node) != FIELD_DECL
3659 && TREE_CODE (*node) != TYPE_DECL)
3660 {
3661 warning (OPT_Wattributes, "%qE attribute only applies to functions",
3662 name);
3663 *no_add_attrs = true;
3664 return NULL_TREE;
3665 }
3666 if (TARGET_64BIT)
3667 {
3668 warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
3669 name);
3670 *no_add_attrs = true;
3671 return NULL_TREE;
3672 }
3673 if (is_attribute_p ("callee_pop_aggregate_return", name))
3674 {
3675 tree cst;
3676
3677 cst = TREE_VALUE (args);
3678 if (TREE_CODE (cst) != INTEGER_CST)
3679 {
3680 warning (OPT_Wattributes,
3681 "%qE attribute requires an integer constant argument",
3682 name);
3683 *no_add_attrs = true;
3684 }
3685 else if (compare_tree_int (cst, 0) != 0
3686 && compare_tree_int (cst, 1) != 0)
3687 {
3688 warning (OPT_Wattributes,
3689 "argument to %qE attribute is neither zero, nor one",
3690 name);
3691 *no_add_attrs = true;
3692 }
3693
3694 return NULL_TREE;
3695 }
3696
3697 return NULL_TREE;
3698 }
3699
3700 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
3701 struct attribute_spec.handler. */
3702
3703 static tree
3704 ix86_handle_abi_attribute (tree *node, tree name, tree, int,
3705 bool *no_add_attrs)
3706 {
3707 if (TREE_CODE (*node) != FUNCTION_TYPE
3708 && TREE_CODE (*node) != METHOD_TYPE
3709 && TREE_CODE (*node) != FIELD_DECL
3710 && TREE_CODE (*node) != TYPE_DECL)
3711 {
3712 warning (OPT_Wattributes, "%qE attribute only applies to functions",
3713 name);
3714 *no_add_attrs = true;
3715 return NULL_TREE;
3716 }
3717
3718 /* Can combine regparm with all attributes but fastcall. */
3719 if (is_attribute_p ("ms_abi", name))
3720 {
3721 if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
3722 {
3723 error ("%qs and %qs attributes are not compatible",
3724 "ms_abi", "sysv_abi");
3725 }
3726
3727 return NULL_TREE;
3728 }
3729 else if (is_attribute_p ("sysv_abi", name))
3730 {
3731 if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
3732 {
3733 error ("%qs and %qs attributes are not compatible",
3734 "ms_abi", "sysv_abi");
3735 }
3736
3737 return NULL_TREE;
3738 }
3739
3740 return NULL_TREE;
3741 }
3742
3743 static tree
3744 ix86_handle_fndecl_attribute (tree *node, tree name, tree args, int,
3745 bool *no_add_attrs)
3746 {
3747 if (TREE_CODE (*node) != FUNCTION_DECL)
3748 {
3749 warning (OPT_Wattributes, "%qE attribute only applies to functions",
3750 name);
3751 *no_add_attrs = true;
3752 }
3753
3754 if (is_attribute_p ("indirect_branch", name))
3755 {
3756 tree cst = TREE_VALUE (args);
3757 if (TREE_CODE (cst) != STRING_CST)
3758 {
3759 warning (OPT_Wattributes,
3760 "%qE attribute requires a string constant argument",
3761 name);
3762 *no_add_attrs = true;
3763 }
3764 else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0
3765 && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0
3766 && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0
3767 && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0)
3768 {
3769 warning (OPT_Wattributes,
3770 "argument to %qE attribute is not "
3771 "(keep|thunk|thunk-inline|thunk-extern)", name);
3772 *no_add_attrs = true;
3773 }
3774 }
3775
3776 if (is_attribute_p ("function_return", name))
3777 {
3778 tree cst = TREE_VALUE (args);
3779 if (TREE_CODE (cst) != STRING_CST)
3780 {
3781 warning (OPT_Wattributes,
3782 "%qE attribute requires a string constant argument",
3783 name);
3784 *no_add_attrs = true;
3785 }
3786 else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0
3787 && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0
3788 && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0
3789 && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0)
3790 {
3791 warning (OPT_Wattributes,
3792 "argument to %qE attribute is not "
3793 "(keep|thunk|thunk-inline|thunk-extern)", name);
3794 *no_add_attrs = true;
3795 }
3796 }
3797
3798 return NULL_TREE;
3799 }
3800
3801 static tree
3802 ix86_handle_no_caller_saved_registers_attribute (tree *, tree, tree,
3803 int, bool *)
3804 {
3805 return NULL_TREE;
3806 }
3807
3808 static tree
3809 ix86_handle_interrupt_attribute (tree *node, tree, tree, int, bool *)
3810 {
3811 /* DECL_RESULT and DECL_ARGUMENTS do not exist there yet,
3812 but the function type contains args and return type data. */
3813 tree func_type = *node;
3814 tree return_type = TREE_TYPE (func_type);
3815
3816 int nargs = 0;
3817 tree current_arg_type = TYPE_ARG_TYPES (func_type);
3818 while (current_arg_type
3819 && ! VOID_TYPE_P (TREE_VALUE (current_arg_type)))
3820 {
3821 if (nargs == 0)
3822 {
3823 if (! POINTER_TYPE_P (TREE_VALUE (current_arg_type)))
3824 error ("interrupt service routine should have a pointer "
3825 "as the first argument");
3826 }
3827 else if (nargs == 1)
3828 {
3829 if (TREE_CODE (TREE_VALUE (current_arg_type)) != INTEGER_TYPE
3830 || TYPE_MODE (TREE_VALUE (current_arg_type)) != word_mode)
3831 error ("interrupt service routine should have %qs "
3832 "as the second argument",
3833 TARGET_64BIT
3834 ? (TARGET_X32 ? "unsigned long long int"
3835 : "unsigned long int")
3836 : "unsigned int");
3837 }
3838 nargs++;
3839 current_arg_type = TREE_CHAIN (current_arg_type);
3840 }
3841 if (!nargs || nargs > 2)
3842 error ("interrupt service routine can only have a pointer argument "
3843 "and an optional integer argument");
3844 if (! VOID_TYPE_P (return_type))
3845 error ("interrupt service routine must return %<void%>");
3846
3847 return NULL_TREE;
3848 }
3849
3850 /* Handle fentry_name / fentry_section attribute. */
3851
3852 static tree
3853 ix86_handle_fentry_name (tree *node, tree name, tree args,
3854 int, bool *no_add_attrs)
3855 {
3856 if (TREE_CODE (*node) == FUNCTION_DECL
3857 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
3858 /* Do nothing else, just set the attribute. We'll get at
3859 it later with lookup_attribute. */
3860 ;
3861 else
3862 {
3863 warning (OPT_Wattributes, "%qE attribute ignored", name);
3864 *no_add_attrs = true;
3865 }
3866
3867 return NULL_TREE;
3868 }
3869
3870 /* Table of valid machine attributes. */
3871 const struct attribute_spec ix86_attribute_table[] =
3872 {
3873 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
3874 affects_type_identity, handler, exclude } */
3875 /* Stdcall attribute says callee is responsible for popping arguments
3876 if they are not variable. */
3877 { "stdcall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute,
3878 NULL },
3879 /* Fastcall attribute says callee is responsible for popping arguments
3880 if they are not variable. */
3881 { "fastcall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute,
3882 NULL },
3883 /* Thiscall attribute says callee is responsible for popping arguments
3884 if they are not variable. */
3885 { "thiscall", 0, 0, false, true, true, true, ix86_handle_cconv_attribute,
3886 NULL },
3887 /* Cdecl attribute says the callee is a normal C declaration */
3888 { "cdecl", 0, 0, false, true, true, true, ix86_handle_cconv_attribute,
3889 NULL },
3890 /* Regparm attribute specifies how many integer arguments are to be
3891 passed in registers. */
3892 { "regparm", 1, 1, false, true, true, true, ix86_handle_cconv_attribute,
3893 NULL },
3894 /* Sseregparm attribute says we are using x86_64 calling conventions
3895 for FP arguments. */
3896 { "sseregparm", 0, 0, false, true, true, true, ix86_handle_cconv_attribute,
3897 NULL },
3898 /* The transactional memory builtins are implicitly regparm or fastcall
3899 depending on the ABI. Override the generic do-nothing attribute that
3900 these builtins were declared with. */
3901 { "*tm regparm", 0, 0, false, true, true, true,
3902 ix86_handle_tm_regparm_attribute, NULL },
3903 /* force_align_arg_pointer says this function realigns the stack at entry. */
3904 { "force_align_arg_pointer", 0, 0,
3905 false, true, true, false, ix86_handle_force_align_arg_pointer_attribute,
3906 NULL },
3907 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3908 { "dllimport", 0, 0, false, false, false, false, handle_dll_attribute,
3909 NULL },
3910 { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute,
3911 NULL },
3912 { "shared", 0, 0, true, false, false, false,
3913 ix86_handle_shared_attribute, NULL },
3914 #endif
3915 { "ms_struct", 0, 0, false, false, false, false,
3916 ix86_handle_struct_attribute, NULL },
3917 { "gcc_struct", 0, 0, false, false, false, false,
3918 ix86_handle_struct_attribute, NULL },
3919 #ifdef SUBTARGET_ATTRIBUTE_TABLE
3920 SUBTARGET_ATTRIBUTE_TABLE,
3921 #endif
3922 /* ms_abi and sysv_abi calling convention function attributes. */
3923 { "ms_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute, NULL },
3924 { "sysv_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute,
3925 NULL },
3926 { "ms_abi va_list", 0, 0, false, false, false, false, NULL, NULL },
3927 { "sysv_abi va_list", 0, 0, false, false, false, false, NULL, NULL },
3928 { "ms_hook_prologue", 0, 0, true, false, false, false,
3929 ix86_handle_fndecl_attribute, NULL },
3930 { "callee_pop_aggregate_return", 1, 1, false, true, true, true,
3931 ix86_handle_callee_pop_aggregate_return, NULL },
3932 { "interrupt", 0, 0, false, true, true, false,
3933 ix86_handle_interrupt_attribute, NULL },
3934 { "no_caller_saved_registers", 0, 0, false, true, true, false,
3935 ix86_handle_no_caller_saved_registers_attribute, NULL },
3936 { "naked", 0, 0, true, false, false, false,
3937 ix86_handle_fndecl_attribute, NULL },
3938 { "indirect_branch", 1, 1, true, false, false, false,
3939 ix86_handle_fndecl_attribute, NULL },
3940 { "function_return", 1, 1, true, false, false, false,
3941 ix86_handle_fndecl_attribute, NULL },
3942 { "indirect_return", 0, 0, false, true, true, false,
3943 NULL, NULL },
3944 { "fentry_name", 1, 1, true, false, false, false,
3945 ix86_handle_fentry_name, NULL },
3946 { "fentry_section", 1, 1, true, false, false, false,
3947 ix86_handle_fentry_name, NULL },
3948 { "cf_check", 0, 0, true, false, false, false,
3949 ix86_handle_fndecl_attribute, NULL },
3950
3951 /* End element. */
3952 { NULL, 0, 0, false, false, false, false, NULL, NULL }
3953 };
3954
3955 #include "gt-i386-options.h"