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