111
|
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
|
131
|
2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
|
111
|
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 #include "diagnostic.h"
|
|
29
|
|
30
|
|
31 #include <mpfr.h>
|
|
32
|
|
33 /* Language-dependent contents of a type. */
|
|
34
|
|
35 struct GTY(()) lang_type
|
|
36 {
|
|
37 char dummy;
|
|
38 };
|
|
39
|
|
40 /* Language-dependent contents of a decl. */
|
|
41
|
|
42 struct GTY((variable_size)) lang_decl
|
|
43 {
|
|
44 char dummy;
|
|
45 };
|
|
46
|
|
47 /* Language-dependent contents of an identifier. This must include a
|
|
48 tree_identifier. */
|
|
49
|
|
50 struct GTY(()) lang_identifier
|
|
51 {
|
|
52 struct tree_identifier common;
|
|
53 };
|
|
54
|
|
55 /* The resulting tree type. */
|
|
56
|
|
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
|
|
60 {
|
|
61 union tree_node GTY((tag ("0"),
|
|
62 desc ("tree_node_structure (&%h)"))) generic;
|
|
63 struct lang_identifier GTY((tag ("1"))) identifier;
|
|
64 };
|
|
65
|
|
66 /* We don't use language_function. */
|
|
67
|
|
68 struct GTY(()) language_function
|
|
69 {
|
|
70 int dummy;
|
|
71 };
|
|
72
|
|
73 /* GC-marking callback for use from jit_root_tab.
|
|
74
|
|
75 If there's an active playback context, call its marking method
|
|
76 so that it can mark any pointers it references. */
|
|
77
|
|
78 static void my_ggc_walker (void *)
|
|
79 {
|
|
80 if (gcc::jit::active_playback_ctxt)
|
|
81 gcc::jit::active_playback_ctxt->gt_ggc_mx ();
|
|
82 }
|
|
83
|
|
84 const char *dummy;
|
|
85
|
|
86 struct ggc_root_tab jit_root_tab[] =
|
|
87 {
|
|
88 {
|
|
89 &dummy, 1, 0, my_ggc_walker, NULL
|
|
90 },
|
|
91 LAST_GGC_ROOT_TAB
|
|
92 };
|
|
93
|
|
94 /* JIT-specific implementation of diagnostic callbacks. */
|
|
95
|
|
96 /* Implementation of "begin_diagnostic". */
|
|
97
|
|
98 static void
|
|
99 jit_begin_diagnostic (diagnostic_context */*context*/,
|
|
100 diagnostic_info */*diagnostic*/)
|
|
101 {
|
|
102 gcc_assert (gcc::jit::active_playback_ctxt);
|
|
103 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
|
|
104
|
|
105 /* No-op (apart from logging); the real error-handling is done in the
|
|
106 "end_diagnostic" hook. */
|
|
107 }
|
|
108
|
|
109 /* Implementation of "end_diagnostic". */
|
|
110
|
|
111 static void
|
|
112 jit_end_diagnostic (diagnostic_context *context,
|
|
113 diagnostic_info *diagnostic)
|
|
114 {
|
|
115 gcc_assert (gcc::jit::active_playback_ctxt);
|
|
116 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
|
|
117
|
|
118 /* Delegate to the playback context (and thence to the
|
|
119 recording context). */
|
|
120 gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic);
|
|
121 }
|
|
122
|
|
123 /* Language hooks. */
|
|
124
|
|
125 static bool
|
|
126 jit_langhook_init (void)
|
|
127 {
|
|
128 gcc_assert (gcc::jit::active_playback_ctxt);
|
|
129 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
|
|
130
|
|
131 static bool registered_root_tab = false;
|
|
132 if (!registered_root_tab)
|
|
133 {
|
|
134 ggc_register_root_tab (jit_root_tab);
|
|
135 registered_root_tab = true;
|
|
136 }
|
|
137
|
|
138 gcc_assert (global_dc);
|
|
139 global_dc->begin_diagnostic = jit_begin_diagnostic;
|
|
140 global_dc->end_diagnostic = jit_end_diagnostic;
|
|
141
|
|
142 build_common_tree_nodes (false);
|
|
143
|
|
144 /* I don't know why this has to be done explicitly. */
|
|
145 void_list_node = build_tree_list (NULL_TREE, void_type_node);
|
|
146
|
|
147 build_common_builtin_nodes ();
|
|
148
|
|
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);
|
|
153
|
|
154 return true;
|
|
155 }
|
|
156
|
|
157 static void
|
|
158 jit_langhook_parse_file (void)
|
|
159 {
|
|
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 ();
|
|
163 }
|
|
164
|
|
165 static tree
|
|
166 jit_langhook_type_for_mode (machine_mode mode, int unsignedp)
|
|
167 {
|
|
168 /* Build any vector types here (see PR 46805). */
|
|
169 if (VECTOR_MODE_P (mode))
|
|
170 {
|
|
171 tree inner;
|
|
172
|
|
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;
|
|
177 }
|
|
178
|
|
179 if (mode == TYPE_MODE (float_type_node))
|
|
180 return float_type_node;
|
|
181
|
|
182 if (mode == TYPE_MODE (double_type_node))
|
|
183 return double_type_node;
|
|
184
|
|
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;
|
|
195
|
|
196 if (mode == TYPE_MODE (integer_type_node))
|
|
197 return unsignedp ? unsigned_type_node : integer_type_node;
|
|
198
|
|
199 if (mode == TYPE_MODE (long_integer_type_node))
|
|
200 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
|
|
201
|
|
202 if (mode == TYPE_MODE (long_long_integer_type_node))
|
|
203 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
|
|
204
|
|
205 if (COMPLEX_MODE_P (mode))
|
|
206 {
|
|
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;
|
|
215 }
|
|
216
|
|
217 /* gcc_unreachable */
|
|
218 return NULL;
|
|
219 }
|
|
220
|
|
221 /* Record a builtin function. We just ignore builtin functions. */
|
|
222
|
|
223 static tree
|
|
224 jit_langhook_builtin_function (tree decl)
|
|
225 {
|
|
226 return decl;
|
|
227 }
|
|
228
|
|
229 static bool
|
|
230 jit_langhook_global_bindings_p (void)
|
|
231 {
|
|
232 gcc_unreachable ();
|
|
233 return true;
|
|
234 }
|
|
235
|
|
236 static tree
|
|
237 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
|
|
238 {
|
|
239 gcc_unreachable ();
|
|
240 }
|
|
241
|
|
242 static tree
|
|
243 jit_langhook_getdecls (void)
|
|
244 {
|
|
245 return NULL;
|
|
246 }
|
|
247
|
|
248 #undef LANG_HOOKS_NAME
|
|
249 #define LANG_HOOKS_NAME "libgccjit"
|
|
250
|
|
251 #undef LANG_HOOKS_INIT
|
|
252 #define LANG_HOOKS_INIT jit_langhook_init
|
|
253
|
|
254 #undef LANG_HOOKS_PARSE_FILE
|
|
255 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file
|
|
256
|
|
257 #undef LANG_HOOKS_TYPE_FOR_MODE
|
|
258 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode
|
|
259
|
|
260 #undef LANG_HOOKS_BUILTIN_FUNCTION
|
|
261 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function
|
|
262
|
|
263 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
|
|
264 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p
|
|
265
|
|
266 #undef LANG_HOOKS_PUSHDECL
|
|
267 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl
|
|
268
|
|
269 #undef LANG_HOOKS_GETDECLS
|
|
270 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls
|
|
271
|
|
272 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
|
|
273
|
|
274 #include "gt-jit-dummy-frontend.h"
|
|
275 #include "gtype-jit.h"
|