comparison gcc/config/i386/i386-options.c @ 145:1830386684a0

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