Mercurial > hg > CbC > CbC_gcc
annotate gcc/config/spu/spu-c.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
rev | line source |
---|---|
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1 /* Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
0 | 2 |
3 This file is free software; you can redistribute it and/or modify it under | |
4 the terms of the GNU General Public License as published by the Free | |
5 Software Foundation; either version 3 of the License, or (at your option) | |
6 any later version. | |
7 | |
8 This file is distributed in the hope that it will be useful, but WITHOUT | |
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
11 for more details. | |
12 | |
13 You should have received a copy of the GNU General Public License | |
14 along with GCC; see the file COPYING3. If not see | |
15 <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include "config.h" | |
18 #include "system.h" | |
19 #include "coretypes.h" | |
20 #include "tm.h" | |
21 #include "cpplib.h" | |
22 #include "tree.h" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
23 #include "c-family/c-common.h" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
24 #include "c-family/c-pragma.h" |
0 | 25 #include "tm_p.h" |
26 #include "langhooks.h" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
27 #include "target.h" |
0 | 28 |
29 | |
30 /* Keep the vector keywords handy for fast comparisons. */ | |
31 static GTY(()) tree __vector_keyword; | |
32 static GTY(()) tree vector_keyword; | |
33 | |
34 static cpp_hashnode * | |
35 spu_categorize_keyword (const cpp_token *tok) | |
36 { | |
37 if (tok->type == CPP_NAME) | |
38 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
39 cpp_hashnode *ident = tok->val.node.node; |
0 | 40 |
41 if (ident == C_CPP_HASHNODE (vector_keyword) | |
42 || ident == C_CPP_HASHNODE (__vector_keyword)) | |
43 return C_CPP_HASHNODE (__vector_keyword); | |
44 else | |
45 return ident; | |
46 } | |
47 return 0; | |
48 } | |
49 | |
50 /* Called to decide whether a conditional macro should be expanded. | |
51 Since we have exactly one such macro (i.e, 'vector'), we do not | |
52 need to examine the 'tok' parameter. */ | |
53 | |
54 static cpp_hashnode * | |
55 spu_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) | |
56 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
57 cpp_hashnode *expand_this = tok->val.node.node; |
0 | 58 cpp_hashnode *ident; |
59 | |
60 ident = spu_categorize_keyword (tok); | |
61 if (ident == C_CPP_HASHNODE (__vector_keyword)) | |
62 { | |
63 tok = cpp_peek_token (pfile, 0); | |
64 ident = spu_categorize_keyword (tok); | |
65 | |
66 if (ident) | |
67 { | |
68 enum rid rid_code = (enum rid)(ident->rid_code); | |
69 if (ident->type == NT_MACRO) | |
70 { | |
71 (void) cpp_get_token (pfile); | |
72 tok = cpp_peek_token (pfile, 0); | |
73 ident = spu_categorize_keyword (tok); | |
74 if (ident) | |
75 rid_code = (enum rid)(ident->rid_code); | |
76 } | |
77 | |
78 if (rid_code == RID_UNSIGNED || rid_code == RID_LONG | |
79 || rid_code == RID_SHORT || rid_code == RID_SIGNED | |
80 || rid_code == RID_INT || rid_code == RID_CHAR | |
81 || rid_code == RID_FLOAT || rid_code == RID_DOUBLE) | |
82 expand_this = C_CPP_HASHNODE (__vector_keyword); | |
83 } | |
84 } | |
85 return expand_this; | |
86 } | |
87 | |
88 /* target hook for resolve_overloaded_builtin(). Returns a function call | |
89 RTX if we can resolve the overloaded builtin */ | |
90 tree | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
91 spu_resolve_overloaded_builtin (location_t loc, tree fndecl, void *passed_args) |
0 | 92 { |
93 #define SCALAR_TYPE_P(t) (INTEGRAL_TYPE_P (t) \ | |
94 || SCALAR_FLOAT_TYPE_P (t) \ | |
95 || POINTER_TYPE_P (t)) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
96 VEC(tree,gc) *fnargs = (VEC(tree,gc) *) passed_args; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
97 unsigned int nargs = VEC_length (tree, fnargs); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
98 int new_fcode, fcode = DECL_FUNCTION_CODE (fndecl); |
0 | 99 struct spu_builtin_description *desc; |
100 tree match = NULL_TREE; | |
101 | |
102 /* The vector types are not available if the backend is not initialized. */ | |
103 gcc_assert (!flag_preprocess_only); | |
104 | |
105 desc = &spu_builtins[fcode]; | |
106 if (desc->type != B_OVERLOAD) | |
107 return NULL_TREE; | |
108 | |
109 /* Compare the signature of each internal builtin function with the | |
110 function arguments until a match is found. */ | |
111 | |
112 for (new_fcode = fcode + 1; spu_builtins[new_fcode].type == B_INTERNAL; | |
113 new_fcode++) | |
114 { | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
115 tree decl = targetm.builtin_decl (new_fcode, true); |
0 | 116 tree params = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
117 tree param; |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
118 bool all_scalar; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
119 unsigned int p; |
0 | 120 |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
121 /* Check whether all parameters are scalar. */ |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
122 all_scalar = true; |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
123 for (param = params; param != void_list_node; param = TREE_CHAIN (param)) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
124 if (!SCALAR_TYPE_P (TREE_VALUE (param))) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
125 all_scalar = false; |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
126 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
127 for (param = params, p = 0; |
0 | 128 param != void_list_node; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
129 param = TREE_CHAIN (param), p++) |
0 | 130 { |
131 tree var, arg_type, param_type = TREE_VALUE (param); | |
132 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
133 if (p >= nargs) |
0 | 134 { |
135 error ("insufficient arguments to overloaded function %s", | |
136 desc->name); | |
137 return error_mark_node; | |
138 } | |
139 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
140 var = VEC_index (tree, fnargs, p); |
0 | 141 |
142 if (TREE_CODE (var) == NON_LVALUE_EXPR) | |
143 var = TREE_OPERAND (var, 0); | |
144 | |
145 if (TREE_CODE (var) == ERROR_MARK) | |
146 return NULL_TREE; /* Let somebody else deal with the problem. */ | |
147 | |
148 arg_type = TREE_TYPE (var); | |
149 | |
150 /* The intrinsics spec does not specify precisely how to | |
151 resolve generic intrinsics. We require an exact match | |
152 for vector types and let C do it's usual parameter type | |
153 checking/promotions for scalar arguments, except for the | |
154 first argument of intrinsics which don't have a vector | |
155 parameter. */ | |
156 if ((!SCALAR_TYPE_P (param_type) | |
157 || !SCALAR_TYPE_P (arg_type) | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
158 || (all_scalar && p == 0)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
159 && !lang_hooks.types_compatible_p (param_type, arg_type)) |
0 | 160 break; |
161 } | |
162 if (param == void_list_node) | |
163 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
164 if (p != nargs) |
0 | 165 { |
166 error ("too many arguments to overloaded function %s", | |
167 desc->name); | |
168 return error_mark_node; | |
169 } | |
170 | |
171 match = decl; | |
172 break; | |
173 } | |
174 } | |
175 | |
176 if (match == NULL_TREE) | |
177 { | |
178 error ("parameter list does not match a valid signature for %s()", | |
179 desc->name); | |
180 return error_mark_node; | |
181 } | |
182 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
183 return build_function_call_vec (loc, match, fnargs, NULL); |
0 | 184 #undef SCALAR_TYPE_P |
185 } | |
186 | |
187 | |
188 void | |
189 spu_cpu_cpp_builtins (struct cpp_reader *pfile) | |
190 { | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
191 cpp_define (pfile, "__SPU__"); |
0 | 192 cpp_assert (pfile, "cpu=spu"); |
193 cpp_assert (pfile, "machine=spu"); | |
194 if (spu_arch == PROCESSOR_CELLEDP) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
195 cpp_define (pfile, "__SPU_EDP__"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
196 cpp_define (pfile, "__vector=__attribute__((__spu_vector__))"); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
197 switch (spu_ea_model) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
198 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
199 case 32: |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
200 cpp_define (pfile, "__EA32__"); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
201 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
202 case 64: |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
203 cpp_define (pfile, "__EA64__"); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
204 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
205 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
206 gcc_unreachable (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
207 } |
0 | 208 |
209 if (!flag_iso) | |
210 { | |
211 /* Define this when supporting context-sensitive keywords. */ | |
212 cpp_define (pfile, "__VECTOR_KEYWORD_SUPPORTED__"); | |
213 cpp_define (pfile, "vector=vector"); | |
214 | |
215 /* Initialize vector keywords. */ | |
216 __vector_keyword = get_identifier ("__vector"); | |
217 C_CPP_HASHNODE (__vector_keyword)->flags |= NODE_CONDITIONAL; | |
218 vector_keyword = get_identifier ("vector"); | |
219 C_CPP_HASHNODE (vector_keyword)->flags |= NODE_CONDITIONAL; | |
220 | |
221 /* Enable context-sensitive macros. */ | |
222 cpp_get_callbacks (pfile)->macro_to_expand = spu_macro_to_expand; | |
223 } | |
224 } | |
225 | |
226 void | |
227 spu_c_common_override_options (void) | |
228 { | |
229 if (!TARGET_STD_MAIN) | |
230 { | |
231 /* Don't give warnings about the main() function. */ | |
232 warn_main = 0; | |
233 } | |
234 } |