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