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

ruby-changes:52072

From: k0kubun <ko1@a...>
Date: Sat, 11 Aug 2018 12:38:44 +0900 (JST)
Subject: [ruby-changes:52072] k0kubun:r64280 (trunk): _mjit_compile_send.erb: refactor to share vm_call_iseq_setup_normal

k0kubun	2018-08-11 12:38:38 +0900 (Sat, 11 Aug 2018)

  New Revision: 64280

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64280

  Log:
    _mjit_compile_send.erb: refactor to share vm_call_iseq_setup_normal
    
    implementation. This had no major performance impact by effort to keep
    them inlined.
    
    vm_insnhelper.c: ditto
    
    mjit_compile.c: just update the comment about opt_pc=0 assumption

  Modified files:
    trunk/mjit_compile.c
    trunk/tool/ruby_vm/views/_mjit_compile_send.erb
    trunk/vm_insnhelper.c
Index: tool/ruby_vm/views/_mjit_compile_send.erb
===================================================================
--- tool/ruby_vm/views/_mjit_compile_send.erb	(revision 64279)
+++ tool/ruby_vm/views/_mjit_compile_send.erb	(revision 64280)
@@ -37,23 +37,18 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_send.erb#L37
 
 % # JIT: Print insn body in insns.def
             fprintf(f, "    {\n");
-            fprintf(f, "        struct rb_calling_info calling;\n");
+            fprintf(f, "        VALUE block_handler = VM_BLOCK_HANDLER_NONE;\n");
 % if insn.name == 'send'
+            fprintf(f, "        struct rb_calling_info calling;\n");
             fprintf(f, "        vm_caller_setup_arg_block(ec, reg_cfp, &calling, (CALL_INFO)0x%"PRIxVALUE", (rb_iseq_t *)0x%"PRIxVALUE", FALSE);\n", operands[0], operands[2]);
-% else
-            fprintf(f, "        calling.block_handler = VM_BLOCK_HANDLER_NONE;\n");
+            fprintf(f, "        block_handler = calling.block_handler;\n");
 % end
-            fprintf(f, "        calling.argc = %d;\n", ci->orig_argc);
-            fprintf(f, "        calling.recv = stack[%d];\n", b->stack_size - 1 - argc);
-
-% # JIT: Special CALL_METHOD. Inline vm_call_iseq_setup_normal for vm_call_iseq_setup_func FASTPATH. TODO: modify VM to share code with here
+% # JIT: Special CALL_METHOD. Inline vm_call_iseq_setup_normal for vm_call_iseq_setup_func FASTPATH.
             fprintf(f, "        {\n");
             fprintf(f, "            VALUE v;\n");
