1 /* jit-builtins.h -- Handling of builtin functions during JIT-compilation. 2 Copyright (C) 2014-2018 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 6 GCC is free software; you can redistribute it and/or modify it under 7 the terms of the GNU General Public License as published by the Free 8 Software Foundation; either version 3, or (at your option) any later 9 version. 10 11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 #ifndef JIT_BUILTINS_H 21 #define JIT_BUILTINS_H 22 23 #include "jit-common.h" 24 25 namespace gcc { 26 27 namespace jit { 28 29 /* Create an enum of the builtin types. */ 30 31 enum jit_builtin_type 32 { 33 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME, 34 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME, 35 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME, 36 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME, 37 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, 38 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, 39 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME, 40 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 41 ARG6) NAME, 42 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 43 ARG6, ARG7) NAME, 44 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 45 ARG6, ARG7, ARG8) NAME, 46 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 47 ARG6, ARG7, ARG8, ARG9) NAME, 48 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 49 ARG6, ARG7, ARG8, ARG9, ARG10) NAME, 50 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 51 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME, 52 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME, 53 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME, 54 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME, 55 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, 56 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, 57 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ 58 NAME, 59 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 60 ARG6) NAME, 61 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 62 ARG6, ARG7) NAME, 63 #define DEF_POINTER_TYPE(NAME, TYPE) NAME, 64 #include "builtin-types.def" 65 #undef DEF_PRIMITIVE_TYPE 66 #undef DEF_FUNCTION_TYPE_0 67 #undef DEF_FUNCTION_TYPE_1 68 #undef DEF_FUNCTION_TYPE_2 69 #undef DEF_FUNCTION_TYPE_3 70 #undef DEF_FUNCTION_TYPE_4 71 #undef DEF_FUNCTION_TYPE_5 72 #undef DEF_FUNCTION_TYPE_6 73 #undef DEF_FUNCTION_TYPE_7 74 #undef DEF_FUNCTION_TYPE_8 75 #undef DEF_FUNCTION_TYPE_9 76 #undef DEF_FUNCTION_TYPE_10 77 #undef DEF_FUNCTION_TYPE_11 78 #undef DEF_FUNCTION_TYPE_VAR_0 79 #undef DEF_FUNCTION_TYPE_VAR_1 80 #undef DEF_FUNCTION_TYPE_VAR_2 81 #undef DEF_FUNCTION_TYPE_VAR_3 82 #undef DEF_FUNCTION_TYPE_VAR_4 83 #undef DEF_FUNCTION_TYPE_VAR_5 84 #undef DEF_FUNCTION_TYPE_VAR_6 85 #undef DEF_FUNCTION_TYPE_VAR_7 86 #undef DEF_POINTER_TYPE 87 BT_LAST 88 }; /* enum jit_builtin_type */ 89 90 /* Create an enum of the attributes that can be present on builtins. */ 91 92 enum built_in_attribute 93 { 94 #define DEF_ATTR_NULL_TREE(ENUM) ENUM, 95 #define DEF_ATTR_INT(ENUM, VALUE) ENUM, 96 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM, 97 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM, 98 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM, 99 #include "builtin-attrs.def" 100 #undef DEF_ATTR_NULL_TREE 101 #undef DEF_ATTR_INT 102 #undef DEF_ATTR_STRING 103 #undef DEF_ATTR_IDENT 104 #undef DEF_ATTR_TREE_LIST 105 ATTR_LAST 106 }; 107 108 /***********************************************************************/ 109 110 class builtins_manager 111 { 112 public: 113 builtins_manager (recording::context *ctxt); 114 115 recording::function * 116 get_builtin_function (const char *name); 117 118 static enum built_in_class 119 get_class (enum built_in_function builtin_id); 120 121 static bool 122 implicit_p (enum built_in_function builtin_id); 123 124 tree 125 get_attrs_tree (enum built_in_function builtin_id); 126 127 tree 128 get_attrs_tree (enum built_in_attribute attr); 129 130 void 131 finish_playback (void); 132 133 private: 134 recording::function * 135 get_builtin_function_by_id (enum built_in_function builtin_id); 136 137 recording::function * 138 make_builtin_function (enum built_in_function builtin_id); 139 140 recording::type * 141 get_type (enum jit_builtin_type type_id); 142 143 recording::type * 144 make_type (enum jit_builtin_type type_id); 145 146 recording::type* 147 make_primitive_type (enum jit_builtin_type type_id); 148 149 recording::function_type* 150 make_fn_type (enum jit_builtin_type type_id, 151 enum jit_builtin_type return_type_id, 152 bool is_variadic, 153 int num_args, ...); 154 155 recording::type* 156 make_ptr_type (enum jit_builtin_type type_id, 157 enum jit_builtin_type other_type_id); 158 159 tree 160 make_attrs_tree (enum built_in_attribute attr); 161 162 private: 163 /* Recording fields. */ 164 recording::context *m_ctxt; 165 recording::type *m_types[BT_LAST]; 166 recording::function *m_builtin_functions[END_BUILTINS]; 167 168 /* Playback fields. */ 169 /* m_attributes is not GTY-marked, but is only ever used from within 170 the region of playback::context::replay () in which a GC can't 171 happen. */ 172 tree m_attributes[ATTR_LAST]; 173 }; 174 175 } // namespace jit 176 } // namespace gcc 177 178 #endif /* JIT_BUILTINS_H */ 179