aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorGregory Heytings2022-10-30 17:00:35 +0100
committerGregory Heytings2022-10-30 17:00:35 +0100
commitaef803d6c3d61004f15d0bc82fa7bf9952302312 (patch)
tree087c444f788cda27006ddc066ad430f62f5ac02a /src/comp.c
parent3bf19c417fd39766ee9c7a793c9faadd3bd88478 (diff)
parent3fa4cca3d244f51e471e7779c934278731fc21e9 (diff)
downloademacs-aef803d6c3d61004f15d0bc82fa7bf9952302312.tar.gz
emacs-aef803d6c3d61004f15d0bc82fa7bf9952302312.zip
Merge master into feature/improved-locked-narrowing.
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c107
1 files changed, 98 insertions, 9 deletions
diff --git a/src/comp.c b/src/comp.c
index 70e7d5a8bbf..14012634ccc 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -68,6 +68,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
68#undef gcc_jit_context_get_type 68#undef gcc_jit_context_get_type
69#undef gcc_jit_context_new_array_access 69#undef gcc_jit_context_new_array_access
70#undef gcc_jit_context_new_array_type 70#undef gcc_jit_context_new_array_type
71#undef gcc_jit_context_new_bitcast
71#undef gcc_jit_context_new_binary_op 72#undef gcc_jit_context_new_binary_op
72#undef gcc_jit_context_new_call 73#undef gcc_jit_context_new_call
73#undef gcc_jit_context_new_call_through_ptr 74#undef gcc_jit_context_new_call_through_ptr
@@ -108,6 +109,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
108#undef gcc_jit_struct_set_fields 109#undef gcc_jit_struct_set_fields
109#undef gcc_jit_type_get_const 110#undef gcc_jit_type_get_const
110#undef gcc_jit_type_get_pointer 111#undef gcc_jit_type_get_pointer
112#undef gcc_jit_type_is_pointer
111#undef gcc_jit_version_major 113#undef gcc_jit_version_major
112#undef gcc_jit_version_minor 114#undef gcc_jit_version_minor
113#undef gcc_jit_version_patchlevel 115#undef gcc_jit_version_patchlevel
@@ -180,8 +182,13 @@ DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_call_through_ptr,
180 (gcc_jit_context *ctxt, gcc_jit_location *loc, 182 (gcc_jit_context *ctxt, gcc_jit_location *loc,
181 gcc_jit_rvalue *fn_ptr, int numargs, gcc_jit_rvalue **args)); 183 gcc_jit_rvalue *fn_ptr, int numargs, gcc_jit_rvalue **args));
182DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_cast, 184DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_cast,
185 (gcc_jit_context * ctxt, gcc_jit_location *loc,
186 gcc_jit_rvalue *rvalue, gcc_jit_type *type));
187#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
188DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_bitcast,
183 (gcc_jit_context *ctxt, gcc_jit_location *loc, 189 (gcc_jit_context *ctxt, gcc_jit_location *loc,
184 gcc_jit_rvalue *rvalue, gcc_jit_type *type)); 190 gcc_jit_rvalue *rvalue, gcc_jit_type *type));
191#endif
185DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_comparison, 192DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_comparison,
186 (gcc_jit_context *ctxt, gcc_jit_location *loc, 193 (gcc_jit_context *ctxt, gcc_jit_location *loc,
187 enum gcc_jit_comparison op, gcc_jit_rvalue *a, gcc_jit_rvalue *b)); 194 enum gcc_jit_comparison op, gcc_jit_rvalue *a, gcc_jit_rvalue *b));
@@ -224,6 +231,9 @@ DEF_DLL_FN (gcc_jit_type *, gcc_jit_struct_as_type,
224 (gcc_jit_struct *struct_type)); 231 (gcc_jit_struct *struct_type));
225DEF_DLL_FN (gcc_jit_type *, gcc_jit_type_get_const, (gcc_jit_type *type)); 232DEF_DLL_FN (gcc_jit_type *, gcc_jit_type_get_const, (gcc_jit_type *type));
226DEF_DLL_FN (gcc_jit_type *, gcc_jit_type_get_pointer, (gcc_jit_type *type)); 233DEF_DLL_FN (gcc_jit_type *, gcc_jit_type_get_pointer, (gcc_jit_type *type));
234#ifdef LIBGCCJIT_HAVE_REFLECTION
235DEF_DLL_FN (gcc_jit_type *, gcc_jit_type_is_pointer, (gcc_jit_type *type));
236#endif
227DEF_DLL_FN (void, gcc_jit_block_add_assignment, 237DEF_DLL_FN (void, gcc_jit_block_add_assignment,
228 (gcc_jit_block *block, gcc_jit_location *loc, gcc_jit_lvalue *lvalue, 238 (gcc_jit_block *block, gcc_jit_location *loc, gcc_jit_lvalue *lvalue,
229 gcc_jit_rvalue *rvalue)); 239 gcc_jit_rvalue *rvalue));
@@ -293,6 +303,9 @@ init_gccjit_functions (void)
293 LOAD_DLL_FN (library, gcc_jit_context_get_type); 303 LOAD_DLL_FN (library, gcc_jit_context_get_type);
294 LOAD_DLL_FN (library, gcc_jit_context_new_array_access); 304 LOAD_DLL_FN (library, gcc_jit_context_new_array_access);
295 LOAD_DLL_FN (library, gcc_jit_context_new_array_type); 305 LOAD_DLL_FN (library, gcc_jit_context_new_array_type);
306#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
307 LOAD_DLL_FN (library, gcc_jit_context_new_bitcast);
308#endif
296 LOAD_DLL_FN (library, gcc_jit_context_new_binary_op); 309 LOAD_DLL_FN (library, gcc_jit_context_new_binary_op);
297 LOAD_DLL_FN (library, gcc_jit_context_new_call); 310 LOAD_DLL_FN (library, gcc_jit_context_new_call);
298 LOAD_DLL_FN (library, gcc_jit_context_new_call_through_ptr); 311 LOAD_DLL_FN (library, gcc_jit_context_new_call_through_ptr);
@@ -334,6 +347,9 @@ init_gccjit_functions (void)
334 LOAD_DLL_FN (library, gcc_jit_struct_set_fields); 347 LOAD_DLL_FN (library, gcc_jit_struct_set_fields);
335 LOAD_DLL_FN (library, gcc_jit_type_get_const); 348 LOAD_DLL_FN (library, gcc_jit_type_get_const);
336 LOAD_DLL_FN (library, gcc_jit_type_get_pointer); 349 LOAD_DLL_FN (library, gcc_jit_type_get_pointer);
350#ifdef LIBGCCJIT_HAVE_REFLECTION
351 LOAD_DLL_FN (library, gcc_jit_type_is_pointer);
352#endif
337 LOAD_DLL_FN_OPT (library, gcc_jit_context_add_command_line_option); 353 LOAD_DLL_FN_OPT (library, gcc_jit_context_add_command_line_option);
338 LOAD_DLL_FN_OPT (library, gcc_jit_context_add_driver_option); 354 LOAD_DLL_FN_OPT (library, gcc_jit_context_add_driver_option);
339#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer) 355#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer)
@@ -368,6 +384,9 @@ init_gccjit_functions (void)
368#define gcc_jit_context_get_type fn_gcc_jit_context_get_type 384#define gcc_jit_context_get_type fn_gcc_jit_context_get_type
369#define gcc_jit_context_new_array_access fn_gcc_jit_context_new_array_access 385#define gcc_jit_context_new_array_access fn_gcc_jit_context_new_array_access
370#define gcc_jit_context_new_array_type fn_gcc_jit_context_new_array_type 386#define gcc_jit_context_new_array_type fn_gcc_jit_context_new_array_type
387#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
388# define gcc_jit_context_new_bitcast fn_gcc_jit_context_new_bitcast
389#endif
371#define gcc_jit_context_new_binary_op fn_gcc_jit_context_new_binary_op 390#define gcc_jit_context_new_binary_op fn_gcc_jit_context_new_binary_op
372#define gcc_jit_context_new_call fn_gcc_jit_context_new_call 391#define gcc_jit_context_new_call fn_gcc_jit_context_new_call
373#define gcc_jit_context_new_call_through_ptr fn_gcc_jit_context_new_call_through_ptr 392#define gcc_jit_context_new_call_through_ptr fn_gcc_jit_context_new_call_through_ptr
@@ -410,6 +429,9 @@ init_gccjit_functions (void)
410#define gcc_jit_rvalue_get_type fn_gcc_jit_rvalue_get_type 429#define gcc_jit_rvalue_get_type fn_gcc_jit_rvalue_get_type
411#define gcc_jit_struct_as_type fn_gcc_jit_struct_as_type 430#define gcc_jit_struct_as_type fn_gcc_jit_struct_as_type
412#define gcc_jit_struct_set_fields fn_gcc_jit_struct_set_fields 431#define gcc_jit_struct_set_fields fn_gcc_jit_struct_set_fields
432#ifdef LIBGCCJIT_HAVE_REFLECTION
433# define gcc_jit_type_is_pointer fn_gcc_jit_type_is_pointer
434#endif
413#define gcc_jit_type_get_const fn_gcc_jit_type_get_const 435#define gcc_jit_type_get_const fn_gcc_jit_type_get_const
414#define gcc_jit_type_get_pointer fn_gcc_jit_type_get_pointer 436#define gcc_jit_type_get_pointer fn_gcc_jit_type_get_pointer
415#if defined (LIBGCCJIT_HAVE_gcc_jit_version) 437#if defined (LIBGCCJIT_HAVE_gcc_jit_version)
@@ -518,7 +540,9 @@ typedef struct {
518 540
519static f_reloc_t freloc; 541static f_reloc_t freloc;
520 542
521#define NUM_CAST_TYPES 15 543#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
544# define NUM_CAST_TYPES 15
545#endif
522 546
523typedef struct { 547typedef struct {
524 EMACS_INT len; 548 EMACS_INT len;
@@ -593,13 +617,15 @@ typedef struct {
593 gcc_jit_rvalue *current_thread_ref; 617 gcc_jit_rvalue *current_thread_ref;
594 /* Other globals. */ 618 /* Other globals. */
595 gcc_jit_rvalue *pure_ptr; 619 gcc_jit_rvalue *pure_ptr;
596 /* libgccjit has really limited support for casting therefore this union will 620#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
597 be used for the scope. */ 621 /* This version of libgccjit has really limited support for casting
622 therefore this union will be used for the scope. */
598 gcc_jit_type *cast_union_type; 623 gcc_jit_type *cast_union_type;
599 gcc_jit_function *cast_functions_from_to[NUM_CAST_TYPES][NUM_CAST_TYPES]; 624 gcc_jit_function *cast_functions_from_to[NUM_CAST_TYPES][NUM_CAST_TYPES];
600 gcc_jit_function *cast_ptr_to_int; 625 gcc_jit_function *cast_ptr_to_int;
601 gcc_jit_function *cast_int_to_ptr; 626 gcc_jit_function *cast_int_to_ptr;
602 gcc_jit_type *cast_types[NUM_CAST_TYPES]; 627 gcc_jit_type *cast_types[NUM_CAST_TYPES];
628#endif
603 gcc_jit_function *func; /* Current function being compiled. */ 629 gcc_jit_function *func; /* Current function being compiled. */
604 bool func_has_non_local; /* From comp-func has-non-local slot. */ 630 bool func_has_non_local; /* From comp-func has-non-local slot. */
605 EMACS_INT func_speed; /* From comp-func speed slot. */ 631 EMACS_INT func_speed; /* From comp-func speed slot. */
@@ -1100,6 +1126,7 @@ emit_cond_jump (gcc_jit_rvalue *test,
1100 1126
1101} 1127}
1102 1128
1129#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
1103static int 1130static int
1104type_to_cast_index (gcc_jit_type * type) 1131type_to_cast_index (gcc_jit_type * type)
1105{ 1132{
@@ -1109,6 +1136,7 @@ type_to_cast_index (gcc_jit_type * type)
1109 1136
1110 xsignal1 (Qnative_ice, build_string ("unsupported cast")); 1137 xsignal1 (Qnative_ice, build_string ("unsupported cast"));
1111} 1138}
1139#endif
1112 1140
1113static gcc_jit_rvalue * 1141static gcc_jit_rvalue *
1114emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj) 1142emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
@@ -1145,14 +1173,48 @@ emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
1145 } 1173 }
1146#endif 1174#endif
1147 1175
1176#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
1177 bool old_is_ptr = gcc_jit_type_is_pointer (old_type) != NULL;
1178 bool new_is_ptr = gcc_jit_type_is_pointer (new_type) != NULL;
1179
1180 gcc_jit_rvalue *tmp = obj;
1181
1182 /* `gcc_jit_context_new_bitcast` requires that the types being converted
1183 between have the same layout and as such, doesn't allow converting
1184 between an arbitrarily sized integer/boolean and a pointer. Casting it
1185 to a uintptr/void* is still necessary, to ensure that it can be bitcast
1186 into a (void *)/uintptr respectively. */
1187 if (old_is_ptr != new_is_ptr)
1188 {
1189 if (old_is_ptr)
1190 {
1191 tmp = gcc_jit_context_new_cast (comp.ctxt, NULL, tmp,
1192 comp.void_ptr_type);
1193 tmp = gcc_jit_context_new_bitcast (comp.ctxt, NULL, tmp,
1194 comp.uintptr_type);
1195 }
1196 else
1197 {
1198 tmp = gcc_jit_context_new_cast (comp.ctxt, NULL, tmp,
1199 comp.uintptr_type);
1200 tmp = gcc_jit_context_new_bitcast (comp.ctxt, NULL, tmp,
1201 comp.void_ptr_type);
1202 }
1203 }
1204 return gcc_jit_context_new_cast (comp.ctxt, NULL, tmp, new_type);
1205
1206#else /* !LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast */
1207
1148 int old_index = type_to_cast_index (old_type); 1208 int old_index = type_to_cast_index (old_type);
1149 int new_index = type_to_cast_index (new_type); 1209 int new_index = type_to_cast_index (new_type);
1150 1210
1151 /* Lookup the appropriate cast function in the cast matrix. */ 1211 /* Lookup the appropriate cast function in the cast matrix. */
1152 return gcc_jit_context_new_call (comp.ctxt, 1212 return gcc_jit_context_new_call (comp.ctxt,
1153 NULL, 1213 NULL,
1154 comp.cast_functions_from_to[old_index][new_index], 1214 comp.cast_functions_from_to
1155 1, &obj); 1215 [old_index][new_index],
1216 1, &obj);
1217#endif
1156} 1218}
1157 1219
1158static gcc_jit_rvalue * 1220static gcc_jit_rvalue *
@@ -3318,6 +3380,7 @@ define_thread_state_struct (void)
3318 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s)); 3380 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s));
3319} 3381}
3320 3382
3383#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
3321static gcc_jit_function * 3384static gcc_jit_function *
3322define_type_punning (const char *name, 3385define_type_punning (const char *name,
3323 gcc_jit_type *from, gcc_jit_field *from_field, 3386 gcc_jit_type *from, gcc_jit_field *from_field,
@@ -3451,6 +3514,7 @@ define_cast_functions (void)
3451 comp.void_ptr_type, 3514 comp.void_ptr_type,
3452 cast_union_fields[0]); 3515 cast_union_fields[0]);
3453 3516
3517
3454 for (int i = 0; i < NUM_CAST_TYPES; ++i) 3518 for (int i = 0; i < NUM_CAST_TYPES; ++i)
3455 comp.cast_types[i] = cast_types[i].type; 3519 comp.cast_types[i] = cast_types[i].type;
3456 3520
@@ -3460,6 +3524,7 @@ define_cast_functions (void)
3460 comp.cast_functions_from_to[i][j] = 3524 comp.cast_functions_from_to[i][j] =
3461 define_cast_from_to (cast_types[i], cast_types[j]); 3525 define_cast_from_to (cast_types[i], cast_types[j]);
3462} 3526}
3527#endif /* !LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast */
3463 3528
3464static void 3529static void
3465define_CHECK_TYPE (void) 3530define_CHECK_TYPE (void)
@@ -4467,7 +4532,7 @@ the latter is supposed to be used by the Emacs build procedure. */)
4467 } 4532 }
4468 if (NILP (base_dir)) 4533 if (NILP (base_dir))
4469 error ("Cannot find suitable directory for output in " 4534 error ("Cannot find suitable directory for output in "
4470 "`comp-native-load-path'."); 4535 "`native-comp-eln-load-path'.");
4471 } 4536 }
4472 4537
4473 if (!file_name_absolute_p (SSDATA (base_dir))) 4538 if (!file_name_absolute_p (SSDATA (base_dir)))
@@ -4660,7 +4725,9 @@ Return t on success. */)
4660 define_jmp_buf (); 4725 define_jmp_buf ();
4661 define_handler_struct (); 4726 define_handler_struct ();
4662 define_thread_state_struct (); 4727 define_thread_state_struct ();
4728#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
4663 define_cast_functions (); 4729 define_cast_functions ();
4730#endif
4664 4731
4665 return Qt; 4732 return Qt;
4666} 4733}
@@ -5107,6 +5174,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
5107 return; 5174 return;
5108 5175
5109 if (!native_comp_deferred_compilation 5176 if (!native_comp_deferred_compilation
5177 || !NILP (Vinhibit_automatic_native_compilation)
5110 || noninteractive 5178 || noninteractive
5111 || !NILP (Vpurify_flag) 5179 || !NILP (Vpurify_flag)
5112 || !COMPILEDP (definition) 5180 || !COMPILEDP (definition)
@@ -5610,6 +5678,14 @@ For internal use. */);
5610 doc: /* Non-nil when comp.el can be native compiled. 5678 doc: /* Non-nil when comp.el can be native compiled.
5611For internal use. */); 5679For internal use. */);
5612 /* Compiler control customizes. */ 5680 /* Compiler control customizes. */
5681 DEFVAR_LISP ("inhibit-automatic-native-compilation",
5682 Vinhibit_automatic_native_compilation,
5683 doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files.
5684
5685After compilation, each function definition is updated to the native
5686compiled one. */);
5687 Vinhibit_automatic_native_compilation = Qnil;
5688
5613 DEFVAR_BOOL ("native-comp-deferred-compilation", 5689 DEFVAR_BOOL ("native-comp-deferred-compilation",
5614 native_comp_deferred_compilation, 5690 native_comp_deferred_compilation,
5615 doc: /* If non-nil compile loaded .elc files asynchronously. 5691 doc: /* If non-nil compile loaded .elc files asynchronously.
@@ -5792,8 +5868,21 @@ The last directory of this list is assumed to be the system one. */);
5792 Vnative_comp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil); 5868 Vnative_comp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil);
5793 5869
5794 DEFVAR_BOOL ("comp-enable-subr-trampolines", comp_enable_subr_trampolines, 5870 DEFVAR_BOOL ("comp-enable-subr-trampolines", comp_enable_subr_trampolines,
5795 doc: /* If non-nil enable primitive trampoline synthesis. 5871 doc: /* If non-nil, enable primitive trampoline synthesis.
5796This makes primitive functions redefinable or advisable effectively. */); 5872This makes Emacs respect redefinition or advises of primitive functions
5873when they are called from Lisp code natively-compiled at `native-comp-speed'
5874of 2.
5875
5876By default, this is enabled, and when Emacs sees a redefined or advised
5877primitive called from natively-compiled Lisp, it generates a trampoline
5878for it on-the-fly.
5879
5880Disabling this, when a trampoline for a redefined or advised primitive is
5881not available from previous compilations, means that such redefinition
5882or advise will not have effect on calls from natively-compiled Lisp code.
5883That is, calls to primitives without existing trampolines from
5884natively-compiled Lisp will behave as if the primitive was called
5885directly from C. */);
5797 5886
5798 DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h, 5887 DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h,
5799 doc: /* Hash table subr-name -> installed trampoline. 5888 doc: /* Hash table subr-name -> installed trampoline.