comparison gcc/jit/jit-playback.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Internals of libgccjit: classes for playing back recorded API calls. 1 /* Internals of libgccjit: classes for playing back recorded API calls.
2 Copyright (C) 2013-2018 Free Software Foundation, Inc. 2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>. 3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it 7 GCC is free software; you can redistribute it and/or modify it
45 #include "jit-playback.h" 45 #include "jit-playback.h"
46 #include "jit-result.h" 46 #include "jit-result.h"
47 #include "jit-builtins.h" 47 #include "jit-builtins.h"
48 #include "jit-tempdir.h" 48 #include "jit-tempdir.h"
49 49
50 /* Compare with gcc/c-family/c-common.h: DECL_C_BIT_FIELD,
51 SET_DECL_C_BIT_FIELD.
52 These are redefined here to avoid depending from the C frontend. */
53 #define DECL_JIT_BIT_FIELD(NODE) \
54 (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) == 1)
55 #define SET_DECL_JIT_BIT_FIELD(NODE) \
56 (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) = 1)
50 57
51 /* gcc::jit::playback::context::build_cast uses the convert.h API, 58 /* gcc::jit::playback::context::build_cast uses the convert.h API,
52 which in turn requires the frontend to provide a "convert" 59 which in turn requires the frontend to provide a "convert"
53 function, apparently as a fallback. 60 function, apparently as a fallback.
54 61
261 set_tree_location (decl, loc); 268 set_tree_location (decl, loc);
262 269
263 return new field (decl); 270 return new field (decl);
264 } 271 }
265 272
273 /* Construct a playback::bitfield instance (wrapping a tree). */
274
275 playback::field *
276 playback::context::
277 new_bitfield (location *loc,
278 type *type,
279 int width,
280 const char *name)
281 {
282 gcc_assert (type);
283 gcc_assert (name);
284 gcc_assert (width);
285
286 /* compare with c/c-decl.c:grokfield, grokdeclarator and
287 check_bitfield_type_and_width. */
288
289 tree tree_type = type->as_tree ();
290 gcc_assert (INTEGRAL_TYPE_P (tree_type));
291 tree tree_width = build_int_cst (integer_type_node, width);
292 if (compare_tree_int (tree_width, TYPE_PRECISION (tree_type)) > 0)
293 {
294 add_error (
295 loc,
296 "width of bit-field %s (width: %i) is wider than its type (width: %i)",
297 name, width, TYPE_PRECISION (tree_type));
298 return NULL;
299 }
300
301 tree decl = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
302 get_identifier (name), type->as_tree ());
303 DECL_NONADDRESSABLE_P (decl) = true;
304 DECL_INITIAL (decl) = tree_width;
305 SET_DECL_JIT_BIT_FIELD (decl);
306
307 if (loc)
308 set_tree_location (decl, loc);
309
310 return new field (decl);
311 }
312
266 /* Construct a playback::compound_type instance (wrapping a tree). */ 313 /* Construct a playback::compound_type instance (wrapping a tree). */
267 314
268 playback::compound_type * 315 playback::compound_type *
269 playback::context:: 316 playback::context::
270 new_compound_type (location *loc, 317 new_compound_type (location *loc,
293 340
294 tree fieldlist = NULL; 341 tree fieldlist = NULL;
295 for (unsigned i = 0; i < fields->length (); i++) 342 for (unsigned i = 0; i < fields->length (); i++)
296 { 343 {
297 field *f = (*fields)[i]; 344 field *f = (*fields)[i];
298 DECL_CONTEXT (f->as_tree ()) = t; 345 tree x = f->as_tree ();
299 fieldlist = chainon (f->as_tree (), fieldlist); 346 DECL_CONTEXT (x) = t;
347 if (DECL_JIT_BIT_FIELD (x))
348 {
349 unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
350 DECL_SIZE (x) = bitsize_int (width);
351 DECL_BIT_FIELD (x) = 1;
352 }
353 fieldlist = chainon (x, fieldlist);
300 } 354 }
301 fieldlist = nreverse (fieldlist); 355 fieldlist = nreverse (fieldlist);
302 TYPE_FIELDS (t) = fieldlist; 356 TYPE_FIELDS (t) = fieldlist;
303 357
304 layout_type (t); 358 layout_type (t);
397 DECL_IGNORED_P (resdecl) = 1; 451 DECL_IGNORED_P (resdecl) = 1;
398 DECL_RESULT (fndecl) = resdecl; 452 DECL_RESULT (fndecl) = resdecl;
399 453
400 if (builtin_id) 454 if (builtin_id)
401 { 455 {
402 DECL_FUNCTION_CODE (fndecl) = builtin_id;
403 gcc_assert (loc == NULL); 456 gcc_assert (loc == NULL);
404 DECL_SOURCE_LOCATION (fndecl) = BUILTINS_LOCATION; 457 DECL_SOURCE_LOCATION (fndecl) = BUILTINS_LOCATION;
405 458
406 DECL_BUILT_IN_CLASS (fndecl) = 459 built_in_class fclass = builtins_manager::get_class (builtin_id);
407 builtins_manager::get_class (builtin_id); 460 set_decl_built_in_function (fndecl, fclass, builtin_id);
408 set_builtin_decl (builtin_id, fndecl, 461 set_builtin_decl (builtin_id, fndecl,
409 builtins_manager::implicit_p (builtin_id)); 462 builtins_manager::implicit_p (builtin_id));
410 463
411 builtins_manager *bm = get_builtins_manager (); 464 builtins_manager *bm = get_builtins_manager ();
412 tree attrs = bm->get_attrs_tree (builtin_id); 465 tree attrs = bm->get_attrs_tree (builtin_id);
1195 tree ptr = as_tree (); 1248 tree ptr = as_tree ();
1196 tree datum = get_context ()->new_dereference (ptr, loc); 1249 tree datum = get_context ()->new_dereference (ptr, loc);
1197 return new lvalue (get_context (), datum); 1250 return new lvalue (get_context (), datum);
1198 } 1251 }
1199 1252
1200 /* Mark EXP saying that we need to be able to take the 1253 /* Mark the lvalue saying that we need to be able to take the
1201 address of it; it should not be allocated in a register. 1254 address of it; it should not be allocated in a register.
1202 Compare with e.g. c/c-typeck.c: c_mark_addressable. */ 1255 Compare with e.g. c/c-typeck.c: c_mark_addressable really_atomic_lvalue.
1203 1256 Returns false if a failure occurred (an error will already have been
1204 static void 1257 added to the active context for this case). */
1205 jit_mark_addressable (tree exp) 1258
1206 { 1259 bool
1207 tree x = exp; 1260 playback::lvalue::
1261 mark_addressable (location *loc)
1262 {
1263 tree x = as_tree ();;
1208 1264
1209 while (1) 1265 while (1)
1210 switch (TREE_CODE (x)) 1266 switch (TREE_CODE (x))
1211 { 1267 {
1212 case COMPONENT_REF: 1268 case COMPONENT_REF:
1213 /* (we don't yet support bitfields) */ 1269 if (DECL_JIT_BIT_FIELD (TREE_OPERAND (x, 1)))
1270 {
1271 gcc_assert (gcc::jit::active_playback_ctxt);
1272 gcc::jit::
1273 active_playback_ctxt->add_error (loc,
1274 "cannot take address of "
1275 "bit-field");
1276 return false;
1277 }
1214 /* fallthrough */ 1278 /* fallthrough */
1215 case ADDR_EXPR: 1279 case ADDR_EXPR:
1216 case ARRAY_REF: 1280 case ARRAY_REF:
1217 case REALPART_EXPR: 1281 case REALPART_EXPR:
1218 case IMAGPART_EXPR: 1282 case IMAGPART_EXPR:
1220 break; 1284 break;
1221 1285
1222 case COMPOUND_LITERAL_EXPR: 1286 case COMPOUND_LITERAL_EXPR:
1223 case CONSTRUCTOR: 1287 case CONSTRUCTOR:
1224 TREE_ADDRESSABLE (x) = 1; 1288 TREE_ADDRESSABLE (x) = 1;
1225 return; 1289 return true;
1226 1290
1227 case VAR_DECL: 1291 case VAR_DECL:
1228 case CONST_DECL: 1292 case CONST_DECL:
1229 case PARM_DECL: 1293 case PARM_DECL:
1230 case RESULT_DECL: 1294 case RESULT_DECL:
1232 /* fallthrough */ 1296 /* fallthrough */
1233 case FUNCTION_DECL: 1297 case FUNCTION_DECL:
1234 TREE_ADDRESSABLE (x) = 1; 1298 TREE_ADDRESSABLE (x) = 1;
1235 /* fallthrough */ 1299 /* fallthrough */
1236 default: 1300 default:
1237 return; 1301 return true;
1238 } 1302 }
1239 } 1303 }
1240 1304
1241 /* Construct a playback::rvalue instance (wrapping a tree) for an 1305 /* Construct a playback::rvalue instance (wrapping a tree) for an
1242 address-lookup. */ 1306 address-lookup. */
1249 tree t_thistype = TREE_TYPE (t_lvalue); 1313 tree t_thistype = TREE_TYPE (t_lvalue);
1250 tree t_ptrtype = build_pointer_type (t_thistype); 1314 tree t_ptrtype = build_pointer_type (t_thistype);
1251 tree ptr = build1 (ADDR_EXPR, t_ptrtype, t_lvalue); 1315 tree ptr = build1 (ADDR_EXPR, t_ptrtype, t_lvalue);
1252 if (loc) 1316 if (loc)
1253 get_context ()->set_tree_location (ptr, loc); 1317 get_context ()->set_tree_location (ptr, loc);
1254 jit_mark_addressable (t_lvalue); 1318 if (mark_addressable (loc))
1255 return new rvalue (get_context (), ptr); 1319 return new rvalue (get_context (), ptr);
1320 else
1321 return NULL;
1256 } 1322 }
1257 1323
1258 /* The wrapper subclasses are GC-managed, but can own non-GC memory. 1324 /* The wrapper subclasses are GC-managed, but can own non-GC memory.
1259 Provide this finalization hook for calling then they are collected, 1325 Provide this finalization hook for calling then they are collected,
1260 which calls the finalizer vfunc. This allows them to call "release" 1326 which calls the finalizer vfunc. This allows them to call "release"
2205 } 2271 }
2206 2272
2207 /* Aggressively garbage-collect, to shake out bugs: */ 2273 /* Aggressively garbage-collect, to shake out bugs: */
2208 if (get_bool_option (GCC_JIT_BOOL_OPTION_SELFCHECK_GC)) 2274 if (get_bool_option (GCC_JIT_BOOL_OPTION_SELFCHECK_GC))
2209 { 2275 {
2210 ADD_ARG ("--param"); 2276 ADD_ARG ("--param=ggc-min-expand=0");
2211 ADD_ARG ("ggc-min-expand=0"); 2277 ADD_ARG ("--param=ggc-min-heapsize=0");
2212 ADD_ARG ("--param");
2213 ADD_ARG ("ggc-min-heapsize=0");
2214 } 2278 }
2215 2279
2216 if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING)) 2280 if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING))
2217 { 2281 {
2218 ADD_ARG ("-fdump-tree-all"); 2282 ADD_ARG ("-fdump-tree-all");
2456 ADD_ARG ("-Wl,-undefined,dynamic_lookup"); 2520 ADD_ARG ("-Wl,-undefined,dynamic_lookup");
2457 #endif 2521 #endif
2458 2522
2459 if (0) 2523 if (0)
2460 ADD_ARG ("-v"); 2524 ADD_ARG ("-v");
2525
2526 /* Add any user-provided driver extra options. */
2527
2528 m_recording_ctxt->append_driver_options (&argvec);
2461 2529
2462 #undef ADD_ARG 2530 #undef ADD_ARG
2463 2531
2464 /* pex_one's error-handling requires pname to be non-NULL. */ 2532 /* pex_one's error-handling requires pname to be non-NULL. */
2465 gcc_assert (ctxt_progname); 2533 gcc_assert (ctxt_progname);
2825 std::pair<tree, location *> *cached_location; 2893 std::pair<tree, location *> *cached_location;
2826 2894
2827 FOR_EACH_VEC_ELT (m_cached_locations, i, cached_location) 2895 FOR_EACH_VEC_ELT (m_cached_locations, i, cached_location)
2828 { 2896 {
2829 tree t = cached_location->first; 2897 tree t = cached_location->first;
2830 source_location srcloc = cached_location->second->m_srcloc; 2898 location_t srcloc = cached_location->second->m_srcloc;
2831 2899
2832 /* This covers expressions: */ 2900 /* This covers expressions: */
2833 if (CAN_HAVE_LOCATION_P (t)) 2901 if (CAN_HAVE_LOCATION_P (t))
2834 SET_EXPR_LOCATION (t, srcloc); 2902 SET_EXPR_LOCATION (t, srcloc);
2835 else if (CODE_CONTAINS_STRUCT(TREE_CODE(t), TS_DECL_MINIMAL)) 2903 else if (CODE_CONTAINS_STRUCT(TREE_CODE(t), TS_DECL_MINIMAL))
2925 } 2993 }
2926 2994
2927 /* Deferred setting of the location for a given tree, by adding the 2995 /* Deferred setting of the location for a given tree, by adding the
2928 (tree, playback::location) pair to a list of deferred associations. 2996 (tree, playback::location) pair to a list of deferred associations.
2929 We will actually set the location on the tree later on once 2997 We will actually set the location on the tree later on once
2930 the source_location for the playback::location exists. */ 2998 the location_t for the playback::location exists. */
2931 2999
2932 void 3000 void
2933 playback::context:: 3001 playback::context::
2934 set_tree_location (tree t, location *loc) 3002 set_tree_location (tree t, location *loc)
2935 { 3003 {