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