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