diff options
| author | Andrea Corallo | 2019-08-22 16:00:43 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:37:40 +0100 |
| commit | ad5488cad62b04ff1ae28cbbe2a0dcb2af817f27 (patch) | |
| tree | fa52cee7939464397faf6c46334f640a80effa07 /src | |
| parent | cf0053a66a8055e05e9842c41f60c2130f4dd642 (diff) | |
| download | emacs-ad5488cad62b04ff1ae28cbbe2a0dcb2af817f27.tar.gz emacs-ad5488cad62b04ff1ae28cbbe2a0dcb2af817f27.zip | |
emit function relocation into structure
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/src/comp.c b/src/comp.c index 5c8106a78e4..1a2984bb72e 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -150,6 +150,7 @@ typedef struct { | |||
| 150 | Lisp_Object func_hash; /* c_f_name -> (gcc_func . subr_name). */ | 150 | Lisp_Object func_hash; /* c_f_name -> (gcc_func . subr_name). */ |
| 151 | Lisp_Object emitter_dispatcher; | 151 | Lisp_Object emitter_dispatcher; |
| 152 | gcc_jit_rvalue *data_relocs; | 152 | gcc_jit_rvalue *data_relocs; |
| 153 | gcc_jit_lvalue *func_relocs; | ||
| 153 | } comp_t; | 154 | } comp_t; |
| 154 | 155 | ||
| 155 | static comp_t comp; | 156 | static comp_t comp; |
| @@ -283,7 +284,7 @@ fill_declaration_types (gcc_jit_type **type, gcc_jit_rvalue **args, | |||
| 283 | type[i] = comp.lisp_obj_type; | 284 | type[i] = comp.lisp_obj_type; |
| 284 | } | 285 | } |
| 285 | 286 | ||
| 286 | static void | 287 | static gcc_jit_field * |
| 287 | declare_imported_func (Lisp_Object subr_sym, gcc_jit_type *ret_type, | 288 | declare_imported_func (Lisp_Object subr_sym, gcc_jit_type *ret_type, |
| 288 | unsigned nargs, gcc_jit_rvalue **args) | 289 | unsigned nargs, gcc_jit_rvalue **args) |
| 289 | { | 290 | { |
| @@ -305,14 +306,15 @@ declare_imported_func (Lisp_Object subr_sym, gcc_jit_type *ret_type, | |||
| 305 | nargs, | 306 | nargs, |
| 306 | type, | 307 | type, |
| 307 | 0); | 308 | 0); |
| 308 | gcc_jit_lvalue *f_ptr | 309 | gcc_jit_field *field |
| 309 | = gcc_jit_context_new_global (comp.ctxt, | 310 | = gcc_jit_context_new_field (comp.ctxt, |
| 310 | NULL, | 311 | NULL, |
| 311 | GCC_JIT_GLOBAL_EXPORTED, | 312 | f_ptr_type, |
| 312 | f_ptr_type, | 313 | SSDATA (f_ptr_name)); |
| 313 | SSDATA (f_ptr_name)); | 314 | |
| 314 | Lisp_Object value = Fcons (make_mint_ptr (f_ptr), subr_sym); | 315 | Lisp_Object value = Fcons (make_mint_ptr (field), subr_sym); |
| 315 | Fputhash (subr_sym, value, comp.func_hash); | 316 | Fputhash (subr_sym, value, comp.func_hash); |
| 317 | return field; | ||
| 316 | } | 318 | } |
| 317 | 319 | ||
| 318 | static gcc_jit_function * | 320 | static gcc_jit_function * |
| @@ -343,14 +345,12 @@ emit_call (Lisp_Object subr_sym, gcc_jit_type *ret_type, unsigned nargs, | |||
| 343 | gcc_jit_rvalue **args) | 345 | gcc_jit_rvalue **args) |
| 344 | { | 346 | { |
| 345 | Lisp_Object value = Fgethash (subr_sym, comp.func_hash, Qnil); | 347 | Lisp_Object value = Fgethash (subr_sym, comp.func_hash, Qnil); |
| 348 | eassert (!NILP (value)); | ||
| 346 | 349 | ||
| 347 | if (NILP (value)) | 350 | gcc_jit_lvalue *f_ptr = |
| 348 | { | 351 | gcc_jit_lvalue_access_field (comp.func_relocs, |
| 349 | declare_imported_func (subr_sym, ret_type, nargs, args); | 352 | NULL, |
| 350 | value = Fgethash (subr_sym, comp.func_hash, Qnil); | 353 | (gcc_jit_field *) xmint_pointer (XCAR (value))); |
| 351 | eassert (!NILP (value)); | ||
| 352 | } | ||
| 353 | gcc_jit_lvalue *f_ptr = (gcc_jit_lvalue *) xmint_pointer (XCAR (value)); | ||
| 354 | emit_comment (format_string ("calling subr: %s", | 354 | emit_comment (format_string ("calling subr: %s", |
| 355 | SSDATA (SYMBOL_NAME (subr_sym)))); | 355 | SSDATA (SYMBOL_NAME (subr_sym)))); |
| 356 | return gcc_jit_context_new_call_through_ptr(comp.ctxt, | 356 | return gcc_jit_context_new_call_through_ptr(comp.ctxt, |
| @@ -1529,6 +1529,8 @@ This emit the code needed by every compilation unit to be loaded. | |||
| 1529 | static void | 1529 | static void |
| 1530 | emit_ctxt_code (void) | 1530 | emit_ctxt_code (void) |
| 1531 | { | 1531 | { |
| 1532 | /* Imported objects. */ | ||
| 1533 | |||
| 1532 | const char *d_reloc = SSDATA (FUNCALL1 (comp-ctxt-data-relocs, Vcomp_ctxt)); | 1534 | const char *d_reloc = SSDATA (FUNCALL1 (comp-ctxt-data-relocs, Vcomp_ctxt)); |
| 1533 | EMACS_UINT d_reloc_len = | 1535 | EMACS_UINT d_reloc_len = |
| 1534 | XFIXNUM (FUNCALL1 (hash-table-count, | 1536 | XFIXNUM (FUNCALL1 (hash-table-count, |
| @@ -1548,6 +1550,37 @@ emit_ctxt_code (void) | |||
| 1548 | 1550 | ||
| 1549 | emit_litteral_string_func ("text_data_relocs", d_reloc); | 1551 | emit_litteral_string_func ("text_data_relocs", d_reloc); |
| 1550 | 1552 | ||
| 1553 | /* Imported functions. */ | ||
| 1554 | Lisp_Object f_reloc = FUNCALL1 (comp-ctxt-func-relocs-l, Vcomp_ctxt); | ||
| 1555 | EMACS_UINT f_reloc_len = XFIXNUM (Flength (f_reloc)); | ||
| 1556 | gcc_jit_field *fields[f_reloc_len]; | ||
| 1557 | int i = 0; | ||
| 1558 | FOR_EACH_TAIL (f_reloc) | ||
| 1559 | { | ||
| 1560 | Lisp_Object subr_sym = XCAR (f_reloc); | ||
| 1561 | Lisp_Object subr = Fsymbol_function (subr_sym); | ||
| 1562 | gcc_jit_field *field | ||
| 1563 | = declare_imported_func (subr_sym, comp.lisp_obj_type, | ||
| 1564 | XFIXNUM (XCDR (Fsubr_arity (subr))), NULL); | ||
| 1565 | fields [i++] = field; | ||
| 1566 | } | ||
| 1567 | eassert (f_reloc_len == i); | ||
| 1568 | |||
| 1569 | gcc_jit_struct *f_reloc_struct | ||
| 1570 | = gcc_jit_context_new_struct_type (comp.ctxt, | ||
| 1571 | NULL, | ||
| 1572 | "function_reloc_struct", | ||
| 1573 | f_reloc_len, | ||
| 1574 | fields); | ||
| 1575 | comp.func_relocs | ||
| 1576 | = gcc_jit_context_new_global ( | ||
| 1577 | comp.ctxt, | ||
| 1578 | NULL, | ||
| 1579 | GCC_JIT_GLOBAL_EXPORTED, | ||
| 1580 | gcc_jit_struct_as_type (f_reloc_struct), | ||
| 1581 | "f_reloc"); | ||
| 1582 | |||
| 1583 | /* Exported functions info. */ | ||
| 1551 | const char *func_list = SSDATA (FUNCALL1 (comp-ctxt-funcs, Vcomp_ctxt)); | 1584 | const char *func_list = SSDATA (FUNCALL1 (comp-ctxt-funcs, Vcomp_ctxt)); |
| 1552 | emit_litteral_string_func ("text_exported_funcs", func_list); | 1585 | emit_litteral_string_func ("text_exported_funcs", func_list); |
| 1553 | } | 1586 | } |
| @@ -2658,17 +2691,6 @@ DEFUN ("comp--init-ctxt", Fcomp__init_ctxt, Scomp__init_ctxt, | |||
| 2658 | comp.void_ptr_type, | 2691 | comp.void_ptr_type, |
| 2659 | pure); | 2692 | pure); |
| 2660 | 2693 | ||
| 2661 | /* Define inline functions. */ | ||
| 2662 | |||
| 2663 | define_CAR_CDR(); | ||
| 2664 | define_PSEUDOVECTORP (); | ||
| 2665 | define_CHECK_TYPE (); | ||
| 2666 | define_CHECK_IMPURE (); | ||
| 2667 | define_bool_to_lisp_obj (); | ||
| 2668 | define_setcar_setcdr (); | ||
| 2669 | define_add1_sub1 (); | ||
| 2670 | define_negate (); | ||
| 2671 | |||
| 2672 | return Qt; | 2694 | return Qt; |
| 2673 | } | 2695 | } |
| 2674 | 2696 | ||
| @@ -2709,6 +2731,16 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, | |||
| 2709 | 2731 | ||
| 2710 | emit_ctxt_code (); | 2732 | emit_ctxt_code (); |
| 2711 | 2733 | ||
| 2734 | /* /\* Define inline functions. *\/ */ | ||
| 2735 | /* define_CAR_CDR(); */ | ||
| 2736 | /* define_PSEUDOVECTORP (); */ | ||
| 2737 | /* define_CHECK_TYPE (); */ | ||
| 2738 | /* define_CHECK_IMPURE (); */ | ||
| 2739 | /* define_bool_to_lisp_obj (); */ | ||
| 2740 | /* define_setcar_setcdr (); */ | ||
| 2741 | /* define_add1_sub1 (); */ | ||
| 2742 | /* define_negate (); */ | ||
| 2743 | |||
| 2712 | /* Compile all functions. Can't be done before because the | 2744 | /* Compile all functions. Can't be done before because the |
| 2713 | relocation vectore has to be already compiled. */ | 2745 | relocation vectore has to be already compiled. */ |
| 2714 | struct Lisp_Hash_Table *func_h | 2746 | struct Lisp_Hash_Table *func_h |