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