Mercurial > hg > CbC > CbC_gcc
annotate gcc/config/spu/spu-c.c @ 19:58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
author | kent@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 24 Sep 2009 13:21:57 +0900 |
parents | a06113de4d67 |
children | 77e2b8dfacca |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. |
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" | |
23 #include "c-tree.h" | |
24 #include "c-pragma.h" | |
25 #include "function.h" | |
26 #include "rtl.h" | |
27 #include "expr.h" | |
28 #include "errors.h" | |
29 #include "tm_p.h" | |
30 #include "langhooks.h" | |
31 #include "insn-config.h" | |
32 #include "insn-codes.h" | |
33 #include "recog.h" | |
34 #include "optabs.h" | |
35 | |
36 | |
37 /* Keep the vector keywords handy for fast comparisons. */ | |
38 static GTY(()) tree __vector_keyword; | |
39 static GTY(()) tree vector_keyword; | |
40 | |
41 static cpp_hashnode * | |
42 spu_categorize_keyword (const cpp_token *tok) | |
43 { | |
44 if (tok->type == CPP_NAME) | |
45 { | |
46 cpp_hashnode *ident = tok->val.node; | |
47 | |
48 if (ident == C_CPP_HASHNODE (vector_keyword) | |
49 || ident == C_CPP_HASHNODE (__vector_keyword)) | |
50 return C_CPP_HASHNODE (__vector_keyword); | |
51 else | |
52 return ident; | |
53 } | |
54 return 0; | |
55 } | |
56 | |
57 /* Called to decide whether a conditional macro should be expanded. | |
58 Since we have exactly one such macro (i.e, 'vector'), we do not | |
59 need to examine the 'tok' parameter. */ | |
60 | |
61 static cpp_hashnode * | |
62 spu_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) | |
63 { | |
64 cpp_hashnode *expand_this = tok->val.node; | |
65 cpp_hashnode *ident; | |
66 | |
67 ident = spu_categorize_keyword (tok); | |
68 if (ident == C_CPP_HASHNODE (__vector_keyword)) | |
69 { | |
70 tok = cpp_peek_token (pfile, 0); | |
71 ident = spu_categorize_keyword (tok); | |
72 | |
73 if (ident) | |
74 { | |
75 enum rid rid_code = (enum rid)(ident->rid_code); | |
76 if (ident->type == NT_MACRO) | |
77 { | |
78 (void) cpp_get_token (pfile); | |
79 tok = cpp_peek_token (pfile, 0); | |
80 ident = spu_categorize_keyword (tok); | |
81 if (ident) | |
82 rid_code = (enum rid)(ident->rid_code); | |
83 } | |
84 | |
85 if (rid_code == RID_UNSIGNED || rid_code == RID_LONG | |
86 || rid_code == RID_SHORT || rid_code == RID_SIGNED | |
87 || rid_code == RID_INT || rid_code == RID_CHAR | |
88 || rid_code == RID_FLOAT || rid_code == RID_DOUBLE) | |
89 expand_this = C_CPP_HASHNODE (__vector_keyword); | |
90 } | |
91 } | |
92 return expand_this; | |
93 } | |
94 | |
95 /* target hook for resolve_overloaded_builtin(). Returns a function call | |
96 RTX if we can resolve the overloaded builtin */ | |
97 tree | |
98 spu_resolve_overloaded_builtin (tree fndecl, tree fnargs) | |
99 { | |
100 #define SCALAR_TYPE_P(t) (INTEGRAL_TYPE_P (t) \ | |
101 || SCALAR_FLOAT_TYPE_P (t) \ | |
102 || POINTER_TYPE_P (t)) | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
103 int new_fcode, fcode = DECL_FUNCTION_CODE (fndecl) - END_BUILTINS; |
0 | 104 struct spu_builtin_description *desc; |
105 tree match = NULL_TREE; | |
106 | |
107 /* The vector types are not available if the backend is not initialized. */ | |
108 gcc_assert (!flag_preprocess_only); | |
109 | |
110 desc = &spu_builtins[fcode]; | |
111 if (desc->type != B_OVERLOAD) | |
112 return NULL_TREE; | |
113 | |
114 /* Compare the signature of each internal builtin function with the | |
115 function arguments until a match is found. */ | |
116 | |
117 for (new_fcode = fcode + 1; spu_builtins[new_fcode].type == B_INTERNAL; | |
118 new_fcode++) | |
119 { | |
120 tree decl = spu_builtins[new_fcode].fndecl; | |
121 tree params = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
122 tree arg, 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
|
123 bool all_scalar; |
0 | 124 int p; |
125 | |
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 /* 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
|
127 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
|
128 for (param = params; param != void_list_node; param = TREE_CHAIN (param)) |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
129 if (!SCALAR_TYPE_P (TREE_VALUE (param))) |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
130 all_scalar = false; |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
131 |
0 | 132 for (param = params, arg = fnargs, p = 0; |
133 param != void_list_node; | |
134 param = TREE_CHAIN (param), arg = TREE_CHAIN (arg), p++) | |
135 { | |
136 tree var, arg_type, param_type = TREE_VALUE (param); | |
137 | |
138 if (!arg) | |
139 { | |
140 error ("insufficient arguments to overloaded function %s", | |
141 desc->name); | |
142 return error_mark_node; | |
143 } | |
144 | |
145 var = TREE_VALUE (arg); | |
146 | |
147 if (TREE_CODE (var) == NON_LVALUE_EXPR) | |
148 var = TREE_OPERAND (var, 0); | |
149 | |
150 if (TREE_CODE (var) == ERROR_MARK) | |
151 return NULL_TREE; /* Let somebody else deal with the problem. */ | |
152 | |
153 arg_type = TREE_TYPE (var); | |
154 | |
155 /* The intrinsics spec does not specify precisely how to | |
156 resolve generic intrinsics. We require an exact match | |
157 for vector types and let C do it's usual parameter type | |
158 checking/promotions for scalar arguments, except for the | |
159 first argument of intrinsics which don't have a vector | |
160 parameter. */ | |
161 if ((!SCALAR_TYPE_P (param_type) | |
162 || !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
|
163 || (all_scalar && p == 0)) |
0 | 164 && !comptypes (TYPE_MAIN_VARIANT (param_type), |
165 TYPE_MAIN_VARIANT (arg_type))) | |
166 break; | |
167 } | |
168 if (param == void_list_node) | |
169 { | |
170 if (arg) | |
171 { | |
172 error ("too many arguments to overloaded function %s", | |
173 desc->name); | |
174 return error_mark_node; | |
175 } | |
176 | |
177 match = decl; | |
178 break; | |
179 } | |
180 } | |
181 | |
182 if (match == NULL_TREE) | |
183 { | |
184 error ("parameter list does not match a valid signature for %s()", | |
185 desc->name); | |
186 return error_mark_node; | |
187 } | |
188 | |
189 return build_function_call (match, fnargs); | |
190 #undef SCALAR_TYPE_P | |
191 } | |
192 | |
193 | |
194 void | |
195 spu_cpu_cpp_builtins (struct cpp_reader *pfile) | |
196 { | |
197 builtin_define_std ("__SPU__"); | |
198 cpp_assert (pfile, "cpu=spu"); | |
199 cpp_assert (pfile, "machine=spu"); | |
200 if (spu_arch == PROCESSOR_CELLEDP) | |
201 builtin_define_std ("__SPU_EDP__"); | |
202 builtin_define_std ("__vector=__attribute__((__spu_vector__))"); | |
203 | |
204 if (!flag_iso) | |
205 { | |
206 /* Define this when supporting context-sensitive keywords. */ | |
207 cpp_define (pfile, "__VECTOR_KEYWORD_SUPPORTED__"); | |
208 cpp_define (pfile, "vector=vector"); | |
209 | |
210 /* Initialize vector keywords. */ | |
211 __vector_keyword = get_identifier ("__vector"); | |
212 C_CPP_HASHNODE (__vector_keyword)->flags |= NODE_CONDITIONAL; | |
213 vector_keyword = get_identifier ("vector"); | |
214 C_CPP_HASHNODE (vector_keyword)->flags |= NODE_CONDITIONAL; | |
215 | |
216 /* Enable context-sensitive macros. */ | |
217 cpp_get_callbacks (pfile)->macro_to_expand = spu_macro_to_expand; | |
218 } | |
219 } | |
220 | |
221 void | |
222 spu_c_common_override_options (void) | |
223 { | |
224 if (!TARGET_STD_MAIN) | |
225 { | |
226 /* Don't give warnings about the main() function. */ | |
227 warn_main = 0; | |
228 } | |
229 } |