aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-06-24 13:47:08 +0200
committerAndrea Corallo2020-01-01 11:33:46 +0100
commitdf93780efe61cea82463a96dbac3792fd3eed737 (patch)
tree938395fad7c5ba5f7469336505b6c2e5ed28aa32 /src/comp.c
parenta8c60ea884b835b7a109b735ee82600c7c785c5d (diff)
downloademacs-df93780efe61cea82463a96dbac3792fd3eed737.tar.gz
emacs-df93780efe61cea82463a96dbac3792fd3eed737.zip
full inline car
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c109
1 files changed, 82 insertions, 27 deletions
diff --git a/src/comp.c b/src/comp.c
index 599f8f158b7..e3ec34d5545 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -194,7 +194,10 @@ typedef struct {
194 /* struct Lisp_Cons */ 194 /* struct Lisp_Cons */
195 gcc_jit_struct *lisp_cons_s; 195 gcc_jit_struct *lisp_cons_s;
196 gcc_jit_field *lisp_cons_u; 196 gcc_jit_field *lisp_cons_u;
197 gcc_jit_type *lisp_cons_ptr; 197 gcc_jit_field *lisp_cons_u_s;
198 gcc_jit_field *lisp_cons_u_s_car;
199 gcc_jit_type *lisp_cons_type;
200 gcc_jit_type *lisp_cons_ptr_type;
198 /* struct jmp_buf. */ 201 /* struct jmp_buf. */
199 gcc_jit_struct *jmp_buf_s; 202 gcc_jit_struct *jmp_buf_s;
200 /* struct handler. */ 203 /* struct handler. */
@@ -217,6 +220,7 @@ typedef struct {
217 gcc_jit_field *cast_union_as_i; 220 gcc_jit_field *cast_union_as_i;
218 gcc_jit_field *cast_union_as_b; 221 gcc_jit_field *cast_union_as_b;
219 gcc_jit_field *cast_union_as_c_p; 222 gcc_jit_field *cast_union_as_c_p;
223 gcc_jit_field *cast_union_as_lisp_cons_ptr;
220 gcc_jit_function *func; /* Current function being compiled */ 224 gcc_jit_function *func; /* Current function being compiled */
221 gcc_jit_rvalue *most_positive_fixnum; 225 gcc_jit_rvalue *most_positive_fixnum;
222 gcc_jit_rvalue *most_negative_fixnum; 226 gcc_jit_rvalue *most_negative_fixnum;
@@ -225,6 +229,7 @@ typedef struct {
225 gcc_jit_rvalue *lisp_int0; 229 gcc_jit_rvalue *lisp_int0;
226 gcc_jit_function *pseudovectorp; 230 gcc_jit_function *pseudovectorp;
227 gcc_jit_function *bool_to_lisp_obj; 231 gcc_jit_function *bool_to_lisp_obj;
232 gcc_jit_function *car;
228 basic_block_t *block; /* Current basic block */ 233 basic_block_t *block; /* Current basic block */
229 Lisp_Object func_hash; /* f_name -> gcc_func */ 234 Lisp_Object func_hash; /* f_name -> gcc_func */
230} comp_t; 235} comp_t;
@@ -297,6 +302,8 @@ type_to_cast_field (gcc_jit_type *type)
297 field = comp.cast_union_as_b; 302 field = comp.cast_union_as_b;
298 else if (type == comp.char_ptr_type) 303 else if (type == comp.char_ptr_type)
299 field = comp.cast_union_as_c_p; 304 field = comp.cast_union_as_c_p;
305 else if (type == comp.lisp_cons_ptr_type)
306 field = comp.cast_union_as_lisp_cons_ptr;
300 else 307 else
301 error ("unsopported cast\n"); 308 error ("unsopported cast\n");
302 309
@@ -768,6 +775,8 @@ emit_NILP (gcc_jit_rvalue *x)
768{ 775{
769 return emit_EQ (x, emit_lisp_obj_from_ptr (comp.block, Qnil)); 776 return emit_EQ (x, emit_lisp_obj_from_ptr (comp.block, Qnil));
770} 777}
778
779static gcc_jit_rvalue *
771emit_call_n_ref (const char *f_name, unsigned nargs, 780emit_call_n_ref (const char *f_name, unsigned nargs,
772 gcc_jit_lvalue *base_arg) 781 gcc_jit_lvalue *base_arg)
773{ 782{
@@ -813,8 +822,10 @@ define_lisp_cons (void)
813 gcc_jit_context_new_opaque_struct (comp.ctxt, 822 gcc_jit_context_new_opaque_struct (comp.ctxt,
814 NULL, 823 NULL,
815 "comp_Lisp_Cons"); 824 "comp_Lisp_Cons");
816 comp.lisp_cons_ptr = 825 comp.lisp_cons_type =
817 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.lisp_cons_s)); 826 gcc_jit_struct_as_type (comp.lisp_cons_s);
827 comp.lisp_cons_ptr_type =
828 gcc_jit_type_get_pointer (comp.lisp_cons_type);
818 829
819 gcc_jit_field *cdr_u_fields[] = 830 gcc_jit_field *cdr_u_fields[] =
820 { gcc_jit_context_new_field (comp.ctxt, 831 { gcc_jit_context_new_field (comp.ctxt,
@@ -823,7 +834,7 @@ define_lisp_cons (void)
823 "cdr"), 834 "cdr"),
824 gcc_jit_context_new_field (comp.ctxt, 835 gcc_jit_context_new_field (comp.ctxt,
825 NULL, 836 NULL,
826 comp.lisp_cons_ptr, 837 comp.lisp_cons_ptr_type,
827 "chain") }; 838 "chain") };
828 839
829 gcc_jit_type *cdr_u = 840 gcc_jit_type *cdr_u =
@@ -834,11 +845,12 @@ define_lisp_cons (void)
834 / sizeof (*cdr_u_fields), 845 / sizeof (*cdr_u_fields),
835 cdr_u_fields); 846 cdr_u_fields);
836 847
848 comp.lisp_cons_u_s_car = gcc_jit_context_new_field (comp.ctxt,
849 NULL,
850 comp.lisp_obj_type,
851 "car");
837 gcc_jit_field *cons_s_fields[] = 852 gcc_jit_field *cons_s_fields[] =
838 { gcc_jit_context_new_field (comp.ctxt, 853 { comp.lisp_cons_u_s_car,
839 NULL,
840 comp.lisp_obj_type,
841 "car"),
842 gcc_jit_context_new_field (comp.ctxt, 854 gcc_jit_context_new_field (comp.ctxt,
843 NULL, 855 NULL,
844 cdr_u, 856 cdr_u,
@@ -852,11 +864,13 @@ define_lisp_cons (void)
852 / sizeof (*cons_s_fields), 864 / sizeof (*cons_s_fields),
853 cons_s_fields); 865 cons_s_fields);
854 866
855 gcc_jit_field *cons_u_fields[] = 867 comp.lisp_cons_u_s = gcc_jit_context_new_field (comp.ctxt,
856 { gcc_jit_context_new_field (comp.ctxt,
857 NULL, 868 NULL,
858 gcc_jit_struct_as_type (cons_s), 869 gcc_jit_struct_as_type (cons_s),
859 "s"), 870 "s");
871
872 gcc_jit_field *cons_u_fields[] =
873 { comp.lisp_cons_u_s,
860 gcc_jit_context_new_field ( 874 gcc_jit_context_new_field (
861 comp.ctxt, 875 comp.ctxt,
862 NULL, 876 NULL,
@@ -866,7 +880,7 @@ define_lisp_cons (void)
866 sizeof (struct Lisp_Cons)), 880 sizeof (struct Lisp_Cons)),
867 "align_pad") }; 881 "align_pad") };
868 882
869 gcc_jit_type *cons_u = 883 gcc_jit_type *lisp_cons_u_type =
870 gcc_jit_context_new_union_type (comp.ctxt, 884 gcc_jit_context_new_union_type (comp.ctxt,
871 NULL, 885 NULL,
872 "comp_cons_u", 886 "comp_cons_u",
@@ -877,7 +891,7 @@ define_lisp_cons (void)
877 comp.lisp_cons_u = 891 comp.lisp_cons_u =
878 gcc_jit_context_new_field (comp.ctxt, 892 gcc_jit_context_new_field (comp.ctxt,
879 NULL, 893 NULL,
880 cons_u, 894 lisp_cons_u_type,
881 "u"); 895 "u");
882 gcc_jit_struct_set_fields (comp.lisp_cons_s, 896 gcc_jit_struct_set_fields (comp.lisp_cons_s,
883 NULL, 1, &comp.lisp_cons_u); 897 NULL, 1, &comp.lisp_cons_u);
@@ -1087,29 +1101,30 @@ define_CAR (void)
1087 1, 1101 1,
1088 &param, 1102 &param,
1089 0); 1103 0);
1104 gcc_jit_rvalue *c = gcc_jit_param_as_rvalue (param);
1090 gcc_jit_block *initial_block = 1105 gcc_jit_block *initial_block =
1091 gcc_jit_function_new_block (comp.car, "CAR_initial_block"); 1106 gcc_jit_function_new_block (comp.car, "CAR_initial_block");
1092 1107
1093 /* gcc_jit_block *is_cons_b = */ 1108 gcc_jit_block *is_cons_b =
1094 /* gcc_jit_function_new_block (comp.pseudovectorp, "is_cons"); */ 1109 gcc_jit_function_new_block (comp.car, "is_cons");
1095 1110
1096 /* gcc_jit_block *not_a_cons_b = */ 1111 gcc_jit_block *not_a_cons_b =
1097 /* gcc_jit_function_new_block (comp.pseudovectorp, "not_a_cons"); */ 1112 gcc_jit_function_new_block (comp.car, "not_a_cons");
1098 1113
1099 1114
1100 /* Set current context as needed */ 1115 /* Set current context as needed */
1101 basic_block_t block = { .gcc_bb = initial_block, 1116 basic_block_t block = { .gcc_bb = initial_block,
1102 .terminated = false }; 1117 .terminated = false };
1103 comp.block = █ 1118 comp.block = █
1104 comp.func = comp.car; 1119 comp.func = comp.car;
1105 1120
1106 /* emit_cond_jump ( */ 1121 emit_cond_jump (
1107 /* emit_cast (comp.bool_type, */ 1122 emit_cast (comp.bool_type,
1108 /* emit_CONSP (gcc_jit_param_as_rvalue (param))), */ 1123 emit_CONSP (c)),
1109 /* is_cons_b, */ 1124 is_cons_b,
1110 /* not_a_cons_b); */ 1125 not_a_cons_b);
1111 1126
1112 /* comp.block->gcc_bb = is_cons_b; */ 1127 comp.block->gcc_bb = is_cons_b;
1113 1128
1114 gcc_jit_rvalue *res_car = 1129 gcc_jit_rvalue *res_car =
1115 /* c->u.s.car */ 1130 /* c->u.s.car */
@@ -1119,7 +1134,7 @@ define_CAR (void)
1119 /* c->u */ 1134 /* c->u */
1120 gcc_jit_lvalue_as_rvalue ( 1135 gcc_jit_lvalue_as_rvalue (
1121 gcc_jit_rvalue_dereference_field ( 1136 gcc_jit_rvalue_dereference_field (
1122 emit_rval_XCONS (gcc_jit_param_as_rvalue (param)), 1137 emit_rval_XCONS (c),
1123 NULL, 1138 NULL,
1124 comp.lisp_cons_u)), 1139 comp.lisp_cons_u)),
1125 NULL, 1140 NULL,
@@ -1127,10 +1142,37 @@ define_CAR (void)
1127 NULL, 1142 NULL,
1128 comp.lisp_cons_u_s_car); 1143 comp.lisp_cons_u_s_car);
1129 1144
1130 gcc_jit_block_end_with_return (initial_block, 1145 gcc_jit_block_end_with_return (comp.block->gcc_bb,
1131 NULL, 1146 NULL,
1132 res_car); 1147 res_car);
1133 1148
1149 comp.block->gcc_bb = not_a_cons_b;
1150
1151 gcc_jit_block *is_nil_b =
1152 gcc_jit_function_new_block (comp.car, "is_nil");
1153 gcc_jit_block *not_nil_b =
1154 gcc_jit_function_new_block (comp.car, "not_nil");
1155
1156 emit_cond_jump (emit_NILP (c),
1157 is_nil_b,
1158 not_nil_b);
1159
1160 comp.block->gcc_bb = is_nil_b;
1161 gcc_jit_block_end_with_return (comp.block->gcc_bb,
1162 NULL,
1163 emit_lisp_obj_from_ptr (comp.block, Qnil));
1164
1165 comp.block->gcc_bb = not_nil_b;
1166 gcc_jit_rvalue *wrong_type_args[] =
1167 { emit_lisp_obj_from_ptr (comp.block, Qlistp), c };
1168
1169 gcc_jit_block_add_eval (comp.block->gcc_bb,
1170 NULL,
1171 emit_call ("wrong_type_argument",
1172 comp.lisp_obj_type, 2, wrong_type_args));
1173 gcc_jit_block_end_with_return (comp.block->gcc_bb,
1174 NULL,
1175 emit_lisp_obj_from_ptr (comp.block, Qnil));
1134} 1176}
1135 1177
1136/* Declare a substitute for PSEUDOVECTORP as always inlined function. */ 1178/* Declare a substitute for PSEUDOVECTORP as always inlined function. */
@@ -1496,6 +1538,10 @@ init_comp (int opt_level)
1496 gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, 1538 gcc_jit_context_new_rvalue_from_ptr (comp.ctxt,
1497 comp.thread_state_ptr_type, 1539 comp.thread_state_ptr_type,
1498 current_thread); 1540 current_thread);
1541
1542 /* Define inline functions. */
1543
1544 define_CAR();
1499 define_PSEUDOVECTORP (); 1545 define_PSEUDOVECTORP ();
1500 define_bool_to_lisp_obj (); 1546 define_bool_to_lisp_obj ();
1501} 1547}
@@ -1911,7 +1957,16 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1911 CASE_CALL_N (eq, 2); 1957 CASE_CALL_N (eq, 2);
1912 CASE_CALL_N (memq, 1); 1958 CASE_CALL_N (memq, 1);
1913 CASE_CALL_N (not, 1); 1959 CASE_CALL_N (not, 1);
1914 CASE_CALL_N (car, 1); 1960
1961 case Bcar:
1962 POP1;
1963 res = gcc_jit_context_new_call (comp.ctxt,
1964 NULL,
1965 comp.car,
1966 1, args);
1967 PUSH_RVAL (res);
1968 break;
1969
1915 CASE_CALL_N (cdr, 1); 1970 CASE_CALL_N (cdr, 1);
1916 CASE_CALL_N (cons, 2); 1971 CASE_CALL_N (cons, 2);
1917 1972