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