From 6dd4657fc2bbbb1aad36afc24dcb19553fd41ab6 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Thu, 3 May 2018 08:47:32 +0000 Subject: _mjit_compile_send.erb: retry inlining attr_reader This reverts r63249 (revert r63212) and fixes a bug in it. The test to prevent the bug is added as well. vm_insnhelper.c: add `index` argument to vm_getivar. The argument is created so that MJIT can pass the value of `cc->aux.index` on compilation time. The cache invalidation in _mjit_compile_send_guard.erb is only working for the cache value on compilation time. Note: As `index` is always passed as constant and it's force-inlined, the performance of `vm_getivar` won't be degraded in VM. _mjit_compile_send_guard.erb: New. Used to invalidate inlined values of cc. common.mk: update dependencies for _mjit_compile_send_guard.erb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/ruby_vm/views/_mjit_compile_send.erb | 26 +++++++++++++++++-------- tool/ruby_vm/views/_mjit_compile_send_guard.erb | 14 +++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 tool/ruby_vm/views/_mjit_compile_send_guard.erb (limited to 'tool') diff --git a/tool/ruby_vm/views/_mjit_compile_send.erb b/tool/ruby_vm/views/_mjit_compile_send.erb index 9b8225c8c5..cb7c1f40f8 100644 --- a/tool/ruby_vm/views/_mjit_compile_send.erb +++ b/tool/ruby_vm/views/_mjit_compile_send.erb @@ -20,7 +20,7 @@ argc += ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0); % end - if (cc->me->def->type == VM_METHOD_TYPE_ISEQ && inlinable_iseq_p(ci, cc, iseq = rb_iseq_check(cc->me->def->body.iseq.iseqptr))) { + if (cc->me->def->type == VM_METHOD_TYPE_ISEQ && inlinable_iseq_p(ci, cc, iseq = rb_iseq_check(cc->me->def->body.iseq.iseqptr))) { /* CI_SET_FASTPATH in vm_callee_setup_arg */ int param_size = iseq->body->param.size; /* TODO: check calling->argc for argument_arity_error */ fprintf(f, "{\n"); @@ -29,16 +29,12 @@ fprintf(f, " MAYBE_UNUSED(unsigned int) stack_size = %u;\n", b->stack_size); } +% # JIT: Invalidate call cache if it requires vm_search_method. This allows to inline some of following things. +<%= render 'mjit_compile_send_guard' -%> + % # JIT: move sp and pc if necessary <%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%> -% # JIT: Invalidate call cache if it requires vm_search_method. This allows to inline some of following things. - fprintf(f, " if (UNLIKELY(GET_GLOBAL_METHOD_STATE() != %"PRI_SERIALT_PREFIX"u ||\n", cc->method_state); - fprintf(f, " RCLASS_SERIAL(CLASS_OF(stack[%d])) != %"PRI_SERIALT_PREFIX"u)) {\n", b->stack_size - 1 - argc, cc->class_serial); - fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); - fprintf(f, " goto cancel;\n"); - fprintf(f, " }\n"); - % # JIT: Print insn body in insns.def fprintf(f, " {\n"); fprintf(f, " struct rb_calling_info calling;\n"); @@ -88,5 +84,19 @@ fprintf(f, "}\n"); break; } +% if insn.name == 'opt_send_without_block' + else if (cc->me->def->type == VM_METHOD_TYPE_IVAR && !(ci->flag & VM_CALL_ARGS_SPLAT)) { /* CI_SET_FASTPATH with vm_call_ivar */ +% # JIT: Invalidate call cache if it requires vm_search_method. This allows to inline some of following things. +<%= render 'mjit_compile_send_guard' -%> + +% # JIT: vm_call_ivar without sp motion + fprintf(f, " stack[%d] = vm_getivar(stack[%d], (ID)0x%"PRIxVALUE", NULL, (CALL_CACHE)0x%"PRIxVALUE", (st_index_t)%ld, 1);\n", + b->stack_size - argc - 1, b->stack_size - argc - 1, cc->me->def->body.attr.id, (VALUE)cc, (long)cc->aux.index); + +% # compiler: Move JIT compiler's internal stack pointer + b->stack_size += <%= insn.call_attribute('sp_inc') %>; + break; + } +% end } } diff --git a/tool/ruby_vm/views/_mjit_compile_send_guard.erb b/tool/ruby_vm/views/_mjit_compile_send_guard.erb new file mode 100644 index 0000000000..7bdb2a3ebf --- /dev/null +++ b/tool/ruby_vm/views/_mjit_compile_send_guard.erb @@ -0,0 +1,14 @@ +% # Copyright (c) 2018 Takashi Kokubun. All rights reserved. +% # +% # This file is a part of the programming language Ruby. Permission is hereby +% # granted, to either redistribute and/or modify this file, provided that the +% # conditions mentioned in the file COPYING are met. Consult the file for +% # details. +% +% # JIT: Invalidate call cache if it requires vm_search_method. This allows to inline some of following things. + fprintf(f, " if (UNLIKELY(GET_GLOBAL_METHOD_STATE() != %"PRI_SERIALT_PREFIX"u ||\n", cc->method_state); + fprintf(f, " RCLASS_SERIAL(CLASS_OF(stack[%d])) != %"PRI_SERIALT_PREFIX"u)) {\n", b->stack_size - 1 - argc, cc->class_serial); + fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); + fprintf(f, " reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1); + fprintf(f, " goto cancel;\n"); + fprintf(f, " }\n"); -- cgit v1.2.3