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