1 /* jit.c -- Dummy "frontend" for use during JIT-compilation. 2 Copyright (C) 2013-2016 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 #include "config.h" 21 #include "system.h" 22 #include "coretypes.h" 23 #include "jit-playback.h" 24 #include "stor-layout.h" 25 #include "debug.h" 26 #include "langhooks.h" 27 #include "langhooks-def.h" 28 29 30 #include <mpfr.h> 31 32 /* Language-dependent contents of a type. */ 33 34 struct GTY(()) lang_type 35 { 36 char dummy; 37 }; 38 39 /* Language-dependent contents of a decl. */ 40 41 struct GTY((variable_size)) lang_decl 42 { 43 char dummy; 44 }; 45 46 /* Language-dependent contents of an identifier. This must include a 47 tree_identifier. */ 48 49 struct GTY(()) lang_identifier 50 { 51 struct tree_identifier common; 52 }; 53 54 /* The resulting tree type. */ 55 56 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), 57 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) 58 lang_tree_node 59 { 60 union tree_node GTY((tag ("0"), 61 desc ("tree_node_structure (&%h)"))) generic; 62 struct lang_identifier GTY((tag ("1"))) identifier; 63 }; 64 65 /* We don't use language_function. */ 66 67 struct GTY(()) language_function 68 { 69 int dummy; 70 }; 71 72 /* GC-marking callback for use from jit_root_tab. 73 74 If there's an active playback context, call its marking method 75 so that it can mark any pointers it references. */ 76 77 static void my_ggc_walker (void *) 78 { 79 if (gcc::jit::active_playback_ctxt) 80 gcc::jit::active_playback_ctxt->gt_ggc_mx (); 81 } 82 83 const char *dummy; 84 85 struct ggc_root_tab jit_root_tab[] = 86 { 87 { 88 &dummy, 1, 0, my_ggc_walker, NULL 89 }, 90 LAST_GGC_ROOT_TAB 91 }; 92 93 /* Language hooks. */ 94 95 static bool 96 jit_langhook_init (void) 97 { 98 gcc_assert (gcc::jit::active_playback_ctxt); 99 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); 100 101 static bool registered_root_tab = false; 102 if (!registered_root_tab) 103 { 104 ggc_register_root_tab (jit_root_tab); 105 registered_root_tab = true; 106 } 107 108 build_common_tree_nodes (false); 109 110 /* I don't know why this has to be done explicitly. */ 111 void_list_node = build_tree_list (NULL_TREE, void_type_node); 112 113 build_common_builtin_nodes (); 114 115 /* The default precision for floating point numbers. This is used 116 for floating point constants with abstract type. This may 117 eventually be controllable by a command line option. */ 118 mpfr_set_default_prec (256); 119 120 return true; 121 } 122 123 static void 124 jit_langhook_parse_file (void) 125 { 126 /* Replay the activity by the client, recorded on the context. */ 127 gcc_assert (gcc::jit::active_playback_ctxt); 128 gcc::jit::active_playback_ctxt->replay (); 129 } 130 131 static tree 132 jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp) 133 { 134 if (mode == TYPE_MODE (float_type_node)) 135 return float_type_node; 136 137 if (mode == TYPE_MODE (double_type_node)) 138 return double_type_node; 139 140 if (mode == TYPE_MODE (intQI_type_node)) 141 return unsignedp ? unsigned_intQI_type_node : intQI_type_node; 142 if (mode == TYPE_MODE (intHI_type_node)) 143 return unsignedp ? unsigned_intHI_type_node : intHI_type_node; 144 if (mode == TYPE_MODE (intSI_type_node)) 145 return unsignedp ? unsigned_intSI_type_node : intSI_type_node; 146 if (mode == TYPE_MODE (intDI_type_node)) 147 return unsignedp ? unsigned_intDI_type_node : intDI_type_node; 148 if (mode == TYPE_MODE (intTI_type_node)) 149 return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 150 151 if (mode == TYPE_MODE (integer_type_node)) 152 return unsignedp ? unsigned_type_node : integer_type_node; 153 154 if (mode == TYPE_MODE (long_integer_type_node)) 155 return unsignedp ? long_unsigned_type_node : long_integer_type_node; 156 157 if (mode == TYPE_MODE (long_long_integer_type_node)) 158 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; 159 160 if (COMPLEX_MODE_P (mode)) 161 { 162 if (mode == TYPE_MODE (complex_float_type_node)) 163 return complex_float_type_node; 164 if (mode == TYPE_MODE (complex_double_type_node)) 165 return complex_double_type_node; 166 if (mode == TYPE_MODE (complex_long_double_type_node)) 167 return complex_long_double_type_node; 168 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp) 169 return complex_integer_type_node; 170 } 171 172 /* gcc_unreachable */ 173 return NULL; 174 } 175 176 static tree 177 jit_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED, 178 int unsignedp ATTRIBUTE_UNUSED) 179 { 180 gcc_unreachable (); 181 return NULL; 182 } 183 184 /* Record a builtin function. We just ignore builtin functions. */ 185 186 static tree 187 jit_langhook_builtin_function (tree decl) 188 { 189 return decl; 190 } 191 192 static bool 193 jit_langhook_global_bindings_p (void) 194 { 195 gcc_unreachable (); 196 return true; 197 } 198 199 static tree 200 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED) 201 { 202 gcc_unreachable (); 203 } 204 205 static tree 206 jit_langhook_getdecls (void) 207 { 208 return NULL; 209 } 210 211 #undef LANG_HOOKS_NAME 212 #define LANG_HOOKS_NAME "libgccjit" 213 214 #undef LANG_HOOKS_INIT 215 #define LANG_HOOKS_INIT jit_langhook_init 216 217 #undef LANG_HOOKS_PARSE_FILE 218 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file 219 220 #undef LANG_HOOKS_TYPE_FOR_MODE 221 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode 222 223 #undef LANG_HOOKS_TYPE_FOR_SIZE 224 #define LANG_HOOKS_TYPE_FOR_SIZE jit_langhook_type_for_size 225 226 #undef LANG_HOOKS_BUILTIN_FUNCTION 227 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function 228 229 #undef LANG_HOOKS_GLOBAL_BINDINGS_P 230 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p 231 232 #undef LANG_HOOKS_PUSHDECL 233 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl 234 235 #undef LANG_HOOKS_GETDECLS 236 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls 237 238 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; 239 240 #include "gt-jit-dummy-frontend.h" 241 #include "gtype-jit.h" 242