aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-09-04 23:12:34 +0200
committerAndrea Corallo2020-01-01 11:37:43 +0100
commit43172dd01fc7344f71f6e1d92fe051942f360355 (patch)
tree1c614a8f5213e7e1f6bc8992df3ff263ef6f39dc /src/comp.c
parent5d6e42e013caf236f5f1c7a8bca6d76916bb404a (diff)
downloademacs-43172dd01fc7344f71f6e1d92fe051942f360355.tar.gz
emacs-43172dd01fc7344f71f6e1d92fe051942f360355.zip
fix relocs for all inliners
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c103
1 files changed, 46 insertions, 57 deletions
diff --git a/src/comp.c b/src/comp.c
index 00ed4172783..4f40d83f82b 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -1,4 +1,4 @@
1/* Compile byte code produced by bytecomp.el into native code. 1/* Compile elisp into native code.
2 Copyright (C) 2019 Free Software Foundation, Inc. 2 Copyright (C) 2019 Free Software Foundation, Inc.
3 3
4Author: Andrea Corallo <akrl@sdf.org> 4Author: Andrea Corallo <akrl@sdf.org>
@@ -795,42 +795,30 @@ emit_make_fixnum (gcc_jit_rvalue *obj)
795 return gcc_jit_lvalue_as_rvalue (res); 795 return gcc_jit_lvalue_as_rvalue (res);
796} 796}
797 797
798/* Construct fill and return a lisp object form a raw pointer. */
799static gcc_jit_rvalue * 798static gcc_jit_rvalue *
800emit_lisp_obj_from_ptr (void *p) 799emit_const_lisp_obj (Lisp_Object obj)
801{ 800{
802 static unsigned i; 801 emit_comment ("const lisp obj");
803 emit_comment ("lisp_obj_from_ptr");
804
805 gcc_jit_lvalue *lisp_obj =
806 gcc_jit_function_new_local (comp.func,
807 NULL,
808 comp.lisp_obj_type,
809 format_string ("lisp_obj_from_ptr_%u", i++));
810 gcc_jit_rvalue *void_ptr =
811 gcc_jit_context_new_rvalue_from_ptr(comp.ctxt,
812 comp.void_ptr_type,
813 p);
814
815 if (SYMBOLP (p))
816 emit_comment (
817 format_string ("Symbol %s",
818 (char *) SDATA (SYMBOL_NAME (p))));
819
820 gcc_jit_block_add_assignment (comp.block,
821 NULL,
822 emit_lval_XLP (lisp_obj),
823 void_ptr);
824 802
825 return gcc_jit_lvalue_as_rvalue (lisp_obj); 803 Lisp_Object d_reloc_idx = FUNCALL1 (comp-ctxt-data-relocs-idx, Vcomp_ctxt);
804 ptrdiff_t reloc_fixn = XFIXNUM (Fgethash (obj, d_reloc_idx, Qnil));
805 gcc_jit_rvalue *reloc_n =
806 gcc_jit_context_new_rvalue_from_int (comp.ctxt,
807 comp.ptrdiff_type,
808 reloc_fixn);
809 return
810 gcc_jit_lvalue_as_rvalue (
811 gcc_jit_context_new_array_access (comp.ctxt,
812 NULL,
813 comp.data_relocs,
814 reloc_n));
826} 815}
827 816
828static gcc_jit_rvalue * 817static gcc_jit_rvalue *
829emit_NILP (gcc_jit_rvalue *x) 818emit_NILP (gcc_jit_rvalue *x)
830{ 819{
831 emit_comment ("NILP"); 820 emit_comment ("NILP");
832 821 return emit_EQ (x, emit_const_lisp_obj (Qnil));
833 return emit_EQ (x, emit_lisp_obj_from_ptr (Qnil));
834} 822}
835 823
836static gcc_jit_rvalue * 824static gcc_jit_rvalue *
@@ -933,7 +921,7 @@ emit_CHECK_CONS (gcc_jit_rvalue *x)
933 921
934 gcc_jit_rvalue *args[] = 922 gcc_jit_rvalue *args[] =
935 { emit_CONSP (x), 923 { emit_CONSP (x),
936 emit_lisp_obj_from_ptr (Qconsp), 924 emit_const_lisp_obj (Qconsp),
937 x }; 925 x };
938 926
939 gcc_jit_block_add_eval ( 927 gcc_jit_block_add_eval (
@@ -1025,27 +1013,16 @@ emit_PURE_P (gcc_jit_rvalue *ptr)
1025static gcc_jit_rvalue * 1013static gcc_jit_rvalue *
1026emit_mvar_val (Lisp_Object mvar) 1014emit_mvar_val (Lisp_Object mvar)
1027{ 1015{
1028 if (CONST_PROP_MAX) 1016
1029 { 1017 if (NILP (FUNCALL1 (comp-mvar-slot, mvar)))
1030 if (NILP (FUNCALL1 (comp-mvar-const-vld, mvar)))
1031 return
1032 gcc_jit_lvalue_as_rvalue(
1033 comp.frame[XFIXNUM (FUNCALL1 (comp-mvar-slot, mvar))]);
1034 else
1035 return emit_lisp_obj_from_ptr (FUNCALL1 (comp-mvar-constant, mvar));
1036 }
1037 else
1038 { 1018 {
1039 if (NILP (FUNCALL1 (comp-mvar-slot, mvar))) 1019 /* If the slot is not specified this must be a constant. */
1040 { 1020 eassert (!NILP (FUNCALL1 (comp-mvar-const-vld, mvar)));
1041 /* If the slot is not specified this must be a constant. */ 1021 return emit_const_lisp_obj (FUNCALL1 (comp-mvar-constant, mvar));
1042 eassert (!NILP (FUNCALL1 (comp-mvar-const-vld, mvar)));
1043 return emit_lisp_obj_from_ptr (FUNCALL1 (comp-mvar-constant, mvar));
1044 }
1045 return
1046 gcc_jit_lvalue_as_rvalue(
1047 comp.frame[XFIXNUM (FUNCALL1 (comp-mvar-slot, mvar))]);
1048 } 1022 }
1023
1024 return
1025 gcc_jit_lvalue_as_rvalue(comp.frame[XFIXNUM (FUNCALL1 (comp-mvar-slot, mvar))]);
1049} 1026}
1050 1027
1051static gcc_jit_rvalue * 1028static gcc_jit_rvalue *
@@ -1063,7 +1040,7 @@ emit_set_internal (Lisp_Object args)
1063 gcc_jit_rvalue *gcc_args[4]; 1040 gcc_jit_rvalue *gcc_args[4];
1064 FOR_EACH_TAIL (args) 1041 FOR_EACH_TAIL (args)
1065 gcc_args[i++] = emit_mvar_val (XCAR (args)); 1042 gcc_args[i++] = emit_mvar_val (XCAR (args));
1066 gcc_args[2] = emit_lisp_obj_from_ptr (Qnil); 1043 gcc_args[2] = emit_const_lisp_obj (Qnil);
1067 gcc_args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, 1044 gcc_args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt,
1068 comp.int_type, 1045 comp.int_type,
1069 SET_INTERNAL_SET); 1046 SET_INTERNAL_SET);
@@ -1617,12 +1594,22 @@ emit_static_object (const char *name, Lisp_Object obj)
1617 gcc_jit_block_end_with_return (block, NULL, res); 1594 gcc_jit_block_end_with_return (block, NULL, res);
1618} 1595}
1619 1596
1597static void
1598declare_runtime_imported_data (void)
1599{
1600 /* Imported symbols by inliner functions. */
1601 FUNCALL1 (comp-add-const-to-relocs, Qnil);
1602 FUNCALL1 (comp-add-const-to-relocs, Qt);
1603 FUNCALL1 (comp-add-const-to-relocs, Qconsp);
1604 FUNCALL1 (comp-add-const-to-relocs, Qlistp);
1605}
1606
1620/* 1607/*
1621 Declare as imported all the functions that are requested from the runtime. 1608 Declare as imported all the functions that are requested from the runtime.
1622 These are either subrs or not. 1609 These are either subrs or not.
1623*/ 1610*/
1624static Lisp_Object 1611static Lisp_Object
1625declare_runtime_imported (void) 1612declare_runtime_imported_funcs (void)
1626{ 1613{
1627 /* For subr imported by the runtime we rely on the standard mechanism in place 1614 /* For subr imported by the runtime we rely on the standard mechanism in place
1628 for functions imported by lisp code. */ 1615 for functions imported by lisp code. */
@@ -1684,11 +1671,13 @@ This emit the code needed by every compilation unit to be loaded.
1684static void 1671static void
1685emit_ctxt_code (void) 1672emit_ctxt_code (void)
1686{ 1673{
1674 declare_runtime_imported_data ();
1687 /* Imported objects. */ 1675 /* Imported objects. */
1688 Lisp_Object d_reloc = FUNCALL1 (comp-ctxt-data-relocs, Vcomp_ctxt);
1689 EMACS_UINT d_reloc_len = 1676 EMACS_UINT d_reloc_len =
1690 XFIXNUM (FUNCALL1 (hash-table-count, 1677 XFIXNUM (FUNCALL1 (hash-table-count,
1691 FUNCALL1 (comp-ctxt-data-relocs-idx, Vcomp_ctxt))); 1678 FUNCALL1 (comp-ctxt-data-relocs-idx, Vcomp_ctxt)));
1679 Lisp_Object d_reloc = Freverse (FUNCALL1 (comp-ctxt-data-relocs-l, Vcomp_ctxt));
1680 d_reloc = Fvconcat (1, &d_reloc);
1692 1681
1693 comp.data_relocs = 1682 comp.data_relocs =
1694 gcc_jit_lvalue_as_rvalue( 1683 gcc_jit_lvalue_as_rvalue(
@@ -1705,7 +1694,7 @@ emit_ctxt_code (void)
1705 emit_static_object (TEXT_DATA_RELOC_SYM, d_reloc); 1694 emit_static_object (TEXT_DATA_RELOC_SYM, d_reloc);
1706 1695
1707 /* Imported functions from non Lisp code. */ 1696 /* Imported functions from non Lisp code. */
1708 Lisp_Object f_runtime = declare_runtime_imported (); 1697 Lisp_Object f_runtime = declare_runtime_imported_funcs ();
1709 EMACS_UINT f_reloc_len = XFIXNUM (Flength (f_runtime)); 1698 EMACS_UINT f_reloc_len = XFIXNUM (Flength (f_runtime));
1710 1699
1711 /* Imported subrs. */ 1700 /* Imported subrs. */
@@ -2232,11 +2221,11 @@ define_CAR_CDR (void)
2232 comp.block = is_nil_b; 2221 comp.block = is_nil_b;
2233 gcc_jit_block_end_with_return (comp.block, 2222 gcc_jit_block_end_with_return (comp.block,
2234 NULL, 2223 NULL,
2235 emit_lisp_obj_from_ptr (Qnil)); 2224 emit_const_lisp_obj (Qnil));
2236 2225
2237 comp.block = not_nil_b; 2226 comp.block = not_nil_b;
2238 gcc_jit_rvalue *wrong_type_args[] = 2227 gcc_jit_rvalue *wrong_type_args[] =
2239 { emit_lisp_obj_from_ptr (Qlistp), c }; 2228 { emit_const_lisp_obj (Qlistp), c };
2240 2229
2241 gcc_jit_block_add_eval (comp.block, 2230 gcc_jit_block_add_eval (comp.block,
2242 NULL, 2231 NULL,
@@ -2244,7 +2233,7 @@ define_CAR_CDR (void)
2244 comp.void_type, 2, wrong_type_args)); 2233 comp.void_type, 2, wrong_type_args));
2245 gcc_jit_block_end_with_return (comp.block, 2234 gcc_jit_block_end_with_return (comp.block,
2246 NULL, 2235 NULL,
2247 emit_lisp_obj_from_ptr (Qnil)); 2236 emit_const_lisp_obj (Qnil));
2248 f = comp.cdr; 2237 f = comp.cdr;
2249 param = cdr_param; 2238 param = cdr_param;
2250 } 2239 }
@@ -2604,12 +2593,12 @@ define_bool_to_lisp_obj (void)
2604 comp.block = ret_t_block; 2593 comp.block = ret_t_block;
2605 gcc_jit_block_end_with_return (ret_t_block, 2594 gcc_jit_block_end_with_return (ret_t_block,
2606 NULL, 2595 NULL,
2607 emit_lisp_obj_from_ptr (Qt)); 2596 emit_const_lisp_obj (Qt));
2608 2597
2609 comp.block = ret_nil_block; 2598 comp.block = ret_nil_block;
2610 gcc_jit_block_end_with_return (ret_nil_block, 2599 gcc_jit_block_end_with_return (ret_nil_block,
2611 NULL, 2600 NULL,
2612 emit_lisp_obj_from_ptr (Qnil)); 2601 emit_const_lisp_obj (Qnil));
2613 2602
2614} 2603}
2615 2604