Mercurial > hg > CbC > CbC_gcc
comparison gcc/config/spu/spu-c.c @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children | 58ad6c70ea60 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
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 #include "spu-builtins.h" | |
36 | |
37 | |
38 /* Keep the vector keywords handy for fast comparisons. */ | |
39 static GTY(()) tree __vector_keyword; | |
40 static GTY(()) tree vector_keyword; | |
41 | |
42 static cpp_hashnode * | |
43 spu_categorize_keyword (const cpp_token *tok) | |
44 { | |
45 if (tok->type == CPP_NAME) | |
46 { | |
47 cpp_hashnode *ident = tok->val.node; | |
48 | |
49 if (ident == C_CPP_HASHNODE (vector_keyword) | |
50 || ident == C_CPP_HASHNODE (__vector_keyword)) | |
51 return C_CPP_HASHNODE (__vector_keyword); | |
52 else | |
53 return ident; | |
54 } | |
55 return 0; | |
56 } | |
57 | |
58 /* Called to decide whether a conditional macro should be expanded. | |
59 Since we have exactly one such macro (i.e, 'vector'), we do not | |
60 need to examine the 'tok' parameter. */ | |
61 | |
62 static cpp_hashnode * | |
63 spu_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) | |
64 { | |
65 cpp_hashnode *expand_this = tok->val.node; | |
66 cpp_hashnode *ident; | |
67 | |
68 ident = spu_categorize_keyword (tok); | |
69 if (ident == C_CPP_HASHNODE (__vector_keyword)) | |
70 { | |
71 tok = cpp_peek_token (pfile, 0); | |
72 ident = spu_categorize_keyword (tok); | |
73 | |
74 if (ident) | |
75 { | |
76 enum rid rid_code = (enum rid)(ident->rid_code); | |
77 if (ident->type == NT_MACRO) | |
78 { | |
79 (void) cpp_get_token (pfile); | |
80 tok = cpp_peek_token (pfile, 0); | |
81 ident = spu_categorize_keyword (tok); | |
82 if (ident) | |
83 rid_code = (enum rid)(ident->rid_code); | |
84 } | |
85 | |
86 if (rid_code == RID_UNSIGNED || rid_code == RID_LONG | |
87 || rid_code == RID_SHORT || rid_code == RID_SIGNED | |
88 || rid_code == RID_INT || rid_code == RID_CHAR | |
89 || rid_code == RID_FLOAT || rid_code == RID_DOUBLE) | |
90 expand_this = C_CPP_HASHNODE (__vector_keyword); | |
91 } | |
92 } | |
93 return expand_this; | |
94 } | |
95 | |
96 /* target hook for resolve_overloaded_builtin(). Returns a function call | |
97 RTX if we can resolve the overloaded builtin */ | |
98 tree | |
99 spu_resolve_overloaded_builtin (tree fndecl, tree fnargs) | |
100 { | |
101 #define SCALAR_TYPE_P(t) (INTEGRAL_TYPE_P (t) \ | |
102 || SCALAR_FLOAT_TYPE_P (t) \ | |
103 || POINTER_TYPE_P (t)) | |
104 spu_function_code new_fcode, fcode = | |
105 DECL_FUNCTION_CODE (fndecl) - END_BUILTINS; | |
106 struct spu_builtin_description *desc; | |
107 tree match = NULL_TREE; | |
108 | |
109 /* The vector types are not available if the backend is not initialized. */ | |
110 gcc_assert (!flag_preprocess_only); | |
111 | |
112 desc = &spu_builtins[fcode]; | |
113 if (desc->type != B_OVERLOAD) | |
114 return NULL_TREE; | |
115 | |
116 /* Compare the signature of each internal builtin function with the | |
117 function arguments until a match is found. */ | |
118 | |
119 for (new_fcode = fcode + 1; spu_builtins[new_fcode].type == B_INTERNAL; | |
120 new_fcode++) | |
121 { | |
122 tree decl = spu_builtins[new_fcode].fndecl; | |
123 tree params = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
124 tree arg, param; | |
125 int p; | |
126 | |
127 for (param = params, arg = fnargs, p = 0; | |
128 param != void_list_node; | |
129 param = TREE_CHAIN (param), arg = TREE_CHAIN (arg), p++) | |
130 { | |
131 tree var, arg_type, param_type = TREE_VALUE (param); | |
132 | |
133 if (!arg) | |
134 { | |
135 error ("insufficient arguments to overloaded function %s", | |
136 desc->name); | |
137 return error_mark_node; | |
138 } | |
139 | |
140 var = TREE_VALUE (arg); | |
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) | |
158 || ((fcode == SPU_SPLATS || fcode == SPU_PROMOTE | |
159 || fcode == SPU_HCMPEQ || fcode == SPU_HCMPGT | |
160 || fcode == SPU_MASKB || fcode == SPU_MASKH | |
161 || fcode == SPU_MASKW) && p == 0)) | |
162 && !comptypes (TYPE_MAIN_VARIANT (param_type), | |
163 TYPE_MAIN_VARIANT (arg_type))) | |
164 break; | |
165 } | |
166 if (param == void_list_node) | |
167 { | |
168 if (arg) | |
169 { | |
170 error ("too many arguments to overloaded function %s", | |
171 desc->name); | |
172 return error_mark_node; | |
173 } | |
174 | |
175 match = decl; | |
176 break; | |
177 } | |
178 } | |
179 | |
180 if (match == NULL_TREE) | |
181 { | |
182 error ("parameter list does not match a valid signature for %s()", | |
183 desc->name); | |
184 return error_mark_node; | |
185 } | |
186 | |
187 return build_function_call (match, fnargs); | |
188 #undef SCALAR_TYPE_P | |
189 } | |
190 | |
191 | |
192 void | |
193 spu_cpu_cpp_builtins (struct cpp_reader *pfile) | |
194 { | |
195 builtin_define_std ("__SPU__"); | |
196 cpp_assert (pfile, "cpu=spu"); | |
197 cpp_assert (pfile, "machine=spu"); | |
198 if (spu_arch == PROCESSOR_CELLEDP) | |
199 builtin_define_std ("__SPU_EDP__"); | |
200 builtin_define_std ("__vector=__attribute__((__spu_vector__))"); | |
201 | |
202 if (!flag_iso) | |
203 { | |
204 /* Define this when supporting context-sensitive keywords. */ | |
205 cpp_define (pfile, "__VECTOR_KEYWORD_SUPPORTED__"); | |
206 cpp_define (pfile, "vector=vector"); | |
207 | |
208 /* Initialize vector keywords. */ | |
209 __vector_keyword = get_identifier ("__vector"); | |
210 C_CPP_HASHNODE (__vector_keyword)->flags |= NODE_CONDITIONAL; | |
211 vector_keyword = get_identifier ("vector"); | |
212 C_CPP_HASHNODE (vector_keyword)->flags |= NODE_CONDITIONAL; | |
213 | |
214 /* Enable context-sensitive macros. */ | |
215 cpp_get_callbacks (pfile)->macro_to_expand = spu_macro_to_expand; | |
216 } | |
217 } | |
218 | |
219 void | |
220 spu_c_common_override_options (void) | |
221 { | |
222 if (!TARGET_STD_MAIN) | |
223 { | |
224 /* Don't give warnings about the main() function. */ | |
225 warn_main = 0; | |
226 } | |
227 } |