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