aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-06-24 12:24:50 +0200
committerAndrea Corallo2020-01-01 11:33:45 +0100
commitc4bebcb38fe426780fc9c460474592d12bc15deb (patch)
treeddce386f8441a82c4c71945b2fe49eae24f77c72 /src/comp.c
parentfc2e2818edc0eaa4b86124d102eb12b7a24fa486 (diff)
downloademacs-c4bebcb38fe426780fc9c460474592d12bc15deb.tar.gz
emacs-c4bebcb38fe426780fc9c460474592d12bc15deb.zip
define cast union into dedicated function
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c176
1 files changed, 128 insertions, 48 deletions
diff --git a/src/comp.c b/src/comp.c
index 9ef1a99b0f5..38183a64e20 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -987,7 +987,128 @@ define_thread_state_struct (void)
987 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s)); 987 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s));
988} 988}
989 989
990/* Declare a substitute for PSEUDOVECTORP as inline function. */ 990static void
991define_cast_union (void)
992{
993
994 comp.cast_union_as_ll =
995 gcc_jit_context_new_field (comp.ctxt,
996 NULL,
997 comp.long_long_type,
998 "ll");
999 comp.cast_union_as_l =
1000 gcc_jit_context_new_field (comp.ctxt,
1001 NULL,
1002 comp.long_type,
1003 "l");
1004 comp.cast_union_as_u =
1005 gcc_jit_context_new_field (comp.ctxt,
1006 NULL,
1007 comp.unsigned_type,
1008 "u");
1009 comp.cast_union_as_i =
1010 gcc_jit_context_new_field (comp.ctxt,
1011 NULL,
1012 comp.int_type,
1013 "i");
1014 comp.cast_union_as_b =
1015 gcc_jit_context_new_field (comp.ctxt,
1016 NULL,
1017 comp.bool_type,
1018 "b");
1019 comp.cast_union_as_c_p =
1020 gcc_jit_context_new_field (comp.ctxt,
1021 NULL,
1022 comp.char_ptr_type,
1023 "c_p");
1024 comp.cast_union_as_lisp_cons_ptr =
1025 gcc_jit_context_new_field (comp.ctxt,
1026 NULL,
1027 comp.lisp_cons_ptr_type,
1028 "cons_ptr");
1029
1030 gcc_jit_field *cast_union_fields[] =
1031 { comp.cast_union_as_ll,
1032 comp.cast_union_as_l,
1033 comp.cast_union_as_u,
1034 comp.cast_union_as_i,
1035 comp.cast_union_as_b,
1036 comp.cast_union_as_c_p,
1037 comp.cast_union_as_lisp_cons_ptr, };
1038 comp.cast_union_type =
1039 gcc_jit_context_new_union_type (comp.ctxt,
1040 NULL,
1041 "cast_union",
1042 sizeof (cast_union_fields)
1043 / sizeof (*cast_union_fields),
1044 cast_union_fields);
1045}
1046
1047/* Declare a substitute for CAR as always inlined function. */
1048
1049static void
1050define_CAR (void)
1051{
1052 gcc_jit_param *param =
1053 gcc_jit_context_new_param (comp.ctxt,
1054 NULL,
1055 comp.lisp_obj_type,
1056 "c");
1057 comp.car =
1058 gcc_jit_context_new_function (comp.ctxt, NULL,
1059 GCC_JIT_FUNCTION_ALWAYS_INLINE,
1060 comp.lisp_obj_type,
1061 "CAR",
1062 1,
1063 &param,
1064 0);
1065 gcc_jit_block *initial_block =
1066 gcc_jit_function_new_block (comp.car, "CAR_initial_block");
1067
1068 /* gcc_jit_block *is_cons_b = */
1069 /* gcc_jit_function_new_block (comp.pseudovectorp, "is_cons"); */
1070
1071 /* gcc_jit_block *not_a_cons_b = */
1072 /* gcc_jit_function_new_block (comp.pseudovectorp, "not_a_cons"); */
1073
1074
1075 /* Set current context as needed */
1076 basic_block_t block = { .gcc_bb = initial_block,
1077 .terminated = false };
1078 comp.block = █
1079 comp.func = comp.car;
1080
1081 /* emit_cond_jump ( */
1082 /* emit_cast (comp.bool_type, */
1083 /* emit_CONSP (gcc_jit_param_as_rvalue (param))), */
1084 /* is_cons_b, */
1085 /* not_a_cons_b); */
1086
1087 /* comp.block->gcc_bb = is_cons_b; */
1088
1089 gcc_jit_rvalue *res_car =
1090 /* c->u.s.car */
1091 gcc_jit_rvalue_access_field (
1092 /* c->u.s */
1093 gcc_jit_rvalue_access_field (
1094 /* c->u */
1095 gcc_jit_lvalue_as_rvalue (
1096 gcc_jit_rvalue_dereference_field (
1097 emit_rval_XCONS (gcc_jit_param_as_rvalue (param)),
1098 NULL,
1099 comp.lisp_cons_u)),
1100 NULL,
1101 comp.lisp_cons_u_s),
1102 NULL,
1103 comp.lisp_cons_u_s_car);
1104
1105 gcc_jit_block_end_with_return (initial_block,
1106 NULL,
1107 res_car);
1108
1109}
1110
1111/* Declare a substitute for PSEUDOVECTORP as always inlined function. */
991 1112
992static void 1113static void
993define_PSEUDOVECTORP (void) 1114define_PSEUDOVECTORP (void)
@@ -1022,7 +1143,7 @@ define_PSEUDOVECTORP (void)
1022 1143
1023 /* Set current context as needed */ 1144 /* Set current context as needed */
1024 basic_block_t block = { .gcc_bb = initial_block, 1145 basic_block_t block = { .gcc_bb = initial_block,
1025 .terminated = false }; 1146 .terminated = false };
1026 comp.block = █ 1147 comp.block = █
1027 comp.func = comp.pseudovectorp; 1148 comp.func = comp.pseudovectorp;
1028 1149
@@ -1044,7 +1165,7 @@ define_PSEUDOVECTORP (void)
1044 { gcc_jit_param_as_rvalue (param[0]), 1165 { gcc_jit_param_as_rvalue (param[0]),
1045 gcc_jit_param_as_rvalue (param[1]) }; 1166 gcc_jit_param_as_rvalue (param[1]) };
1046 comp.block->gcc_bb = call_pseudovector_typep_b; 1167 comp.block->gcc_bb = call_pseudovector_typep_b;
1047 /* FIXME XUNTAG missing here. */ 1168 /* FIXME use XUNTAG now that's available. */
1048 gcc_jit_block_end_with_return (call_pseudovector_typep_b, 1169 gcc_jit_block_end_with_return (call_pseudovector_typep_b,
1049 NULL, 1170 NULL,
1050 emit_call ("helper_PSEUDOVECTOR_TYPEP_XUNTAG", 1171 emit_call ("helper_PSEUDOVECTOR_TYPEP_XUNTAG",
@@ -1302,51 +1423,6 @@ init_comp (int opt_level)
1302 lisp_obj_fields); 1423 lisp_obj_fields);
1303 comp.lisp_obj_ptr_type = gcc_jit_type_get_pointer (comp.lisp_obj_type); 1424 comp.lisp_obj_ptr_type = gcc_jit_type_get_pointer (comp.lisp_obj_type);
1304 1425
1305 comp.cast_union_as_ll =
1306 gcc_jit_context_new_field (comp.ctxt,
1307 NULL,
1308 comp.long_long_type,
1309 "ll");
1310 comp.cast_union_as_l =
1311 gcc_jit_context_new_field (comp.ctxt,
1312 NULL,
1313 comp.long_type,
1314 "l");
1315 comp.cast_union_as_u =
1316 gcc_jit_context_new_field (comp.ctxt,
1317 NULL,
1318 comp.unsigned_type,
1319 "u");
1320 comp.cast_union_as_i =
1321 gcc_jit_context_new_field (comp.ctxt,
1322 NULL,
1323 comp.int_type,
1324 "i");
1325 comp.cast_union_as_b =
1326 gcc_jit_context_new_field (comp.ctxt,
1327 NULL,
1328 comp.bool_type,
1329 "b");
1330 comp.cast_union_as_c_p =
1331 gcc_jit_context_new_field (comp.ctxt,
1332 NULL,
1333 comp.bool_type,
1334 "c_p");
1335
1336 gcc_jit_field *cast_union_fields[] =
1337 { comp.cast_union_as_ll,
1338 comp.cast_union_as_l,
1339 comp.cast_union_as_u,
1340 comp.cast_union_as_i,
1341 comp.cast_union_as_b,
1342 comp.cast_union_as_c_p, };
1343 comp.cast_union_type =
1344 gcc_jit_context_new_union_type (comp.ctxt,
1345 NULL,
1346 "cast_union",
1347 sizeof (cast_union_fields)
1348 / sizeof (*cast_union_fields),
1349 cast_union_fields);
1350 comp.most_positive_fixnum = 1426 comp.most_positive_fixnum =
1351 gcc_jit_context_new_rvalue_from_long (comp.ctxt, 1427 gcc_jit_context_new_rvalue_from_long (comp.ctxt,
1352 comp.emacs_int_type, 1428 comp.emacs_int_type,
@@ -1383,10 +1459,14 @@ init_comp (int opt_level)
1383 1459
1384 comp.func_hash = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt); 1460 comp.func_hash = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt);
1385 1461
1462 /* Define data structures. */
1463
1386 define_lisp_cons (); 1464 define_lisp_cons ();
1387 define_jmp_buf (); 1465 define_jmp_buf ();
1388 define_handler_struct (); 1466 define_handler_struct ();
1389 define_thread_state_struct (); 1467 define_thread_state_struct ();
1468 define_cast_union ();
1469
1390 comp.current_thread = 1470 comp.current_thread =
1391 gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, 1471 gcc_jit_context_new_rvalue_from_ptr (comp.ctxt,
1392 comp.thread_state_ptr_type, 1472 comp.thread_state_ptr_type,