PR tree-optimization/83695
[official-gcc.git] / gcc / jit / dummy-frontend.c
blob4c7f96078a4961dc69065b7382c593194470d6cd
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
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 #include "diagnostic.h"
31 #include <mpfr.h>
33 /* Language-dependent contents of a type. */
35 struct GTY(()) lang_type
37 char dummy;
40 /* Language-dependent contents of a decl. */
42 struct GTY((variable_size)) lang_decl
44 char dummy;
47 /* Language-dependent contents of an identifier. This must include a
48 tree_identifier. */
50 struct GTY(()) lang_identifier
52 struct tree_identifier common;
55 /* The resulting tree type. */
57 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
58 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
59 lang_tree_node
61 union tree_node GTY((tag ("0"),
62 desc ("tree_node_structure (&%h)"))) generic;
63 struct lang_identifier GTY((tag ("1"))) identifier;
66 /* We don't use language_function. */
68 struct GTY(()) language_function
70 int dummy;
73 /* GC-marking callback for use from jit_root_tab.
75 If there's an active playback context, call its marking method
76 so that it can mark any pointers it references. */
78 static void my_ggc_walker (void *)
80 if (gcc::jit::active_playback_ctxt)
81 gcc::jit::active_playback_ctxt->gt_ggc_mx ();
84 const char *dummy;
86 struct ggc_root_tab jit_root_tab[] =
89 &dummy, 1, 0, my_ggc_walker, NULL
91 LAST_GGC_ROOT_TAB
94 /* JIT-specific implementation of diagnostic callbacks. */
96 /* Implementation of "begin_diagnostic". */
98 static void
99 jit_begin_diagnostic (diagnostic_context */*context*/,
100 diagnostic_info */*diagnostic*/)
102 gcc_assert (gcc::jit::active_playback_ctxt);
103 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
105 /* No-op (apart from logging); the real error-handling is done in the
106 "end_diagnostic" hook. */
109 /* Implementation of "end_diagnostic". */
111 static void
112 jit_end_diagnostic (diagnostic_context *context,
113 diagnostic_info *diagnostic)
115 gcc_assert (gcc::jit::active_playback_ctxt);
116 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
118 /* Delegate to the playback context (and thence to the
119 recording context). */
120 gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic);
123 /* Language hooks. */
125 static bool
126 jit_langhook_init (void)
128 gcc_assert (gcc::jit::active_playback_ctxt);
129 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
131 static bool registered_root_tab = false;
132 if (!registered_root_tab)
134 ggc_register_root_tab (jit_root_tab);
135 registered_root_tab = true;
138 gcc_assert (global_dc);
139 global_dc->begin_diagnostic = jit_begin_diagnostic;
140 global_dc->end_diagnostic = jit_end_diagnostic;
142 build_common_tree_nodes (false);
144 /* I don't know why this has to be done explicitly. */
145 void_list_node = build_tree_list (NULL_TREE, void_type_node);
147 build_common_builtin_nodes ();
149 /* The default precision for floating point numbers. This is used
150 for floating point constants with abstract type. This may
151 eventually be controllable by a command line option. */
152 mpfr_set_default_prec (256);
154 return true;
157 static void
158 jit_langhook_parse_file (void)
160 /* Replay the activity by the client, recorded on the context. */
161 gcc_assert (gcc::jit::active_playback_ctxt);
162 gcc::jit::active_playback_ctxt->replay ();
165 static tree
166 jit_langhook_type_for_mode (machine_mode mode, int unsignedp)
168 /* Build any vector types here (see PR 46805). */
169 if (VECTOR_MODE_P (mode))
171 tree inner;
173 inner = jit_langhook_type_for_mode (GET_MODE_INNER (mode), unsignedp);
174 if (inner != NULL_TREE)
175 return build_vector_type_for_mode (inner, mode);
176 return NULL_TREE;
179 if (mode == TYPE_MODE (float_type_node))
180 return float_type_node;
182 if (mode == TYPE_MODE (double_type_node))
183 return double_type_node;
185 if (mode == TYPE_MODE (intQI_type_node))
186 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
187 if (mode == TYPE_MODE (intHI_type_node))
188 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
189 if (mode == TYPE_MODE (intSI_type_node))
190 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
191 if (mode == TYPE_MODE (intDI_type_node))
192 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
193 if (mode == TYPE_MODE (intTI_type_node))
194 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
196 if (mode == TYPE_MODE (integer_type_node))
197 return unsignedp ? unsigned_type_node : integer_type_node;
199 if (mode == TYPE_MODE (long_integer_type_node))
200 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
202 if (mode == TYPE_MODE (long_long_integer_type_node))
203 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
205 if (COMPLEX_MODE_P (mode))
207 if (mode == TYPE_MODE (complex_float_type_node))
208 return complex_float_type_node;
209 if (mode == TYPE_MODE (complex_double_type_node))
210 return complex_double_type_node;
211 if (mode == TYPE_MODE (complex_long_double_type_node))
212 return complex_long_double_type_node;
213 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
214 return complex_integer_type_node;
217 /* gcc_unreachable */
218 return NULL;
221 /* Record a builtin function. We just ignore builtin functions. */
223 static tree
224 jit_langhook_builtin_function (tree decl)
226 return decl;
229 static bool
230 jit_langhook_global_bindings_p (void)
232 gcc_unreachable ();
233 return true;
236 static tree
237 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
239 gcc_unreachable ();
242 static tree
243 jit_langhook_getdecls (void)
245 return NULL;
248 #undef LANG_HOOKS_NAME
249 #define LANG_HOOKS_NAME "libgccjit"
251 #undef LANG_HOOKS_INIT
252 #define LANG_HOOKS_INIT jit_langhook_init
254 #undef LANG_HOOKS_PARSE_FILE
255 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file
257 #undef LANG_HOOKS_TYPE_FOR_MODE
258 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode
260 #undef LANG_HOOKS_BUILTIN_FUNCTION
261 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function
263 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
264 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p
266 #undef LANG_HOOKS_PUSHDECL
267 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl
269 #undef LANG_HOOKS_GETDECLS
270 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls
272 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
274 #include "gt-jit-dummy-frontend.h"
275 #include "gtype-jit.h"