]> git.eshelyaron.com Git - emacs.git/commitdiff
fix broken selfcall optimization
authorAndrea Corallo <akrl@sdf.org>
Mon, 9 Sep 2019 19:35:31 +0000 (21:35 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:37:46 +0000 (11:37 +0100)
src/comp.c

index f966a2427b7f8cd9da31482ed20dd6691b796d2a..98932f79bb00d12cb3de5eb3684eae7790f7c481 100644 (file)
@@ -147,6 +147,7 @@ typedef struct {
   gcc_jit_field *cast_union_as_lisp_obj;
   gcc_jit_field *cast_union_as_lisp_obj_ptr;
   gcc_jit_function *func; /* Current function being compiled.  */
+  Lisp_Object lfunc;
   gcc_jit_block *block;  /* Current basic block being compiled.  */
   gcc_jit_lvalue **frame; /* Frame for the current function.  */
   gcc_jit_rvalue *most_positive_fixnum;
@@ -210,7 +211,7 @@ static void
 ice (const char* msg)
 {
   if (msg)
-    msg = format_string ("Internal native compiler error:  %s", msg);
+    msg = format_string ("Internal native compiler error: %s", msg);
   else
     msg = "Internal native compiler error";
   error ("%s", msg);
@@ -394,6 +395,16 @@ static gcc_jit_rvalue *
 emit_call (Lisp_Object subr_sym, gcc_jit_type *ret_type, unsigned nargs,
           gcc_jit_rvalue **args)
 {
+  /* Self call optimization.  */
+  if (!NILP (comp.lfunc) &&
+      comp_speed >= 2 &&
+      EQ (subr_sym, FUNCALL1 (comp-func-symbol-name, comp.lfunc)))
+    return gcc_jit_context_new_call (comp.ctxt,
+                                    NULL,
+                                    comp.func,
+                                    nargs,
+                                    args);
+
   Lisp_Object value = Fgethash (subr_sym, comp.func_hash, Qnil);
   ICE_IF (NILP (value), "missing function declaration");
 
@@ -2651,6 +2662,8 @@ compile_function (Lisp_Object func)
   EMACS_INT frame_size = XFIXNUM (FUNCALL1 (comp-func-frame-size, func));
   bool ncall = (FUNCALL1 (comp-nargs-p, args));
 
+  comp.lfunc = func;
+
   if (!ncall)
     {
       EMACS_INT max_args = XFIXNUM (FUNCALL1 (comp-args-max, args));
@@ -2733,6 +2746,7 @@ compile_function (Lisp_Object func)
          format_string ("failing to compile function %s with error: %s",
                         SSDATA (SYMBOL_NAME (FUNCALL1 (comp-func-symbol-name, func))),
                         err));
+  comp.lfunc = Qnil;
   SAFE_FREE ();
 }