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