]>
Commit | Line | Data |
---|---|---|
d353bf18 | 1 | /* Copyright (C) 2006-2015 Free Software Foundation, Inc. |
644459d0 | 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 | |
038d1e19 | 5 | Software Foundation; either version 3 of the License, or (at your option) |
644459d0 | 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 | |
038d1e19 | 14 | along with GCC; see the file COPYING3. If not see |
15 | <http://www.gnu.org/licenses/>. */ | |
644459d0 | 16 | |
17 | #include "config.h" | |
18 | #include "system.h" | |
19 | #include "coretypes.h" | |
20 | #include "tm.h" | |
21 | #include "cpplib.h" | |
b20a8bb4 | 22 | #include "hash-set.h" |
b20a8bb4 | 23 | #include "vec.h" |
b20a8bb4 | 24 | #include "input.h" |
25 | #include "alias.h" | |
26 | #include "symtab.h" | |
b20a8bb4 | 27 | #include "inchash.h" |
644459d0 | 28 | #include "tree.h" |
9ed99284 | 29 | #include "stringpool.h" |
7bedc3a0 | 30 | #include "c-family/c-common.h" |
31 | #include "c-family/c-pragma.h" | |
644459d0 | 32 | #include "tm_p.h" |
33 | #include "langhooks.h" | |
0c5c4d59 | 34 | #include "target.h" |
644459d0 | 35 | \f |
36 | ||
f952c224 | 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 | { | |
897ffbb0 | 46 | cpp_hashnode *ident = tok->val.node.node; |
f952c224 | 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 | { | |
897ffbb0 | 64 | cpp_hashnode *expand_this = tok->val.node.node; |
f952c224 | 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 | ||
644459d0 | 95 | /* target hook for resolve_overloaded_builtin(). Returns a function call |
96 | RTX if we can resolve the overloaded builtin */ | |
97 | tree | |
54e46243 | 98 | spu_resolve_overloaded_builtin (location_t loc, tree fndecl, void *passed_args) |
644459d0 | 99 | { |
828ce6b1 | 100 | #define SCALAR_TYPE_P(t) (INTEGRAL_TYPE_P (t) \ |
101 | || SCALAR_FLOAT_TYPE_P (t) \ | |
102 | || POINTER_TYPE_P (t)) | |
f1f41a6c | 103 | vec<tree, va_gc> *fnargs = static_cast <vec<tree, va_gc> *> (passed_args); |
104 | unsigned int nargs = vec_safe_length (fnargs); | |
3726fe5e | 105 | int new_fcode, fcode = DECL_FUNCTION_CODE (fndecl); |
644459d0 | 106 | struct spu_builtin_description *desc; |
107 | tree match = NULL_TREE; | |
108 | ||
fa7637bd | 109 | /* The vector types are not available if the backend is not initialized. */ |
644459d0 | 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 | { | |
0c5c4d59 | 122 | tree decl = targetm.builtin_decl (new_fcode, true); |
644459d0 | 123 | tree params = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
b9c74b4d | 124 | tree param; |
c2233b46 | 125 | bool all_scalar; |
b9c74b4d | 126 | unsigned int p; |
644459d0 | 127 | |
c2233b46 | 128 | /* Check whether all parameters are scalar. */ |
129 | all_scalar = true; | |
130 | for (param = params; param != void_list_node; param = TREE_CHAIN (param)) | |
131 | if (!SCALAR_TYPE_P (TREE_VALUE (param))) | |
132 | all_scalar = false; | |
133 | ||
b9c74b4d | 134 | for (param = params, p = 0; |
644459d0 | 135 | param != void_list_node; |
b9c74b4d | 136 | param = TREE_CHAIN (param), p++) |
644459d0 | 137 | { |
138 | tree var, arg_type, param_type = TREE_VALUE (param); | |
139 | ||
da84efc1 | 140 | if (p >= nargs) |
644459d0 | 141 | { |
142 | error ("insufficient arguments to overloaded function %s", | |
143 | desc->name); | |
144 | return error_mark_node; | |
145 | } | |
146 | ||
f1f41a6c | 147 | var = (*fnargs)[p]; |
644459d0 | 148 | |
149 | if (TREE_CODE (var) == NON_LVALUE_EXPR) | |
150 | var = TREE_OPERAND (var, 0); | |
151 | ||
152 | if (TREE_CODE (var) == ERROR_MARK) | |
153 | return NULL_TREE; /* Let somebody else deal with the problem. */ | |
154 | ||
155 | arg_type = TREE_TYPE (var); | |
156 | ||
157 | /* The intrinsics spec does not specify precisely how to | |
158 | resolve generic intrinsics. We require an exact match | |
159 | for vector types and let C do it's usual parameter type | |
160 | checking/promotions for scalar arguments, except for the | |
161 | first argument of intrinsics which don't have a vector | |
162 | parameter. */ | |
828ce6b1 | 163 | if ((!SCALAR_TYPE_P (param_type) |
164 | || !SCALAR_TYPE_P (arg_type) | |
c2233b46 | 165 | || (all_scalar && p == 0)) |
e8a6252b | 166 | && !lang_hooks.types_compatible_p (param_type, arg_type)) |
644459d0 | 167 | break; |
168 | } | |
169 | if (param == void_list_node) | |
170 | { | |
b9c74b4d | 171 | if (p != nargs) |
644459d0 | 172 | { |
173 | error ("too many arguments to overloaded function %s", | |
174 | desc->name); | |
175 | return error_mark_node; | |
176 | } | |
177 | ||
178 | match = decl; | |
179 | break; | |
180 | } | |
181 | } | |
182 | ||
183 | if (match == NULL_TREE) | |
184 | { | |
185 | error ("parameter list does not match a valid signature for %s()", | |
186 | desc->name); | |
187 | return error_mark_node; | |
188 | } | |
189 | ||
7eba0028 | 190 | return build_function_call_vec (loc, vNULL, match, fnargs, NULL); |
828ce6b1 | 191 | #undef SCALAR_TYPE_P |
644459d0 | 192 | } |
193 | ||
644459d0 | 194 | |
6352eedf | 195 | void |
196 | spu_cpu_cpp_builtins (struct cpp_reader *pfile) | |
644459d0 | 197 | { |
ea130120 | 198 | cpp_define (pfile, "__SPU__"); |
6352eedf | 199 | cpp_assert (pfile, "cpu=spu"); |
200 | cpp_assert (pfile, "machine=spu"); | |
5474166e | 201 | if (spu_arch == PROCESSOR_CELLEDP) |
ea130120 | 202 | cpp_define (pfile, "__SPU_EDP__"); |
c378948c | 203 | if (cpp_get_options (pfile)->lang != CLK_ASM) |
204 | cpp_define (pfile, "__vector=__attribute__((__spu_vector__))"); | |
6cf5579e | 205 | switch (spu_ea_model) |
206 | { | |
207 | case 32: | |
ea130120 | 208 | cpp_define (pfile, "__EA32__"); |
6cf5579e | 209 | break; |
210 | case 64: | |
ea130120 | 211 | cpp_define (pfile, "__EA64__"); |
6cf5579e | 212 | break; |
213 | default: | |
214 | gcc_unreachable (); | |
215 | } | |
f952c224 | 216 | |
c378948c | 217 | if (!flag_iso && cpp_get_options (pfile)->lang != CLK_ASM) |
f952c224 | 218 | { |
219 | /* Define this when supporting context-sensitive keywords. */ | |
220 | cpp_define (pfile, "__VECTOR_KEYWORD_SUPPORTED__"); | |
221 | cpp_define (pfile, "vector=vector"); | |
222 | ||
223 | /* Initialize vector keywords. */ | |
224 | __vector_keyword = get_identifier ("__vector"); | |
225 | C_CPP_HASHNODE (__vector_keyword)->flags |= NODE_CONDITIONAL; | |
226 | vector_keyword = get_identifier ("vector"); | |
227 | C_CPP_HASHNODE (vector_keyword)->flags |= NODE_CONDITIONAL; | |
228 | ||
229 | /* Enable context-sensitive macros. */ | |
230 | cpp_get_callbacks (pfile)->macro_to_expand = spu_macro_to_expand; | |
231 | } | |
644459d0 | 232 | } |
233 | ||
8ddfcaa9 | 234 | void |
235 | spu_c_common_override_options (void) | |
236 | { | |
237 | if (!TARGET_STD_MAIN) | |
238 | { | |
239 | /* Don't give warnings about the main() function. */ | |
240 | warn_main = 0; | |
241 | } | |
242 | } |