diff options
| author | Andrea Corallo | 2019-06-30 10:42:13 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:47 +0100 |
| commit | dc963cf0c8a6f009bc3f2ddbb8224b57ded53339 (patch) | |
| tree | ff529257eb314baad4ae925124182fc6a6acb9f1 /src/comp.c | |
| parent | b5b0e63bbc23a6584e5aaa49861a37b832a0def3 (diff) | |
| download | emacs-dc963cf0c8a6f009bc3f2ddbb8224b57ded53339.tar.gz emacs-dc963cf0c8a6f009bc3f2ddbb8224b57ded53339.zip | |
inline setcdr support
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 160 |
1 files changed, 113 insertions, 47 deletions
diff --git a/src/comp.c b/src/comp.c index 538169c0b2a..f31be0426f1 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -254,6 +254,7 @@ typedef struct { | |||
| 254 | gcc_jit_function *car; | 254 | gcc_jit_function *car; |
| 255 | gcc_jit_function *cdr; | 255 | gcc_jit_function *cdr; |
| 256 | gcc_jit_function *setcar; | 256 | gcc_jit_function *setcar; |
| 257 | gcc_jit_function *setcdr; | ||
| 257 | gcc_jit_function *check_type; | 258 | gcc_jit_function *check_type; |
| 258 | gcc_jit_function *check_impure; | 259 | gcc_jit_function *check_impure; |
| 259 | basic_block_t *block; /* Current basic block */ | 260 | basic_block_t *block; /* Current basic block */ |
| @@ -918,6 +919,31 @@ emit_XCDR (gcc_jit_rvalue *c) | |||
| 918 | comp.lisp_cons_u_s_u_cdr); | 919 | comp.lisp_cons_u_s_u_cdr); |
| 919 | } | 920 | } |
| 920 | 921 | ||
| 922 | static gcc_jit_lvalue * | ||
| 923 | emit_lval_XCDR (gcc_jit_rvalue *c) | ||
| 924 | { | ||
| 925 | emit_comment ("lval_XCDR"); | ||
| 926 | |||
| 927 | /* XCONS (c)->u.s.u.cdr */ | ||
| 928 | return | ||
| 929 | gcc_jit_lvalue_access_field ( | ||
| 930 | /* XCONS (c)->u.s.u */ | ||
| 931 | gcc_jit_lvalue_access_field ( | ||
| 932 | /* XCONS (c)->u.s */ | ||
| 933 | gcc_jit_lvalue_access_field ( | ||
| 934 | /* XCONS (c)->u */ | ||
| 935 | gcc_jit_rvalue_dereference_field ( | ||
| 936 | emit_XCONS (c), | ||
| 937 | NULL, | ||
| 938 | comp.lisp_cons_u), | ||
| 939 | NULL, | ||
| 940 | comp.lisp_cons_u_s), | ||
| 941 | NULL, | ||
| 942 | comp.lisp_cons_u_s_u), | ||
| 943 | NULL, | ||
| 944 | comp.lisp_cons_u_s_u_cdr); | ||
| 945 | } | ||
| 946 | |||
| 921 | static void | 947 | static void |
| 922 | emit_CHECK_CONS (gcc_jit_rvalue *x) | 948 | emit_CHECK_CONS (gcc_jit_rvalue *x) |
| 923 | { | 949 | { |
| @@ -946,6 +972,14 @@ emit_car_addr (gcc_jit_rvalue *c) | |||
| 946 | return gcc_jit_lvalue_get_address (emit_lval_XCAR (c), NULL); | 972 | return gcc_jit_lvalue_get_address (emit_lval_XCAR (c), NULL); |
| 947 | } | 973 | } |
| 948 | 974 | ||
| 975 | static gcc_jit_rvalue * | ||
| 976 | emit_cdr_addr (gcc_jit_rvalue *c) | ||
| 977 | { | ||
| 978 | emit_comment ("cdr_addr"); | ||
| 979 | |||
| 980 | return gcc_jit_lvalue_get_address (emit_lval_XCDR (c), NULL); | ||
| 981 | } | ||
| 982 | |||
| 949 | static void | 983 | static void |
| 950 | emit_XSETCAR (gcc_jit_rvalue *c, gcc_jit_rvalue *n) | 984 | emit_XSETCAR (gcc_jit_rvalue *c, gcc_jit_rvalue *n) |
| 951 | { | 985 | { |
| @@ -960,6 +994,20 @@ emit_XSETCAR (gcc_jit_rvalue *c, gcc_jit_rvalue *n) | |||
| 960 | n); | 994 | n); |
| 961 | } | 995 | } |
| 962 | 996 | ||
| 997 | static void | ||
| 998 | emit_XSETCDR (gcc_jit_rvalue *c, gcc_jit_rvalue *n) | ||
| 999 | { | ||
| 1000 | emit_comment ("XSETCDR"); | ||
| 1001 | |||
| 1002 | gcc_jit_block_add_assignment( | ||
| 1003 | comp.block->gcc_bb, | ||
| 1004 | NULL, | ||
| 1005 | gcc_jit_rvalue_dereference ( | ||
| 1006 | emit_cdr_addr (c), | ||
| 1007 | NULL), | ||
| 1008 | n); | ||
| 1009 | } | ||
| 1010 | |||
| 963 | static gcc_jit_rvalue * | 1011 | static gcc_jit_rvalue * |
| 964 | emit_PURE_P (gcc_jit_rvalue *ptr) | 1012 | emit_PURE_P (gcc_jit_rvalue *ptr) |
| 965 | { | 1013 | { |
| @@ -1471,62 +1519,73 @@ define_CAR_CDR (void) | |||
| 1471 | } | 1519 | } |
| 1472 | 1520 | ||
| 1473 | static void | 1521 | static void |
| 1474 | define_setcar (void) | 1522 | define_setcar_setcdr (void) |
| 1475 | { | 1523 | { |
| 1476 | USE_SAFE_ALLOCA; | 1524 | USE_SAFE_ALLOCA; |
| 1477 | 1525 | ||
| 1478 | gcc_jit_param *cell = | 1526 | char const *f_name[] = {"setcar", "setcdr"}; |
| 1479 | gcc_jit_context_new_param (comp.ctxt, | 1527 | char const *par_name[] = {"new_car", "new_cdr"}; |
| 1480 | NULL, | ||
| 1481 | comp.lisp_obj_type, | ||
| 1482 | "cell"); | ||
| 1483 | gcc_jit_param *new_car = | ||
| 1484 | gcc_jit_context_new_param (comp.ctxt, | ||
| 1485 | NULL, | ||
| 1486 | comp.lisp_obj_type, | ||
| 1487 | "new_car"); | ||
| 1488 | |||
| 1489 | gcc_jit_param *param[] = { cell, new_car }; | ||
| 1490 | comp.setcar = | ||
| 1491 | gcc_jit_context_new_function (comp.ctxt, NULL, | ||
| 1492 | GCC_JIT_FUNCTION_ALWAYS_INLINE, | ||
| 1493 | comp.lisp_obj_type, | ||
| 1494 | "setcar", | ||
| 1495 | 2, | ||
| 1496 | param, | ||
| 1497 | 0); | ||
| 1498 | 1528 | ||
| 1499 | DECL_AND_SAFE_ALLOCA_BLOCK (init_block, comp.setcar); | 1529 | for (int i = 0; i < 2; i++) |
| 1500 | comp.block = init_block; | 1530 | { |
| 1501 | comp.func = comp.setcar; | 1531 | gcc_jit_param *cell = |
| 1532 | gcc_jit_context_new_param (comp.ctxt, | ||
| 1533 | NULL, | ||
| 1534 | comp.lisp_obj_type, | ||
| 1535 | "cell"); | ||
| 1536 | gcc_jit_param *new_el = | ||
| 1537 | gcc_jit_context_new_param (comp.ctxt, | ||
| 1538 | NULL, | ||
| 1539 | comp.lisp_obj_type, | ||
| 1540 | par_name[i]); | ||
| 1541 | |||
| 1542 | gcc_jit_param *param[] = { cell, new_el }; | ||
| 1543 | |||
| 1544 | gcc_jit_function **f_ref = !i ? &comp.setcar : &comp.setcdr; | ||
| 1545 | *f_ref = gcc_jit_context_new_function (comp.ctxt, NULL, | ||
| 1546 | GCC_JIT_FUNCTION_ALWAYS_INLINE, | ||
| 1547 | comp.lisp_obj_type, | ||
| 1548 | f_name[i], | ||
| 1549 | 2, | ||
| 1550 | param, | ||
| 1551 | 0); | ||
| 1552 | DECL_AND_SAFE_ALLOCA_BLOCK (init_block, *f_ref); | ||
| 1553 | comp.func = *f_ref; | ||
| 1554 | comp.block = init_block; | ||
| 1502 | 1555 | ||
| 1503 | /* CHECK_CONS (cell); */ | 1556 | /* CHECK_CONS (cell); */ |
| 1504 | emit_CHECK_CONS (gcc_jit_param_as_rvalue (cell)); | 1557 | emit_CHECK_CONS (gcc_jit_param_as_rvalue (cell)); |
| 1505 | 1558 | ||
| 1506 | /* CHECK_IMPURE (cell, XCONS (cell)); */ | 1559 | /* CHECK_IMPURE (cell, XCONS (cell)); */ |
| 1507 | gcc_jit_rvalue *args[] = | 1560 | gcc_jit_rvalue *args[] = |
| 1508 | { gcc_jit_param_as_rvalue (cell), | 1561 | { gcc_jit_param_as_rvalue (cell), |
| 1509 | emit_XCONS (gcc_jit_param_as_rvalue (cell)) }; | 1562 | emit_XCONS (gcc_jit_param_as_rvalue (cell)) }; |
| 1510 | 1563 | ||
| 1511 | gcc_jit_block_add_eval ( | 1564 | gcc_jit_block_add_eval ( |
| 1512 | init_block->gcc_bb, | 1565 | init_block->gcc_bb, |
| 1513 | NULL, | ||
| 1514 | gcc_jit_context_new_call (comp.ctxt, | ||
| 1515 | NULL, | 1566 | NULL, |
| 1516 | comp.check_impure, | 1567 | gcc_jit_context_new_call (comp.ctxt, |
| 1517 | 2, | 1568 | NULL, |
| 1518 | args)); | 1569 | comp.check_impure, |
| 1519 | 1570 | 2, | |
| 1520 | /* XSETCAR (cell, newcar); */ | 1571 | args)); |
| 1521 | emit_XSETCAR (gcc_jit_param_as_rvalue (cell), | 1572 | |
| 1522 | gcc_jit_param_as_rvalue (new_car)); | 1573 | /* XSETCDR (cell, newel); */ |
| 1574 | if (!i) | ||
| 1575 | emit_XSETCAR (gcc_jit_param_as_rvalue (cell), | ||
| 1576 | gcc_jit_param_as_rvalue (new_el)); | ||
| 1577 | else | ||
| 1578 | emit_XSETCDR (gcc_jit_param_as_rvalue (cell), | ||
| 1579 | gcc_jit_param_as_rvalue (new_el)); | ||
| 1523 | 1580 | ||
| 1524 | /* return newcar; */ | 1581 | /* return newel; */ |
| 1525 | gcc_jit_block_end_with_return (init_block->gcc_bb, | 1582 | gcc_jit_block_end_with_return (init_block->gcc_bb, |
| 1526 | NULL, | 1583 | NULL, |
| 1527 | gcc_jit_param_as_rvalue (new_car)); | 1584 | gcc_jit_param_as_rvalue (new_el)); |
| 1585 | } | ||
| 1528 | SAFE_FREE (); | 1586 | SAFE_FREE (); |
| 1529 | } | 1587 | } |
| 1588 | |||
| 1530 | /* Declare a substitute for PSEUDOVECTORP as always inlined function. */ | 1589 | /* Declare a substitute for PSEUDOVECTORP as always inlined function. */ |
| 1531 | 1590 | ||
| 1532 | static void | 1591 | static void |
| @@ -1942,7 +2001,7 @@ init_comp (int opt_level) | |||
| 1942 | define_CHECK_TYPE (); | 2001 | define_CHECK_TYPE (); |
| 1943 | define_CHECK_IMPURE (); | 2002 | define_CHECK_IMPURE (); |
| 1944 | define_bool_to_lisp_obj (); | 2003 | define_bool_to_lisp_obj (); |
| 1945 | define_setcar(); | 2004 | define_setcar_setcdr(); |
| 1946 | } | 2005 | } |
| 1947 | 2006 | ||
| 1948 | static void | 2007 | static void |
| @@ -2885,7 +2944,14 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 2885 | PUSH_RVAL (res); | 2944 | PUSH_RVAL (res); |
| 2886 | break; | 2945 | break; |
| 2887 | 2946 | ||
| 2888 | CASE_CALL_N (setcdr, 2); | 2947 | case Bsetcdr: |
| 2948 | POP2; | ||
| 2949 | res = gcc_jit_context_new_call (comp.ctxt, | ||
| 2950 | NULL, | ||
| 2951 | comp.setcdr, | ||
| 2952 | 2, args); | ||
| 2953 | PUSH_RVAL (res); | ||
| 2954 | break; | ||
| 2889 | 2955 | ||
| 2890 | CASE (Bcar_safe); | 2956 | CASE (Bcar_safe); |
| 2891 | EMIT_CALL_N ("CAR_SAFE", 1); | 2957 | EMIT_CALL_N ("CAR_SAFE", 1); |