diff options
| author | Andrea Corallo | 2019-06-23 19:16:10 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:44 +0100 |
| commit | 97b39deeeaa55c7cfed05cfb2ae57e2323a7c69c (patch) | |
| tree | 2f6697d786cdbb21ef1dfddaa5996f254e819ce0 /src | |
| parent | 5637eae4a4a1be757f5f203c7e08ec5cf1a69c03 (diff) | |
| download | emacs-97b39deeeaa55c7cfed05cfb2ae57e2323a7c69c.tar.gz emacs-97b39deeeaa55c7cfed05cfb2ae57e2323a7c69c.zip | |
remove scratch call mechanism
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 118 |
1 files changed, 30 insertions, 88 deletions
diff --git a/src/comp.c b/src/comp.c index 296f215cd27..154a1a9028e 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -36,10 +36,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 36 | 36 | ||
| 37 | #define MAX_FUN_NAME 256 | 37 | #define MAX_FUN_NAME 256 |
| 38 | 38 | ||
| 39 | /* Max number of args we are able to handle while emitting function calls. */ | ||
| 40 | |||
| 41 | #define MAX_ARGS 16 | ||
| 42 | |||
| 43 | #define DISASS_FILE_NAME "emacs-asm.s" | 39 | #define DISASS_FILE_NAME "emacs-asm.s" |
| 44 | 40 | ||
| 45 | #define CHECK_STACK \ | 41 | #define CHECK_STACK \ |
| @@ -147,13 +143,15 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 147 | EMIT_CALL_N (STR(F##name), nargs); \ | 143 | EMIT_CALL_N (STR(F##name), nargs); \ |
| 148 | break | 144 | break |
| 149 | 145 | ||
| 150 | /* Emit calls to functions with prototype (ptrdiff_t nargs, Lisp_Object *args) | 146 | /* |
| 151 | This is done aggregating args into the scratch_call_area. */ | 147 | Emit calls to functions with prototype (ptrdiff_t nargs, Lisp_Object *args). |
| 148 | This is done by passing a reference to the first obj involved on the stack. | ||
| 149 | */ | ||
| 152 | 150 | ||
| 153 | #define EMIT_SCRATCH_CALL_N(name, nargs) \ | 151 | #define EMIT_CALL_N_REF(name, nargs) \ |
| 154 | do { \ | 152 | do { \ |
| 155 | pop (nargs, &stack, args); \ | 153 | DISCARD (nargs); \ |
| 156 | res = emit_scratch_callN (name, nargs, args); \ | 154 | res = emit_call_n_ref (name, nargs, *stack); \ |
| 157 | PUSH_RVAL (res); \ | 155 | PUSH_RVAL (res); \ |
| 158 | } while (0) | 156 | } while (0) |
| 159 | 157 | ||
| @@ -214,7 +212,6 @@ typedef struct { | |||
| 214 | gcc_jit_field *cast_union_as_i; | 212 | gcc_jit_field *cast_union_as_i; |
| 215 | gcc_jit_field *cast_union_as_b; | 213 | gcc_jit_field *cast_union_as_b; |
| 216 | gcc_jit_function *func; /* Current function being compiled */ | 214 | gcc_jit_function *func; /* Current function being compiled */ |
| 217 | gcc_jit_rvalue *scratch; /* Will point to scratch_call_area */ | ||
| 218 | gcc_jit_rvalue *most_positive_fixnum; | 215 | gcc_jit_rvalue *most_positive_fixnum; |
| 219 | gcc_jit_rvalue *most_negative_fixnum; | 216 | gcc_jit_rvalue *most_negative_fixnum; |
| 220 | gcc_jit_rvalue *one; | 217 | gcc_jit_rvalue *one; |
| @@ -228,8 +225,6 @@ typedef struct { | |||
| 228 | 225 | ||
| 229 | static comp_t comp; | 226 | static comp_t comp; |
| 230 | 227 | ||
| 231 | Lisp_Object scratch_call_area[MAX_ARGS]; | ||
| 232 | |||
| 233 | FILE *logfile = NULL; | 228 | FILE *logfile = NULL; |
| 234 | 229 | ||
| 235 | /* The result of one function compilation. */ | 230 | /* The result of one function compilation. */ |
| @@ -722,60 +717,15 @@ emit_lisp_obj_from_ptr (basic_block_t *block, void *p) | |||
| 722 | } | 717 | } |
| 723 | 718 | ||
| 724 | static gcc_jit_rvalue * | 719 | static gcc_jit_rvalue * |
| 725 | emit_scratch_callN (const char *f_name, unsigned nargs, gcc_jit_rvalue **args) | 720 | emit_call_n_ref (const char *f_name, unsigned nargs, |
| 721 | gcc_jit_lvalue *base_arg) | ||
| 726 | { | 722 | { |
| 727 | /* Here we set all the pointers into the scratch call area. */ | 723 | gcc_jit_rvalue *arguments[2] = |
| 728 | /* TODO: distinguish primitives for faster calling convention. */ | 724 | { gcc_jit_context_new_rvalue_from_int(comp.ctxt, |
| 729 | |||
| 730 | /* | ||
| 731 | Lisp_Object *p; | ||
| 732 | p = scratch_call_area; | ||
| 733 | |||
| 734 | p[0] = nargs; | ||
| 735 | p[1] = 0x...; | ||
| 736 | . | ||
| 737 | . | ||
| 738 | . | ||
| 739 | p[n] = 0x...; | ||
| 740 | */ | ||
| 741 | |||
| 742 | gcc_jit_block_add_comment (comp.block->gcc_bb, | ||
| 743 | NULL, | ||
| 744 | format_string ("calling %s", f_name)); | ||
| 745 | |||
| 746 | gcc_jit_lvalue *p = | ||
| 747 | gcc_jit_function_new_local(comp.func, | ||
| 748 | NULL, | ||
| 749 | gcc_jit_type_get_pointer (comp.lisp_obj_type), | ||
| 750 | "p"); | ||
| 751 | |||
| 752 | gcc_jit_block_add_assignment(comp.block->gcc_bb, NULL, | ||
| 753 | p, | ||
| 754 | comp.scratch); | ||
| 755 | |||
| 756 | for (int i = 0; i < nargs; i++) { | ||
| 757 | gcc_jit_rvalue *idx = | ||
| 758 | gcc_jit_context_new_rvalue_from_int ( | ||
| 759 | comp.ctxt, | ||
| 760 | gcc_jit_context_get_type(comp.ctxt, | ||
| 761 | GCC_JIT_TYPE_UNSIGNED_INT), | ||
| 762 | i); | ||
| 763 | gcc_jit_block_add_assignment ( | ||
| 764 | comp.block->gcc_bb, | ||
| 765 | NULL, | ||
| 766 | gcc_jit_context_new_array_access (comp.ctxt, | ||
| 767 | NULL, | ||
| 768 | gcc_jit_lvalue_as_rvalue(p), | ||
| 769 | idx), | ||
| 770 | args[i]); | ||
| 771 | } | ||
| 772 | |||
| 773 | args[0] = gcc_jit_context_new_rvalue_from_int(comp.ctxt, | ||
| 774 | comp.ptrdiff_type, | 725 | comp.ptrdiff_type, |
| 775 | nargs); | 726 | nargs), |
| 776 | args[1] = comp.scratch; | 727 | gcc_jit_lvalue_get_address (base_arg, NULL) }; |
| 777 | 728 | return emit_call (f_name, comp.lisp_obj_type, 2, arguments); | |
| 778 | return emit_call (f_name, comp.lisp_obj_type, 2, args); | ||
| 779 | } | 729 | } |
| 780 | 730 | ||
| 781 | /* opaque jmp_buf definition */ | 731 | /* opaque jmp_buf definition */ |
| @@ -1288,14 +1238,6 @@ init_comp (int opt_level) | |||
| 1288 | 1238 | ||
| 1289 | comp.ptrdiff_type = gcc_jit_context_get_type (comp.ctxt, ptrdiff_t_gcc); | 1239 | comp.ptrdiff_type = gcc_jit_context_get_type (comp.ctxt, ptrdiff_t_gcc); |
| 1290 | 1240 | ||
| 1291 | comp.scratch = | ||
| 1292 | gcc_jit_lvalue_get_address( | ||
| 1293 | gcc_jit_context_new_global (comp.ctxt, NULL, | ||
| 1294 | GCC_JIT_GLOBAL_IMPORTED, | ||
| 1295 | comp.lisp_obj_type, | ||
| 1296 | "scratch_call_area"), | ||
| 1297 | NULL); | ||
| 1298 | |||
| 1299 | comp.func_hash = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt); | 1241 | comp.func_hash = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt); |
| 1300 | 1242 | ||
| 1301 | define_jmp_buf (); | 1243 | define_jmp_buf (); |
| @@ -1557,8 +1499,8 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 1557 | docall: | 1499 | docall: |
| 1558 | { | 1500 | { |
| 1559 | ptrdiff_t nargs = op + 1; | 1501 | ptrdiff_t nargs = op + 1; |
| 1560 | pop (nargs, &stack, args); | 1502 | DISCARD (nargs); |
| 1561 | res = emit_scratch_callN ("Ffuncall", nargs, args); | 1503 | res = emit_call_n_ref ("Ffuncall", nargs, *stack); |
| 1562 | PUSH_RVAL (res); | 1504 | PUSH_RVAL (res); |
| 1563 | break; | 1505 | break; |
| 1564 | } | 1506 | } |
| @@ -1763,17 +1705,17 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 1763 | CASE_CALL_NARGS (substring, 3); | 1705 | CASE_CALL_NARGS (substring, 3); |
| 1764 | 1706 | ||
| 1765 | CASE (Bconcat2) | 1707 | CASE (Bconcat2) |
| 1766 | EMIT_SCRATCH_CALL_N ("Fconcat", 2); | 1708 | EMIT_CALL_N_REF ("Fconcat", 2); |
| 1767 | break; | 1709 | break; |
| 1768 | CASE (Bconcat3) | 1710 | CASE (Bconcat3) |
| 1769 | EMIT_SCRATCH_CALL_N ("Fconcat", 3); | 1711 | EMIT_CALL_N_REF ("Fconcat", 3); |
| 1770 | break; | 1712 | break; |
| 1771 | CASE (Bconcat4) | 1713 | CASE (Bconcat4) |
| 1772 | EMIT_SCRATCH_CALL_N ("Fconcat", 4); | 1714 | EMIT_CALL_N_REF ("Fconcat", 4); |
| 1773 | break; | 1715 | break; |
| 1774 | CASE (BconcatN) | 1716 | CASE (BconcatN) |
| 1775 | op = FETCH; | 1717 | op = FETCH; |
| 1776 | EMIT_SCRATCH_CALL_N ("Fconcat", op); | 1718 | EMIT_CALL_N_REF ("Fconcat", op); |
| 1777 | break; | 1719 | break; |
| 1778 | 1720 | ||
| 1779 | CASE (Bsub1) | 1721 | CASE (Bsub1) |
| @@ -1917,7 +1859,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 1917 | break; | 1859 | break; |
| 1918 | 1860 | ||
| 1919 | CASE (Bdiff) | 1861 | CASE (Bdiff) |
| 1920 | EMIT_SCRATCH_CALL_N ("Fminus", 2); | 1862 | EMIT_CALL_N_REF ("Fminus", 2); |
| 1921 | break; | 1863 | break; |
| 1922 | 1864 | ||
| 1923 | CASE (Bnegate) | 1865 | CASE (Bnegate) |
| @@ -1966,7 +1908,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 1966 | basic_block_t bb_orig = *comp.block; | 1908 | basic_block_t bb_orig = *comp.block; |
| 1967 | 1909 | ||
| 1968 | comp.block->gcc_bb = negate_fcall_block; | 1910 | comp.block->gcc_bb = negate_fcall_block; |
| 1969 | EMIT_SCRATCH_CALL_N ("Fminus", 1); | 1911 | EMIT_CALL_N_REF ("Fminus", 1); |
| 1970 | *comp.block = bb_orig; | 1912 | *comp.block = bb_orig; |
| 1971 | 1913 | ||
| 1972 | gcc_jit_block_end_with_jump (negate_inline_block, NULL, | 1914 | gcc_jit_block_end_with_jump (negate_inline_block, NULL, |
| @@ -1976,16 +1918,16 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 1976 | } | 1918 | } |
| 1977 | break; | 1919 | break; |
| 1978 | CASE (Bplus) | 1920 | CASE (Bplus) |
| 1979 | EMIT_SCRATCH_CALL_N ("Fplus", 2); | 1921 | EMIT_CALL_N_REF ("Fplus", 2); |
| 1980 | break; | 1922 | break; |
| 1981 | CASE (Bmax) | 1923 | CASE (Bmax) |
| 1982 | EMIT_SCRATCH_CALL_N ("Fmax", 2); | 1924 | EMIT_CALL_N_REF ("Fmax", 2); |
| 1983 | break; | 1925 | break; |
| 1984 | CASE (Bmin) | 1926 | CASE (Bmin) |
| 1985 | EMIT_SCRATCH_CALL_N ("Fmin", 2); | 1927 | EMIT_CALL_N_REF ("Fmin", 2); |
| 1986 | break; | 1928 | break; |
| 1987 | CASE (Bmult) | 1929 | CASE (Bmult) |
| 1988 | EMIT_SCRATCH_CALL_N ("Ftimes", 2); | 1930 | EMIT_CALL_N_REF ("Ftimes", 2); |
| 1989 | break; | 1931 | break; |
| 1990 | CASE (Bpoint) | 1932 | CASE (Bpoint) |
| 1991 | args[0] = | 1933 | args[0] = |
| @@ -2002,7 +1944,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 2002 | CASE_CALL_NARGS (goto_char, 1); | 1944 | CASE_CALL_NARGS (goto_char, 1); |
| 2003 | 1945 | ||
| 2004 | CASE (Binsert) | 1946 | CASE (Binsert) |
| 2005 | EMIT_SCRATCH_CALL_N ("Finsert", 1); | 1947 | EMIT_CALL_N_REF ("Finsert", 1); |
| 2006 | break; | 1948 | break; |
| 2007 | 1949 | ||
| 2008 | CASE (Bpoint_max) | 1950 | CASE (Bpoint_max) |
| @@ -2231,11 +2173,11 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 2231 | break; | 2173 | break; |
| 2232 | 2174 | ||
| 2233 | CASE (Bnconc) | 2175 | CASE (Bnconc) |
| 2234 | EMIT_SCRATCH_CALL_N ("Fnconc", 2); | 2176 | EMIT_CALL_N_REF ("Fnconc", 2); |
| 2235 | break; | 2177 | break; |
| 2236 | 2178 | ||
| 2237 | CASE (Bquo) | 2179 | CASE (Bquo) |
| 2238 | EMIT_SCRATCH_CALL_N ("Fquo", 2); | 2180 | EMIT_CALL_N_REF ("Fquo", 2); |
| 2239 | break; | 2181 | break; |
| 2240 | 2182 | ||
| 2241 | CASE_CALL_NARGS (rem, 2); | 2183 | CASE_CALL_NARGS (rem, 2); |
| @@ -2312,7 +2254,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 2312 | 2254 | ||
| 2313 | CASE (BinsertN) | 2255 | CASE (BinsertN) |
| 2314 | op = FETCH; | 2256 | op = FETCH; |
| 2315 | EMIT_SCRATCH_CALL_N ("Finsert", op); | 2257 | EMIT_CALL_N_REF ("Finsert", op); |
| 2316 | break; | 2258 | break; |
| 2317 | 2259 | ||
| 2318 | CASE (Bstack_set) | 2260 | CASE (Bstack_set) |