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