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