diff options
| author | Andrea Corallo | 2020-05-31 20:28:31 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-05-31 22:22:23 +0100 |
| commit | ce3c1ea83e18e6b8a02013bbdae4b4c183e39997 (patch) | |
| tree | 7a865407f0a4759c3425b9709dfb32ae34dfa7f4 /src/comp.c | |
| parent | c936e028c643dc2629e6d2041f2069d89d8c5877 (diff) | |
| download | emacs-ce3c1ea83e18e6b8a02013bbdae4b4c183e39997.tar.gz emacs-ce3c1ea83e18e6b8a02013bbdae4b4c183e39997.zip | |
* 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/comp.c')
| -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) | |||
| 2441 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, comp.int_type, 0)), | 2441 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, comp.int_type, 0)), |
| 2442 | NULL)); | 2442 | NULL)); |
| 2443 | 2443 | ||
| 2444 | /* We can't use always string literals longer that 200 bytes because | ||
| 2445 | they cause a crash in pre GCC 10 libgccjit. | ||
| 2446 | <https://gcc.gnu.org/ml/jit/2019-q3/msg00013.html>. | ||
| 2447 | |||
| 2448 | Adjust if possible to reduce the number of function calls. */ | ||
| 2449 | size_t chunck_size = NILP (Fcomp_libgccjit_version ()) ? 200 : 1024; | ||
| 2450 | char *buff = xmalloc (chunck_size); | ||
| 2444 | for (ptrdiff_t i = 0; i < len;) | 2451 | for (ptrdiff_t i = 0; i < len;) |
| 2445 | { | 2452 | { |
| 2446 | /* We can't use string literals longer that 200 bytes because | 2453 | strncpy (buff, p, chunck_size); |
| 2447 | they cause a crash in older versions of gccjit. | 2454 | buff[chunck_size - 1] = 0; |
| 2448 | https://gcc.gnu.org/ml/jit/2019-q3/msg00013.html. */ | 2455 | uintptr_t l = strlen (buff); |
| 2449 | char str[200]; | ||
| 2450 | strncpy (str, p, 200); | ||
| 2451 | str[199] = 0; | ||
| 2452 | uintptr_t l = strlen (str); | ||
| 2453 | 2456 | ||
| 2454 | if (l != 0) | 2457 | if (l != 0) |
| 2455 | { | 2458 | { |
| 2456 | p += l; | 2459 | p += l; |
| 2457 | i += l; | 2460 | i += l; |
| 2458 | 2461 | ||
| 2459 | gcc_jit_rvalue *args[3] | 2462 | gcc_jit_rvalue *args[] = |
| 2460 | = {gcc_jit_lvalue_as_rvalue (ptrvar), | 2463 | { gcc_jit_lvalue_as_rvalue (ptrvar), |
| 2461 | gcc_jit_context_new_string_literal (comp.ctxt, str), | 2464 | gcc_jit_context_new_string_literal (comp.ctxt, buff), |
| 2462 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, | 2465 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, |
| 2463 | comp.size_t_type, | 2466 | comp.size_t_type, |
| 2464 | l)}; | 2467 | l) }; |
| 2465 | 2468 | ||
| 2466 | gcc_jit_block_add_eval (block, NULL, | 2469 | gcc_jit_block_add_eval (block, NULL, |
| 2467 | gcc_jit_context_new_call (comp.ctxt, NULL, | 2470 | gcc_jit_context_new_call (comp.ctxt, NULL, |
| @@ -2496,6 +2499,7 @@ emit_static_object (const char *name, Lisp_Object obj) | |||
| 2496 | NULL)); | 2499 | NULL)); |
| 2497 | } | 2500 | } |
| 2498 | } | 2501 | } |
| 2502 | xfree (buff); | ||
| 2499 | 2503 | ||
| 2500 | gcc_jit_block_add_assignment ( | 2504 | gcc_jit_block_add_assignment ( |
| 2501 | block, | 2505 | block, |