Mercurial > hg > CbC > CbC_gcc
annotate gcc/config/i386/i386-c.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
rev | line source |
---|---|
0 | 1 /* Subroutines used for macro/preprocessor support on the ia-32. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2 Copyright (C) 2008, 2009 |
0 | 3 Free Software Foundation, Inc. |
4 | |
5 This file is part of GCC. | |
6 | |
7 GCC is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 3, or (at your option) | |
10 any later version. | |
11 | |
12 GCC is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GCC; see the file COPYING3. If not see | |
19 <http://www.gnu.org/licenses/>. */ | |
20 | |
21 #include "config.h" | |
22 #include "system.h" | |
23 #include "coretypes.h" | |
24 #include "tm.h" | |
25 #include "rtl.h" | |
26 #include "tree.h" | |
27 #include "tm_p.h" | |
28 #include "flags.h" | |
29 #include "c-common.h" | |
30 #include "ggc.h" | |
31 #include "target.h" | |
32 #include "target-def.h" | |
33 #include "cpplib.h" | |
34 #include "c-pragma.h" | |
35 | |
36 static bool ix86_pragma_target_parse (tree, tree); | |
37 static void ix86_target_macros_internal | |
38 (int, enum processor_type, enum processor_type, enum fpmath_unit, | |
39 void (*def_or_undef) (cpp_reader *, const char *)); | |
40 | |
41 | |
42 /* Internal function to either define or undef the appropriate system | |
43 macros. */ | |
44 static void | |
45 ix86_target_macros_internal (int isa_flag, | |
46 enum processor_type arch, | |
47 enum processor_type tune, | |
48 enum fpmath_unit fpmath, | |
49 void (*def_or_undef) (cpp_reader *, | |
50 const char *)) | |
51 { | |
52 /* For some of the k6/pentium varients there weren't seperate ISA bits to | |
53 identify which tune/arch flag was passed, so figure it out here. */ | |
54 size_t arch_len = strlen (ix86_arch_string); | |
55 size_t tune_len = strlen (ix86_tune_string); | |
56 int last_arch_char = ix86_arch_string[arch_len - 1]; | |
57 int last_tune_char = ix86_tune_string[tune_len - 1]; | |
58 | |
59 /* Built-ins based on -march=. */ | |
60 switch (arch) | |
61 { | |
62 case PROCESSOR_I386: | |
63 break; | |
64 case PROCESSOR_I486: | |
65 def_or_undef (parse_in, "__i486"); | |
66 def_or_undef (parse_in, "__i486__"); | |
67 break; | |
68 case PROCESSOR_PENTIUM: | |
69 def_or_undef (parse_in, "__i586"); | |
70 def_or_undef (parse_in, "__i586__"); | |
71 def_or_undef (parse_in, "__pentium"); | |
72 def_or_undef (parse_in, "__pentium__"); | |
73 if (isa_flag & OPTION_MASK_ISA_MMX) | |
74 def_or_undef (parse_in, "__pentium_mmx__"); | |
75 break; | |
76 case PROCESSOR_PENTIUMPRO: | |
77 def_or_undef (parse_in, "__i686"); | |
78 def_or_undef (parse_in, "__i686__"); | |
79 def_or_undef (parse_in, "__pentiumpro"); | |
80 def_or_undef (parse_in, "__pentiumpro__"); | |
81 break; | |
82 case PROCESSOR_GEODE: | |
83 def_or_undef (parse_in, "__geode"); | |
84 def_or_undef (parse_in, "__geode__"); | |
85 break; | |
86 case PROCESSOR_K6: | |
87 def_or_undef (parse_in, "__k6"); | |
88 def_or_undef (parse_in, "__k6__"); | |
89 if (last_arch_char == '2') | |
90 def_or_undef (parse_in, "__k6_2__"); | |
91 else if (last_arch_char == '3') | |
92 def_or_undef (parse_in, "__k6_3__"); | |
93 else if (isa_flag & OPTION_MASK_ISA_3DNOW) | |
94 def_or_undef (parse_in, "__k6_3__"); | |
95 break; | |
96 case PROCESSOR_ATHLON: | |
97 def_or_undef (parse_in, "__athlon"); | |
98 def_or_undef (parse_in, "__athlon__"); | |
99 if (isa_flag & OPTION_MASK_ISA_SSE) | |
100 def_or_undef (parse_in, "__athlon_sse__"); | |
101 break; | |
102 case PROCESSOR_K8: | |
103 def_or_undef (parse_in, "__k8"); | |
104 def_or_undef (parse_in, "__k8__"); | |
105 break; | |
106 case PROCESSOR_AMDFAM10: | |
107 def_or_undef (parse_in, "__amdfam10"); | |
108 def_or_undef (parse_in, "__amdfam10__"); | |
109 break; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
110 case PROCESSOR_BDVER1: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
111 def_or_undef (parse_in, "__bdver1"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
112 def_or_undef (parse_in, "__bdver1__"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
113 break; |
0 | 114 case PROCESSOR_PENTIUM4: |
115 def_or_undef (parse_in, "__pentium4"); | |
116 def_or_undef (parse_in, "__pentium4__"); | |
117 break; | |
118 case PROCESSOR_NOCONA: | |
119 def_or_undef (parse_in, "__nocona"); | |
120 def_or_undef (parse_in, "__nocona__"); | |
121 break; | |
122 case PROCESSOR_CORE2: | |
123 def_or_undef (parse_in, "__core2"); | |
124 def_or_undef (parse_in, "__core2__"); | |
125 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
126 case PROCESSOR_ATOM: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
127 def_or_undef (parse_in, "__atom"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
128 def_or_undef (parse_in, "__atom__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
129 break; |
0 | 130 /* use PROCESSOR_max to not set/unset the arch macro. */ |
131 case PROCESSOR_max: | |
132 break; | |
133 case PROCESSOR_GENERIC32: | |
134 case PROCESSOR_GENERIC64: | |
135 gcc_unreachable (); | |
136 } | |
137 | |
138 /* Built-ins based on -mtune=. */ | |
139 switch (tune) | |
140 { | |
141 case PROCESSOR_I386: | |
142 def_or_undef (parse_in, "__tune_i386__"); | |
143 break; | |
144 case PROCESSOR_I486: | |
145 def_or_undef (parse_in, "__tune_i486__"); | |
146 break; | |
147 case PROCESSOR_PENTIUM: | |
148 def_or_undef (parse_in, "__tune_i586__"); | |
149 def_or_undef (parse_in, "__tune_pentium__"); | |
150 if (last_tune_char == 'x') | |
151 def_or_undef (parse_in, "__tune_pentium_mmx__"); | |
152 break; | |
153 case PROCESSOR_PENTIUMPRO: | |
154 def_or_undef (parse_in, "__tune_i686__"); | |
155 def_or_undef (parse_in, "__tune_pentiumpro__"); | |
156 switch (last_tune_char) | |
157 { | |
158 case '3': | |
159 def_or_undef (parse_in, "__tune_pentium3__"); | |
160 /* FALLTHRU */ | |
161 case '2': | |
162 def_or_undef (parse_in, "__tune_pentium2__"); | |
163 break; | |
164 } | |
165 break; | |
166 case PROCESSOR_GEODE: | |
167 def_or_undef (parse_in, "__tune_geode__"); | |
168 break; | |
169 case PROCESSOR_K6: | |
170 def_or_undef (parse_in, "__tune_k6__"); | |
171 if (last_tune_char == '2') | |
172 def_or_undef (parse_in, "__tune_k6_2__"); | |
173 else if (last_tune_char == '3') | |
174 def_or_undef (parse_in, "__tune_k6_3__"); | |
175 else if (isa_flag & OPTION_MASK_ISA_3DNOW) | |
176 def_or_undef (parse_in, "__tune_k6_3__"); | |
177 break; | |
178 case PROCESSOR_ATHLON: | |
179 def_or_undef (parse_in, "__tune_athlon__"); | |
180 if (isa_flag & OPTION_MASK_ISA_SSE) | |
181 def_or_undef (parse_in, "__tune_athlon_sse__"); | |
182 break; | |
183 case PROCESSOR_K8: | |
184 def_or_undef (parse_in, "__tune_k8__"); | |
185 break; | |
186 case PROCESSOR_AMDFAM10: | |
187 def_or_undef (parse_in, "__tune_amdfam10__"); | |
188 break; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
189 case PROCESSOR_BDVER1: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
190 def_or_undef (parse_in, "__tune_bdver1__"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
191 break; |
0 | 192 case PROCESSOR_PENTIUM4: |
193 def_or_undef (parse_in, "__tune_pentium4__"); | |
194 break; | |
195 case PROCESSOR_NOCONA: | |
196 def_or_undef (parse_in, "__tune_nocona__"); | |
197 break; | |
198 case PROCESSOR_CORE2: | |
199 def_or_undef (parse_in, "__tune_core2__"); | |
200 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
201 case PROCESSOR_ATOM: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
202 def_or_undef (parse_in, "__tune_atom__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
203 break; |
0 | 204 case PROCESSOR_GENERIC32: |
205 case PROCESSOR_GENERIC64: | |
206 break; | |
207 /* use PROCESSOR_max to not set/unset the tune macro. */ | |
208 case PROCESSOR_max: | |
209 break; | |
210 } | |
211 | |
212 if (isa_flag & OPTION_MASK_ISA_MMX) | |
213 def_or_undef (parse_in, "__MMX__"); | |
214 if (isa_flag & OPTION_MASK_ISA_3DNOW) | |
215 def_or_undef (parse_in, "__3dNOW__"); | |
216 if (isa_flag & OPTION_MASK_ISA_3DNOW_A) | |
217 def_or_undef (parse_in, "__3dNOW_A__"); | |
218 if (isa_flag & OPTION_MASK_ISA_SSE) | |
219 def_or_undef (parse_in, "__SSE__"); | |
220 if (isa_flag & OPTION_MASK_ISA_SSE2) | |
221 def_or_undef (parse_in, "__SSE2__"); | |
222 if (isa_flag & OPTION_MASK_ISA_SSE3) | |
223 def_or_undef (parse_in, "__SSE3__"); | |
224 if (isa_flag & OPTION_MASK_ISA_SSSE3) | |
225 def_or_undef (parse_in, "__SSSE3__"); | |
226 if (isa_flag & OPTION_MASK_ISA_SSE4_1) | |
227 def_or_undef (parse_in, "__SSE4_1__"); | |
228 if (isa_flag & OPTION_MASK_ISA_SSE4_2) | |
229 def_or_undef (parse_in, "__SSE4_2__"); | |
230 if (isa_flag & OPTION_MASK_ISA_AES) | |
231 def_or_undef (parse_in, "__AES__"); | |
232 if (isa_flag & OPTION_MASK_ISA_PCLMUL) | |
233 def_or_undef (parse_in, "__PCLMUL__"); | |
234 if (isa_flag & OPTION_MASK_ISA_AVX) | |
235 def_or_undef (parse_in, "__AVX__"); | |
236 if (isa_flag & OPTION_MASK_ISA_FMA) | |
237 def_or_undef (parse_in, "__FMA__"); | |
238 if (isa_flag & OPTION_MASK_ISA_SSE4A) | |
239 def_or_undef (parse_in, "__SSE4A__"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
240 if (isa_flag & OPTION_MASK_ISA_FMA4) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
241 def_or_undef (parse_in, "__FMA4__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
242 if (isa_flag & OPTION_MASK_ISA_XOP) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
243 def_or_undef (parse_in, "__XOP__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
244 if (isa_flag & OPTION_MASK_ISA_LWP) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
245 def_or_undef (parse_in, "__LWP__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
246 if (isa_flag & OPTION_MASK_ISA_ABM) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
247 def_or_undef (parse_in, "__ABM__"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
248 if (isa_flag & OPTION_MASK_ISA_POPCNT) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
249 def_or_undef (parse_in, "__POPCNT__"); |
0 | 250 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE)) |
251 def_or_undef (parse_in, "__SSE_MATH__"); | |
252 if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2)) | |
253 def_or_undef (parse_in, "__SSE2_MATH__"); | |
254 } | |
255 | |
256 | |
257 /* Hook to validate the current #pragma GCC target and set the state, and | |
258 update the macros based on what was changed. If ARGS is NULL, then | |
259 POP_TARGET is used to reset the options. */ | |
260 | |
261 static bool | |
262 ix86_pragma_target_parse (tree args, tree pop_target) | |
263 { | |
264 tree prev_tree = build_target_option_node (); | |
265 tree cur_tree; | |
266 struct cl_target_option *prev_opt; | |
267 struct cl_target_option *cur_opt; | |
268 int prev_isa; | |
269 int cur_isa; | |
270 int diff_isa; | |
271 enum processor_type prev_arch; | |
272 enum processor_type prev_tune; | |
273 enum processor_type cur_arch; | |
274 enum processor_type cur_tune; | |
275 | |
276 if (! args) | |
277 { | |
278 cur_tree = ((pop_target) | |
279 ? pop_target | |
280 : target_option_default_node); | |
281 cl_target_option_restore (TREE_TARGET_OPTION (cur_tree)); | |
282 } | |
283 else | |
284 { | |
285 cur_tree = ix86_valid_target_attribute_tree (args); | |
286 if (!cur_tree) | |
287 return false; | |
288 } | |
289 | |
290 target_option_current_node = cur_tree; | |
291 | |
292 /* Figure out the previous/current isa, arch, tune and the differences. */ | |
293 prev_opt = TREE_TARGET_OPTION (prev_tree); | |
294 cur_opt = TREE_TARGET_OPTION (cur_tree); | |
295 prev_isa = prev_opt->ix86_isa_flags; | |
296 cur_isa = cur_opt->ix86_isa_flags; | |
297 diff_isa = (prev_isa ^ cur_isa); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
298 prev_arch = (enum processor_type) prev_opt->arch; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
299 prev_tune = (enum processor_type) prev_opt->tune; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
300 cur_arch = (enum processor_type) cur_opt->arch; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
301 cur_tune = (enum processor_type) cur_opt->tune; |
0 | 302 |
303 /* If the same processor is used for both previous and current options, don't | |
304 change the macros. */ | |
305 if (cur_arch == prev_arch) | |
306 cur_arch = prev_arch = PROCESSOR_max; | |
307 | |
308 if (cur_tune == prev_tune) | |
309 cur_tune = prev_tune = PROCESSOR_max; | |
310 | |
311 /* Undef all of the macros for that are no longer current. */ | |
312 ix86_target_macros_internal (prev_isa & diff_isa, | |
313 prev_arch, | |
314 prev_tune, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
315 (enum fpmath_unit) prev_opt->fpmath, |
0 | 316 cpp_undef); |
317 | |
318 /* Define all of the macros for new options that were just turned on. */ | |
319 ix86_target_macros_internal (cur_isa & diff_isa, | |
320 cur_arch, | |
321 cur_tune, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
322 (enum fpmath_unit) cur_opt->fpmath, |
0 | 323 cpp_define); |
324 | |
325 return true; | |
326 } | |
327 | |
328 /* Function to tell the preprocessor about the defines for the current target. */ | |
329 | |
330 void | |
331 ix86_target_macros (void) | |
332 { | |
333 /* 32/64-bit won't change with target specific options, so do the assert and | |
334 builtin_define_std calls here. */ | |
335 if (TARGET_64BIT) | |
336 { | |
337 cpp_assert (parse_in, "cpu=x86_64"); | |
338 cpp_assert (parse_in, "machine=x86_64"); | |
339 cpp_define (parse_in, "__amd64"); | |
340 cpp_define (parse_in, "__amd64__"); | |
341 cpp_define (parse_in, "__x86_64"); | |
342 cpp_define (parse_in, "__x86_64__"); | |
343 } | |
344 else | |
345 { | |
346 cpp_assert (parse_in, "cpu=i386"); | |
347 cpp_assert (parse_in, "machine=i386"); | |
348 builtin_define_std ("i386"); | |
349 } | |
350 | |
351 ix86_target_macros_internal (ix86_isa_flags, | |
352 ix86_arch, | |
353 ix86_tune, | |
354 ix86_fpmath, | |
355 cpp_define); | |
356 } | |
357 | |
358 | |
359 /* Register target pragmas. We need to add the hook for parsing #pragma GCC | |
360 option here rather than in i386.c since it will pull in various preprocessor | |
361 functions, and those are not present in languages like fortran without a | |
362 preprocessor. */ | |
363 | |
364 void | |
365 ix86_register_pragmas (void) | |
366 { | |
367 /* Update pragma hook to allow parsing #pragma GCC target. */ | |
368 targetm.target_option.pragma_parse = ix86_pragma_target_parse; | |
369 | |
370 #ifdef REGISTER_SUBTARGET_PRAGMAS | |
371 REGISTER_SUBTARGET_PRAGMAS (); | |
372 #endif | |
373 } |