-            fprintf(f, "            VALUE *argv = reg_cfp->sp - calling.argc;\n");
-            fprintf(f, "            reg_cfp->sp = argv - 1;\n"); /* recv */
-            fprintf(f, "            vm_push_frame(ec, (const rb_iseq_t *)0x%"PRIxVALUE", VM_FRAME_MAGIC_METHOD | VM_ENV_FLAG_LOCAL, calling.recv, "
-                    "calling.block_handler, 0x%"PRIxVALUE", (const VALUE *)0x%"PRIxVALUE", argv + %d, %d, %d);\n",
-                    (VALUE)iseq, (VALUE)cc->me, (VALUE)iseq->body->iseq_encoded, param_size, iseq->body->local_table_size - param_size, iseq->body->stack_max);
+            fprintf(f, "            const rb_callable_method_entry_t *me = 0x%"PRIxVALUE";\n", (VALUE)cc->me);
+            fprintf(f, "            vm_call_iseq_setup_normal_internal(ec, reg_cfp, %d, stack[%d], block_handler, me, (const rb_iseq_t *)0x%"PRIxVALUE", (const VALUE *)0x%"PRIxVALUE", %d, %d, %d);\n",
+                    argc, b->stack_size - 1 - argc, (VALUE)iseq, (VALUE)iseq->body->iseq_encoded, param_size, iseq->body->local_table_size, iseq->body->stack_max);
             if (iseq->body->catch_except_p) {
                 fprintf(f, "            VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);\n");
                 fprintf(f, "            v = vm_exec(ec, TRUE);\n");
Index: mjit_compile.c
===================================================================
--- mjit_compile.c	(revision 64279)
+++ mjit_compile.c	(revision 64280)
@@ -58,7 +58,7 @@ inlinable_iseq_p(CALL_INFO ci, CALL_CACH https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L58
 {
     extern int rb_simple_iseq_p(const rb_iseq_t *iseq);
     return iseq != NULL
-        && rb_simple_iseq_p(iseq) && !(ci->flag & VM_CALL_KW_SPLAT) /* top of vm_callee_setup_arg */
+        && rb_simple_iseq_p(iseq) && !(ci->flag & VM_CALL_KW_SPLAT) /* Top of vm_callee_setup_arg. In this case, opt_pc is 0. */
         && (!IS_ARGS_SPLAT(ci) && !IS_ARGS_KEYWORD(ci) && !(METHOD_ENTRY_VISI(cc->me) == METHOD_VISI_PROTECTED)); /* CI_SET_FASTPATH */
 }
 
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 64279)
+++ vm_insnhelper.c	(revision 64280)
@@ -1657,25 +1657,35 @@ vm_call_iseq_setup_2(rb_execution_contex https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1657
     }
 }
 
+/* Used in JIT to ensure intended me is used and to reduce memory access by inlining values. */
+ALWAYS_INLINE(static inline VALUE vm_call_iseq_setup_normal_internal(rb_execution_context_t *ec, rb_control_frame_t *cfp, int argc, VALUE recv, VALUE block_handler, const rb_callable_method_entry_t *me, const rb_iseq_t *iseq, const VALUE *pc, int param_size, int local_size, int stack_max));
 static inline VALUE
-vm_call_iseq_setup_normal(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc,
-			  int opt_pc, int param_size, int local_size)
+vm_call_iseq_setup_normal_internal(rb_execution_context_t *ec, rb_control_frame_t *cfp, int argc, VALUE recv, VALUE block_handler, const rb_callable_method_entry_t *me,
+                                   const rb_iseq_t *iseq, const VALUE *pc, int param_size, int local_size, int stack_max)
 {
-    const rb_callable_method_entry_t *me = cc->me;
-    const rb_iseq_t *iseq = def_iseq_ptr(me->def);
-    VALUE *argv = cfp->sp - calling->argc;
+    VALUE *argv = cfp->sp - argc;
     VALUE *sp = argv + param_size;
     cfp->sp = argv - 1 /* recv */;
 
-    vm_push_frame(ec, iseq, VM_FRAME_MAGIC_METHOD | VM_ENV_FLAG_LOCAL, calling->recv,
-		  calling->block_handler, (VALUE)me,
-		  iseq->body->iseq_encoded + opt_pc, sp,
-		  local_size - param_size,
-		  iseq->body->stack_max);
+    vm_push_frame(ec, iseq, VM_FRAME_MAGIC_METHOD | VM_ENV_FLAG_LOCAL, recv,
+                  block_handler, (VALUE)me,
+                  pc, sp,
+                  local_size - param_size,
+                  stack_max);
     return Qundef;
 }
 
 static inline VALUE
+vm_call_iseq_setup_normal(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc,
+                          int opt_pc, int param_size, int local_size)
+{
+    const rb_callable_method_entry_t *me = cc->me;
+    const rb_iseq_t *iseq = def_iseq_ptr(me->def);
+    return vm_call_iseq_setup_normal_internal(ec, cfp, calling->argc, calling->recv, calling->block_handler, me, iseq,
+                                              iseq->body->iseq_encoded + opt_pc, param_size, local_size, iseq->body->stack_max);
+}
+
+static inline VALUE
 vm_call_iseq_setup_tailcall(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc,
 			    int opt_pc)
 {

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

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