diff options
| author | Andrea Corallo <akrl@sdf.org> | 2020-05-31 20:28:31 +0100 |
|---|---|---|
| committer | Andrea Corallo <akrl@sdf.org> | 2020-05-31 22:22:23 +0100 |
| commit | ce3c1ea83e18e6b8a02013bbdae4b4c183e39997 (patch) | |
| tree | 7a865407f0a4759c3425b9709dfb32ae34dfa7f4 /src | |
| parent | c936e028c643dc2629e6d2041f2069d89d8c5877 (diff) | |
* Optimize 'emit_static_object' for load-time
* src/comp.c (emit_static_object): Use a chunck size of 200 bytes
on bugged GCCs and a longer one (1024) in sane ones. Rename
str in buff to disambiguate and prefer xmalloc to a VLA given
the buffer is not that small.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/comp.c b/src/comp.c index c9d3fd04070..2d904c91548 100644 --- a/src/comp.c +++ b/src/comp.c @@ -2441,27 +2441,30 @@ emit_static_object (const char *name, Lisp_Object obj) gcc_jit_context_new_rvalue_from_int (comp.ctxt, comp.int_type, 0)), NULL)); + /* We can't use always string literals longer that 200 bytes because + they cause a crash in pre GCC 10 libgccjit. + <https://gcc.gnu.org/ml/jit/2019-q3/msg00013.html>. + + Adjust if possible to reduce the number of function calls. */ + size_t chunck_size = NILP (Fcomp_libgccjit_version ()) ? 200 : 1024; + char *buff = xmalloc (chunck_size); for (ptrdiff_t i = 0; i < len;) { - /* We can't use string literals longer that 200 bytes because - they cause a crash in older versions of gccjit. - https://gcc.gnu.org/ml/jit/2019-q3/msg00013.html. */ - char str[200]; - strncpy (str, p, 200); - str[199] = 0; - uintptr_t l = strlen (str); + strncpy (buff, p, chunck_size); + buff[chunck_size - 1] = 0; + uintptr_t l = strlen (buff); if (l != 0) { p += l; i += l; - gcc_jit_rvalue *args[3] - = {gcc_jit_lvalue_as_rvalue (ptrvar), - gcc_jit_context_new_string_literal (comp.ctxt, str), - gcc_jit_context_new_rvalue_from_int (comp.ctxt, - comp.size_t_type, - l)}; + gcc_jit_rvalue *args[] = + { gcc_jit_lvalue_as_rvalue (ptrvar), + gcc_jit_context_new_string_literal (comp.ctxt, buff), + gcc_jit_context_new_rvalue_from_int (comp.ctxt, + comp.size_t_type, + l) }; gcc_jit_block_add_eval (block, NULL, gcc_jit_context_new_call (comp.ctxt, NULL, @@ -2496,6 +2499,7 @@ emit_static_object (const char *name, Lisp_Object obj) NULL)); } } + xfree (buff); gcc_jit_block_add_assignment ( block, |
