diff options
| author | Andrea Corallo <akrl@sdf.org> | 2020-05-31 14:39:59 +0100 |
|---|---|---|
| committer | Andrea Corallo <akrl@sdf.org> | 2020-09-11 15:04:28 +0200 |
| commit | ff593d934aec6d8e7b211d7fe2ff7fc8f92ad42b (patch) | |
| tree | caba8c8a5c882d503715f060ae11abf21b6e38d7 /src | |
| parent | 42b5a1101d2230bc1a6d7abf019f9a96c164da5c (diff) | |
* 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/>. */ #undef gcc_jit_function_get_param #undef gcc_jit_function_new_block #undef gcc_jit_function_new_local +#undef gcc_jit_global_set_initializer #undef gcc_jit_lvalue_access_field #undef gcc_jit_lvalue_as_rvalue #undef gcc_jit_lvalue_get_address @@ -144,6 +145,8 @@ DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_global, DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_function_new_local, (gcc_jit_function *func, gcc_jit_location *loc, gcc_jit_type *type, const char *name)); +DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_global_set_initializer, + (gcc_jit_lvalue *global, const void *blob, size_t num_bytes)); DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_lvalue_access_field, (gcc_jit_lvalue *struct_or_union, gcc_jit_location *loc, gcc_jit_field *field)); @@ -307,6 +310,7 @@ init_gccjit_functions (void) LOAD_DLL_FN (library, gcc_jit_struct_set_fields); LOAD_DLL_FN (library, gcc_jit_type_get_pointer); LOAD_DLL_FN_OPT (library, gcc_jit_context_add_driver_option); + LOAD_DLL_FN_OPT (library, gcc_jit_global_set_initializer); LOAD_DLL_FN_OPT (library, gcc_jit_version_major); LOAD_DLL_FN_OPT (library, gcc_jit_version_minor); LOAD_DLL_FN_OPT (library, gcc_jit_version_patchlevel); @@ -357,6 +361,7 @@ init_gccjit_functions (void) #define gcc_jit_function_get_param fn_gcc_jit_function_get_param #define gcc_jit_function_new_block fn_gcc_jit_function_new_block #define gcc_jit_function_new_local fn_gcc_jit_function_new_local +#define gcc_jit_global_set_initializer fn_gcc_jit_global_set_initializer #define gcc_jit_lvalue_access_field fn_gcc_jit_lvalue_access_field #define gcc_jit_lvalue_as_rvalue fn_gcc_jit_lvalue_as_rvalue #define gcc_jit_lvalue_get_address fn_gcc_jit_lvalue_get_address @@ -589,7 +594,7 @@ FILE *logfile = NULL; /* This is used for serialized objects by the reload mechanism. */ typedef struct { ptrdiff_t len; - const char data[]; + char data[]; } static_obj_t; typedef struct { @@ -2497,6 +2502,33 @@ emit_static_object (const char *name, Lisp_Object obj) ptrdiff_t len = SBYTES (str); const char *p = SSDATA (str); +#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer) \ + || defined (WINDOWSNT) +#pragma GCC diagnostic ignored "-Waddress" + if (gcc_jit_global_set_initializer) +#pragma GCC diagnostic pop + { + ptrdiff_t str_size = len + 1; + ptrdiff_t size = sizeof (static_obj_t) + str_size; + static_obj_t *static_obj = xmalloc (size); + static_obj->len = str_size; + memcpy (static_obj->data, p, str_size); + gcc_jit_lvalue *blob = + gcc_jit_context_new_global ( + comp.ctxt, + NULL, + GCC_JIT_GLOBAL_EXPORTED, + gcc_jit_context_new_array_type (comp.ctxt, NULL, + comp.char_type, + size), + format_string ("%s_blob", name)); + gcc_jit_global_set_initializer (blob, static_obj, size); + xfree (static_obj); + + return; + } +#endif + gcc_jit_type *a_type = gcc_jit_context_new_array_type (comp.ctxt, NULL, @@ -4599,12 +4631,19 @@ typedef char *(*comp_lit_str_func) (void); static Lisp_Object load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) { + static_obj_t *blob = + dynlib_sym (comp_u->handle, format_string ("%s_blob", name)); + if (blob) + /* New blob format. */ + return Fread (make_string (blob->data, blob->len)); + static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); if (!f) xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); - static_obj_t *res = f (); - return Fread (make_string (res->data, res->len)); + blob = f (); + return Fread (make_string (blob->data, blob->len)); + } /* Return false when something is wrong or true otherwise. */ |
