1 /* Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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)
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
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/>. */
19 #include "coretypes.h"
23 #include "c-family/c-common.h"
24 #include "c-family/c-pragma.h"
26 #include "langhooks.h"
29 /* Keep the vector keywords handy for fast comparisons. */
30 static GTY(()) tree __vector_keyword
;
31 static GTY(()) tree vector_keyword
;
34 spu_categorize_keyword (const cpp_token
*tok
)
36 if (tok
->type
== CPP_NAME
)
38 cpp_hashnode
*ident
= tok
->val
.node
.node
;
40 if (ident
== C_CPP_HASHNODE (vector_keyword
)
41 || ident
== C_CPP_HASHNODE (__vector_keyword
))
42 return C_CPP_HASHNODE (__vector_keyword
);
49 /* Called to decide whether a conditional macro should be expanded.
50 Since we have exactly one such macro (i.e, 'vector'), we do not
51 need to examine the 'tok' parameter. */
54 spu_macro_to_expand (cpp_reader
*pfile
, const cpp_token
*tok
)
56 cpp_hashnode
*expand_this
= tok
->val
.node
.node
;
59 ident
= spu_categorize_keyword (tok
);
60 if (ident
== C_CPP_HASHNODE (__vector_keyword
))
62 tok
= cpp_peek_token (pfile
, 0);
63 ident
= spu_categorize_keyword (tok
);
67 enum rid rid_code
= (enum rid
)(ident
->rid_code
);
68 if (ident
->type
== NT_MACRO
)
70 (void) cpp_get_token (pfile
);
71 tok
= cpp_peek_token (pfile
, 0);
72 ident
= spu_categorize_keyword (tok
);
74 rid_code
= (enum rid
)(ident
->rid_code
);
77 if (rid_code
== RID_UNSIGNED
|| rid_code
== RID_LONG
78 || rid_code
== RID_SHORT
|| rid_code
== RID_SIGNED
79 || rid_code
== RID_INT
|| rid_code
== RID_CHAR
80 || rid_code
== RID_FLOAT
|| rid_code
== RID_DOUBLE
)
81 expand_this
= C_CPP_HASHNODE (__vector_keyword
);
87 /* target hook for resolve_overloaded_builtin(). Returns a function call
88 RTX if we can resolve the overloaded builtin */
90 spu_resolve_overloaded_builtin (location_t loc
, tree fndecl
, void *passed_args
)
92 #define SCALAR_TYPE_P(t) (INTEGRAL_TYPE_P (t) \
93 || SCALAR_FLOAT_TYPE_P (t) \
94 || POINTER_TYPE_P (t))
95 VEC(tree
,gc
) *fnargs
= (VEC(tree
,gc
) *) passed_args
;
96 unsigned int nargs
= VEC_length (tree
, fnargs
);
97 int new_fcode
, fcode
= DECL_FUNCTION_CODE (fndecl
) - END_BUILTINS
;
98 struct spu_builtin_description
*desc
;
99 tree match
= NULL_TREE
;
101 /* The vector types are not available if the backend is not initialized. */
102 gcc_assert (!flag_preprocess_only
);
104 desc
= &spu_builtins
[fcode
];
105 if (desc
->type
!= B_OVERLOAD
)
108 /* Compare the signature of each internal builtin function with the
109 function arguments until a match is found. */
111 for (new_fcode
= fcode
+ 1; spu_builtins
[new_fcode
].type
== B_INTERNAL
;
114 tree decl
= spu_builtins
[new_fcode
].fndecl
;
115 tree params
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
120 /* Check whether all parameters are scalar. */
122 for (param
= params
; param
!= void_list_node
; param
= TREE_CHAIN (param
))
123 if (!SCALAR_TYPE_P (TREE_VALUE (param
)))
126 for (param
= params
, p
= 0;
127 param
!= void_list_node
;
128 param
= TREE_CHAIN (param
), p
++)
130 tree var
, arg_type
, param_type
= TREE_VALUE (param
);
134 error ("insufficient arguments to overloaded function %s",
136 return error_mark_node
;
139 var
= VEC_index (tree
, fnargs
, p
);
141 if (TREE_CODE (var
) == NON_LVALUE_EXPR
)
142 var
= TREE_OPERAND (var
, 0);
144 if (TREE_CODE (var
) == ERROR_MARK
)
145 return NULL_TREE
; /* Let somebody else deal with the problem. */
147 arg_type
= TREE_TYPE (var
);
149 /* The intrinsics spec does not specify precisely how to
150 resolve generic intrinsics. We require an exact match
151 for vector types and let C do it's usual parameter type
152 checking/promotions for scalar arguments, except for the
153 first argument of intrinsics which don't have a vector
155 if ((!SCALAR_TYPE_P (param_type
)
156 || !SCALAR_TYPE_P (arg_type
)
157 || (all_scalar
&& p
== 0))
158 && !lang_hooks
.types_compatible_p (param_type
, arg_type
))
161 if (param
== void_list_node
)
165 error ("too many arguments to overloaded function %s",
167 return error_mark_node
;
175 if (match
== NULL_TREE
)
177 error ("parameter list does not match a valid signature for %s()",
179 return error_mark_node
;
182 return build_function_call_vec (loc
, match
, fnargs
, NULL
);
188 spu_cpu_cpp_builtins (struct cpp_reader
*pfile
)
190 builtin_define_std ("__SPU__");
191 cpp_assert (pfile
, "cpu=spu");
192 cpp_assert (pfile
, "machine=spu");
193 if (spu_arch
== PROCESSOR_CELLEDP
)
194 builtin_define_std ("__SPU_EDP__");
195 builtin_define_std ("__vector=__attribute__((__spu_vector__))");
196 switch (spu_ea_model
)
199 builtin_define_std ("__EA32__");
202 builtin_define_std ("__EA64__");
210 /* Define this when supporting context-sensitive keywords. */
211 cpp_define (pfile
, "__VECTOR_KEYWORD_SUPPORTED__");
212 cpp_define (pfile
, "vector=vector");
214 /* Initialize vector keywords. */
215 __vector_keyword
= get_identifier ("__vector");
216 C_CPP_HASHNODE (__vector_keyword
)->flags
|= NODE_CONDITIONAL
;
217 vector_keyword
= get_identifier ("vector");
218 C_CPP_HASHNODE (vector_keyword
)->flags
|= NODE_CONDITIONAL
;
220 /* Enable context-sensitive macros. */
221 cpp_get_callbacks (pfile
)->macro_to_expand
= spu_macro_to_expand
;
226 spu_c_common_override_options (void)
228 if (!TARGET_STD_MAIN
)
230 /* Don't give warnings about the main() function. */