Debian Codegraph @

gcc/config/i386/i386-options.cc

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