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