diff options
| author | Andrea Corallo | 2020-05-31 14:39:59 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-09-11 15:04:28 +0200 |
| commit | ff593d934aec6d8e7b211d7fe2ff7fc8f92ad42b (patch) | |
| tree | caba8c8a5c882d503715f060ae11abf21b6e38d7 /src | |
| parent | 42b5a1101d2230bc1a6d7abf019f9a96c164da5c (diff) | |
| download | emacs-ff593d934aec6d8e7b211d7fe2ff7fc8f92ad42b.tar.gz emacs-ff593d934aec6d8e7b211d7fe2ff7fc8f92ad42b.zip | |
* Make use of new 'gcc_jit_global_set_initializer' entry point
Use this brand new entry point to avoid the current workaround and its
load-time memcpys.
* src/comp.c (gcc_jit_global_set_initializer): Add to the dynamic
load machinery.
(static_obj_t): Remove const qualifier from the data field.
(emit_static_object): Make use of 'gcc_jit_global_set_initializer'
when available.
(load_static_obj): Use the blob for loading if that was emitted.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/comp.c b/src/comp.c index d7966d42221..1ef4f3054b1 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -90,6 +90,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 90 | #undef gcc_jit_function_get_param | 90 | #undef gcc_jit_function_get_param |
| 91 | #undef gcc_jit_function_new_block | 91 | #undef gcc_jit_function_new_block |
| 92 | #undef gcc_jit_function_new_local | 92 | #undef gcc_jit_function_new_local |
| 93 | #undef gcc_jit_global_set_initializer | ||
| 93 | #undef gcc_jit_lvalue_access_field | 94 | #undef gcc_jit_lvalue_access_field |
| 94 | #undef gcc_jit_lvalue_as_rvalue | 95 | #undef gcc_jit_lvalue_as_rvalue |
| 95 | #undef gcc_jit_lvalue_get_address | 96 | #undef gcc_jit_lvalue_get_address |
| @@ -144,6 +145,8 @@ DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_global, | |||
| 144 | DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_function_new_local, | 145 | DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_function_new_local, |
| 145 | (gcc_jit_function *func, gcc_jit_location *loc, gcc_jit_type *type, | 146 | (gcc_jit_function *func, gcc_jit_location *loc, gcc_jit_type *type, |
| 146 | const char *name)); | 147 | const char *name)); |
| 148 | DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_global_set_initializer, | ||
| 149 | (gcc_jit_lvalue *global, const void *blob, size_t num_bytes)); | ||
| 147 | DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_lvalue_access_field, | 150 | DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_lvalue_access_field, |
| 148 | (gcc_jit_lvalue *struct_or_union, gcc_jit_location *loc, | 151 | (gcc_jit_lvalue *struct_or_union, gcc_jit_location *loc, |
| 149 | gcc_jit_field *field)); | 152 | gcc_jit_field *field)); |
| @@ -307,6 +310,7 @@ init_gccjit_functions (void) | |||
| 307 | LOAD_DLL_FN (library, gcc_jit_struct_set_fields); | 310 | LOAD_DLL_FN (library, gcc_jit_struct_set_fields); |
| 308 | LOAD_DLL_FN (library, gcc_jit_type_get_pointer); | 311 | LOAD_DLL_FN (library, gcc_jit_type_get_pointer); |
| 309 | LOAD_DLL_FN_OPT (library, gcc_jit_context_add_driver_option); | 312 | LOAD_DLL_FN_OPT (library, gcc_jit_context_add_driver_option); |
| 313 | LOAD_DLL_FN_OPT (library, gcc_jit_global_set_initializer); | ||
| 310 | LOAD_DLL_FN_OPT (library, gcc_jit_version_major); | 314 | LOAD_DLL_FN_OPT (library, gcc_jit_version_major); |
| 311 | LOAD_DLL_FN_OPT (library, gcc_jit_version_minor); | 315 | LOAD_DLL_FN_OPT (library, gcc_jit_version_minor); |
| 312 | LOAD_DLL_FN_OPT (library, gcc_jit_version_patchlevel); | 316 | LOAD_DLL_FN_OPT (library, gcc_jit_version_patchlevel); |
| @@ -357,6 +361,7 @@ init_gccjit_functions (void) | |||
| 357 | #define gcc_jit_function_get_param fn_gcc_jit_function_get_param | 361 | #define gcc_jit_function_get_param fn_gcc_jit_function_get_param |
| 358 | #define gcc_jit_function_new_block fn_gcc_jit_function_new_block | 362 | #define gcc_jit_function_new_block fn_gcc_jit_function_new_block |
| 359 | #define gcc_jit_function_new_local fn_gcc_jit_function_new_local | 363 | #define gcc_jit_function_new_local fn_gcc_jit_function_new_local |
| 364 | #define gcc_jit_global_set_initializer fn_gcc_jit_global_set_initializer | ||
| 360 | #define gcc_jit_lvalue_access_field fn_gcc_jit_lvalue_access_field | 365 | #define gcc_jit_lvalue_access_field fn_gcc_jit_lvalue_access_field |
| 361 | #define gcc_jit_lvalue_as_rvalue fn_gcc_jit_lvalue_as_rvalue | 366 | #define gcc_jit_lvalue_as_rvalue fn_gcc_jit_lvalue_as_rvalue |
| 362 | #define gcc_jit_lvalue_get_address fn_gcc_jit_lvalue_get_address | 367 | #define gcc_jit_lvalue_get_address fn_gcc_jit_lvalue_get_address |
| @@ -589,7 +594,7 @@ FILE *logfile = NULL; | |||
| 589 | /* This is used for serialized objects by the reload mechanism. */ | 594 | /* This is used for serialized objects by the reload mechanism. */ |
| 590 | typedef struct { | 595 | typedef struct { |
| 591 | ptrdiff_t len; | 596 | ptrdiff_t len; |
| 592 | const char data[]; | 597 | char data[]; |
| 593 | } static_obj_t; | 598 | } static_obj_t; |
| 594 | 599 | ||
| 595 | typedef struct { | 600 | typedef struct { |
| @@ -2497,6 +2502,33 @@ emit_static_object (const char *name, Lisp_Object obj) | |||
| 2497 | ptrdiff_t len = SBYTES (str); | 2502 | ptrdiff_t len = SBYTES (str); |
| 2498 | const char *p = SSDATA (str); | 2503 | const char *p = SSDATA (str); |
| 2499 | 2504 | ||
| 2505 | #if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer) \ | ||
| 2506 | || defined (WINDOWSNT) | ||
| 2507 | #pragma GCC diagnostic ignored "-Waddress" | ||
| 2508 | if (gcc_jit_global_set_initializer) | ||
| 2509 | #pragma GCC diagnostic pop | ||
| 2510 | { | ||
| 2511 | ptrdiff_t str_size = len + 1; | ||
| 2512 | ptrdiff_t size = sizeof (static_obj_t) + str_size; | ||
| 2513 | static_obj_t *static_obj = xmalloc (size); | ||
| 2514 | static_obj->len = str_size; | ||
| 2515 | memcpy (static_obj->data, p, str_size); | ||
| 2516 | gcc_jit_lvalue *blob = | ||
| 2517 | gcc_jit_context_new_global ( | ||
| 2518 | comp.ctxt, | ||
| 2519 | NULL, | ||
| 2520 | GCC_JIT_GLOBAL_EXPORTED, | ||
| 2521 | gcc_jit_context_new_array_type (comp.ctxt, NULL, | ||
| 2522 | comp.char_type, | ||
| 2523 | size), | ||
| 2524 | format_string ("%s_blob", name)); | ||
| 2525 | gcc_jit_global_set_initializer (blob, static_obj, size); | ||
| 2526 | xfree (static_obj); | ||
| 2527 | |||
| 2528 | return; | ||
| 2529 | } | ||
| 2530 | #endif | ||
| 2531 | |||
| 2500 | gcc_jit_type *a_type = | 2532 | gcc_jit_type *a_type = |
| 2501 | gcc_jit_context_new_array_type (comp.ctxt, | 2533 | gcc_jit_context_new_array_type (comp.ctxt, |
| 2502 | NULL, | 2534 | NULL, |
| @@ -4599,12 +4631,19 @@ typedef char *(*comp_lit_str_func) (void); | |||
| 4599 | static Lisp_Object | 4631 | static Lisp_Object |
| 4600 | load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) | 4632 | load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) |
| 4601 | { | 4633 | { |
| 4634 | static_obj_t *blob = | ||
| 4635 | dynlib_sym (comp_u->handle, format_string ("%s_blob", name)); | ||
| 4636 | if (blob) | ||
| 4637 | /* New blob format. */ | ||
| 4638 | return Fread (make_string (blob->data, blob->len)); | ||
| 4639 | |||
| 4602 | static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); | 4640 | static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); |
| 4603 | if (!f) | 4641 | if (!f) |
| 4604 | xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); | 4642 | xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); |
| 4605 | 4643 | ||
| 4606 | static_obj_t *res = f (); | 4644 | blob = f (); |
| 4607 | return Fread (make_string (res->data, res->len)); | 4645 | return Fread (make_string (blob->data, blob->len)); |
| 4646 | |||
| 4608 | } | 4647 | } |
| 4609 | 4648 | ||
| 4610 | /* Return false when something is wrong or true otherwise. */ | 4649 | /* Return false when something is wrong or true otherwise. */ |