[前][次][番号順一覧][スレッド一覧]

ruby-changes:61395

From: Takashi <ko1@a...>
Date: Wed, 27 May 2020 15:02:18 +0900 (JST)
Subject: [ruby-changes:61395] 61b14bb32b (master): Eliminate a call instruction on JIT cancel path

https://git.ruby-lang.org/ruby.git/commit/?id=61b14bb32b

From 61b14bb32b7e62760225cb2207df5fe87e5339ab Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Tue, 26 May 2020 22:49:55 -0700
Subject: Eliminate a call instruction on JIT cancel path

by calling combined functions specialized for each cancel type.

I'm hoping to improve locality of hot code, but this patch's impact should
be insignificant.

diff --git a/mjit.c b/mjit.c
index 4b2e7c5..f2443e0 100644
--- a/mjit.c
+++ b/mjit.c
@@ -455,8 +455,8 @@ rb_mjit_iseq_compile_info(const struct rb_iseq_constant_body *body) https://github.com/ruby/ruby/blob/trunk/mjit.c#L455
     return &body->jit_unit->compile_info;
 }
 
-void
-rb_mjit_recompile_iseq(const rb_iseq_t *iseq)
+static void
+mjit_recompile(const rb_iseq_t *iseq)
 {
     if ((uintptr_t)iseq->body->jit_func <= (uintptr_t)LAST_JIT_ISEQ_FUNC)
         return;
@@ -476,6 +476,38 @@ rb_mjit_recompile_iseq(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/mjit.c#L476
     }
 }
 
+// Recompile iseq, disabling send optimization
+void
+rb_mjit_recompile_send(const rb_iseq_t *iseq)
+{
+    rb_mjit_iseq_compile_info(iseq->body)->disable_send_cache = true;
+    mjit_recompile(iseq);
+}
+
+// Recompile iseq, disabling ivar optimization
+void
+rb_mjit_recompile_ivar(const rb_iseq_t *iseq)
+{
+    rb_mjit_iseq_compile_info(iseq->body)->disable_ivar_cache = true;
+    mjit_recompile(iseq);
+}
+
+// Recompile iseq, disabling exivar optimization
+void
+rb_mjit_recompile_exivar(const rb_iseq_t *iseq)
+{
+    rb_mjit_iseq_compile_info(iseq->body)->disable_exivar_cache = true;
+    mjit_recompile(iseq);
+}
+
+// Recompile iseq, disabling method inlining
+void
+rb_mjit_recompile_inlining(const rb_iseq_t *iseq)
+{
+    rb_mjit_iseq_compile_info(iseq->body)->disable_inlining = true;
+    mjit_recompile(iseq);
+}
+
 extern VALUE ruby_archlibdir_path, ruby_prefix_path;
 
 // Initialize header_file, pch_file, libruby_pathflag. Return true on success.
diff --git a/mjit.h b/mjit.h
index 72d865e..0c93896 100644
--- a/mjit.h
+++ b/mjit.h
@@ -80,7 +80,10 @@ RUBY_EXTERN bool mjit_call_p; https://github.com/ruby/ruby/blob/trunk/mjit.h#L80
 extern void rb_mjit_add_iseq_to_process(const rb_iseq_t *iseq);
 extern VALUE rb_mjit_wait_call(rb_execution_context_t *ec, struct rb_iseq_constant_body *body);
 extern struct rb_mjit_compile_info* rb_mjit_iseq_compile_info(const struct rb_iseq_constant_body *body);
-extern void rb_mjit_recompile_iseq(const rb_iseq_t *iseq);
+extern void rb_mjit_recompile_send(const rb_iseq_t *iseq);
+extern void rb_mjit_recompile_ivar(const rb_iseq_t *iseq);
+extern void rb_mjit_recompile_exivar(const rb_iseq_t *iseq);
+extern void rb_mjit_recompile_inlining(const rb_iseq_t *iseq);
 RUBY_SYMBOL_EXPORT_END
 
 extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id);
diff --git a/mjit_compile.c b/mjit_compile.c
index 6a17d24..fe5c241 100644
--- a/mjit_compile.c
+++ b/mjit_compile.c
@@ -241,8 +241,7 @@ compile_inlined_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L241
 {
     fprintf(f, "\ncancel:\n");
     fprintf(f, "    RB_DEBUG_COUNTER_INC(mjit_cancel);\n");
-    fprintf(f, "    rb_mjit_iseq_compile_info(original_iseq->body)->disable_inlining = true;\n");
-    fprintf(f, "    rb_mjit_recompile_iseq(original_iseq);\n");
+    fprintf(f, "    rb_mjit_recompile_inlining(original_iseq);\n");
 
     // Swap pc/sp set on cancel with original pc/sp.
     fprintf(f, "    const VALUE *current_pc = reg_cfp->pc;\n");
@@ -282,20 +281,17 @@ compile_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body, struct https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L281
 
     fprintf(f, "\nsend_cancel:\n");
     fprintf(f, "    RB_DEBUG_COUNTER_INC(mjit_cancel_send_inline);\n");
-    fprintf(f, "    rb_mjit_iseq_compile_info(original_iseq->body)->disable_send_cache = true;\n");
-    fprintf(f, "    rb_mjit_recompile_iseq(original_iseq);\n");
+    fprintf(f, "    rb_mjit_recompile_send(original_iseq);\n");
     fprintf(f, "    goto cancel;\n");
 
     fprintf(f, "\nivar_cancel:\n");
     fprintf(f, "    RB_DEBUG_COUNTER_INC(mjit_cancel_ivar_inline);\n");
-    fprintf(f, "    rb_mjit_iseq_compile_info(original_iseq->body)->disable_ivar_cache = true;\n");
-    fprintf(f, "    rb_mjit_recompile_iseq(original_iseq);\n");
+    fprintf(f, "    rb_mjit_recompile_ivar(original_iseq);\n");
     fprintf(f, "    goto cancel;\n");
 
     fprintf(f, "\nexivar_cancel:\n");
     fprintf(f, "    RB_DEBUG_COUNTER_INC(mjit_cancel_exivar_inline);\n");
-    fprintf(f, "    rb_mjit_iseq_compile_info(original_iseq->body)->disable_exivar_cache = true;\n");
-    fprintf(f, "    rb_mjit_recompile_iseq(original_iseq);\n");
+    fprintf(f, "    rb_mjit_recompile_exivar(original_iseq);\n");
     fprintf(f, "    goto cancel;\n");
 
     fprintf(f, "\ncancel:\n");
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]