summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-16 17:02:16 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-16 17:02:16 +0000
commitd71b78575b08f55d35194b2c091719b2c4463ea3 (patch)
treedd0dba7549e3bc80ddc70c24c7e10120b5acf54e /tool
parentb914166fcdba3faf5d4cb5e3a18d49691546ce21 (diff)
Introduce frame-omitted method inlining
for ISeq including only leaf and no-handles_sp insns except leaf. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r--tool/ruby_vm/views/_insn_sp_pc_dependency.erb27
-rw-r--r--tool/ruby_vm/views/_mjit_compile_send.erb73
-rw-r--r--tool/ruby_vm/views/insns_info.inc.erb1
-rw-r--r--tool/ruby_vm/views/mjit_compile.inc.erb6
4 files changed, 73 insertions, 34 deletions
diff --git a/tool/ruby_vm/views/_insn_sp_pc_dependency.erb b/tool/ruby_vm/views/_insn_sp_pc_dependency.erb
new file mode 100644
index 0000000000..95528fbbf4
--- /dev/null
+++ b/tool/ruby_vm/views/_insn_sp_pc_dependency.erb
@@ -0,0 +1,27 @@
+%# -*- C -*-
+%# Copyright (c) 2019 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.
+%#
+PUREFUNC(MAYBE_UNUSED(static bool insn_may_depend_on_sp_or_pc(int insn, const VALUE *opes)));
+
+static bool
+insn_may_depend_on_sp_or_pc(int insn, const VALUE *opes)
+{
+ switch (insn) {
+% RubyVM::Instructions.each do |insn|
+% # handles_sp?: If true, it requires to move sp in JIT
+% # always_leaf?: If false, it may call an arbitrary method. pc should be moved
+% # before the call, and the method may refer to caller's pc (lineno).
+% unless !insn.is_a?(RubyVM::TraceInstructions) && !insn.handles_sp? && insn.always_leaf?
+ case <%= insn.bin %>:
+% end
+% end
+ return true;
+ default:
+ return false;
+ }
+}
diff --git a/tool/ruby_vm/views/_mjit_compile_send.erb b/tool/ruby_vm/views/_mjit_compile_send.erb
index 41a77189d9..8904d15a3e 100644
--- a/tool/ruby_vm/views/_mjit_compile_send.erb
+++ b/tool/ruby_vm/views/_mjit_compile_send.erb
@@ -24,7 +24,7 @@
% end
if (!(ci->flag & VM_CALL_TAILCALL) // inlining non-tailcall path
- && cc_copy->me->def->type == VM_METHOD_TYPE_ISEQ && inlinable_iseq_p(ci, cc_copy, iseq = def_iseq_ptr(cc_copy->me->def))) { // CC_SET_FASTPATH in vm_callee_setup_arg
+ && cc_copy->me->def->type == VM_METHOD_TYPE_ISEQ && fastpath_applied_iseq_p(ci, cc_copy, iseq = def_iseq_ptr(cc_copy->me->def))) { // CC_SET_FASTPATH in vm_callee_setup_arg
int param_size = iseq->body->param.size;
fprintf(f, "{\n");
@@ -44,52 +44,57 @@
% # JIT: move sp and pc if necessary
<%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%>
+% # JIT: If ISeq is inlinable, call the inlined method without pushing a frame.
+ if (status->inlined_iseqs != NULL && status->inlined_iseqs[pos] == iseq->body) {
+ fprintf(f, " {\n");
+ fprintf(f, " VALUE orig_self = reg_cfp->self;\n");
+ fprintf(f, " reg_cfp->self = stack[%d];\n", b->stack_size - argc - 1);
+ fprintf(f, " stack[%d] = _mjit_inlined_%d(ec, reg_cfp, orig_self);\n", b->stack_size - argc - 1, pos);
+ fprintf(f, " reg_cfp->self = orig_self;\n");
+ fprintf(f, " }\n");
+ }
+ else {
% # JIT: Print insn body in insns.def
- fprintf(f, " {\n");
- fprintf(f, " struct rb_calling_info calling;\n");
+ fprintf(f, " {\n");
+ fprintf(f, " struct rb_calling_info calling;\n");
% if insn.name == 'send'
- fprintf(f, " calling.block_handler = vm_caller_setup_arg_block(ec, reg_cfp, (CALL_INFO)0x%"PRIxVALUE", (rb_iseq_t *)0x%"PRIxVALUE", FALSE);\n", operands[0], operands[2]);
+ fprintf(f, " calling.block_handler = vm_caller_setup_arg_block(ec, reg_cfp, (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, " calling.block_handler = VM_BLOCK_HANDLER_NONE;\n");
% end
- fprintf(f, " calling.argc = %d;\n", ci->orig_argc);
- fprintf(f, " calling.recv = stack[%d];\n", b->stack_size - 1 - argc);
+ 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. Bypass cc_copy->call and inline vm_call_iseq_setup_normal for vm_call_iseq_setup_func FASTPATH.
- fprintf(f, " {\n");
- fprintf(f, " VALUE v;\n");
- fprintf(f, " vm_call_iseq_setup_normal(ec, reg_cfp, &calling, (const rb_callable_method_entry_t *)0x%"PRIxVALUE", 0, %d, %d);\n",
- (VALUE)cc_copy->me, param_size, iseq->body->local_table_size); /* inlinable_iseq_p checks rb_simple_iseq_p, which ensures has_opt == FALSE */
- 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");
- }
- else {
- if (status->iseq_for_pos != NULL && status->iseq_for_pos[pos] == iseq->body) {
- fprintf(f, " v = _mjit_inlined_%d(ec, ec->cfp);\n", pos);
+ fprintf(f, " {\n");
+ fprintf(f, " VALUE v;\n");
+ fprintf(f, " vm_call_iseq_setup_normal(ec, reg_cfp, &calling, (const rb_callable_method_entry_t *)0x%"PRIxVALUE", 0, %d, %d);\n",
+ (VALUE)cc_copy->me, param_size, iseq->body->local_table_size); // fastpath_applied_iseq_p checks rb_simple_iseq_p, which ensures has_opt == FALSE
+ 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");
}
else {
- fprintf(f, " v = mjit_exec(ec);\n");
+ fprintf(f, " if ((v = mjit_exec(ec)) == Qundef) {\n");
+ fprintf(f, " VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);\n"); // This is vm_call0_body's code after vm_call_iseq_setup
+ fprintf(f, " v = vm_exec(ec, FALSE);\n");
+ fprintf(f, " }\n");
}
- fprintf(f, " if (v == Qundef) {\n");
- fprintf(f, " VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);\n"); /* This is vm_call0_body's code after vm_call_iseq_setup */
- fprintf(f, " v = vm_exec(ec, FALSE);\n");
- fprintf(f, " }\n");
- }
- fprintf(f, " stack[%d] = v;\n", b->stack_size - argc - 1);
- fprintf(f, " }\n");
+ fprintf(f, " stack[%d] = v;\n", b->stack_size - argc - 1);
+ fprintf(f, " }\n");
- fprintf(f, " }\n");
+ fprintf(f, " }\n");
% # JIT: We should evaluate ISeq modified for TracePoint if it's enabled. Note: This is slow.
- fprintf(f, " if (UNLIKELY(ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS)) {\n");
- fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size + (int)<%= insn.call_attribute('sp_inc') %>);
- if (!pc_moved_p) {
- fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", next_pos);
+ fprintf(f, " if (UNLIKELY(ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS)) {\n");
+ fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size + (int)<%= insn.call_attribute('sp_inc') %>);
+ if (!pc_moved_p) {
+ fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", next_pos);
+ }
+ fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_trace);\n");
+ fprintf(f, " goto cancel;\n");
+ fprintf(f, " }\n");
}
- fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_trace);\n");
- fprintf(f, " goto cancel;\n");
- fprintf(f, " }\n");
% # compiler: Move JIT compiler's internal stack pointer
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
diff --git a/tool/ruby_vm/views/insns_info.inc.erb b/tool/ruby_vm/views/insns_info.inc.erb
index 532cdbaa88..e5793a2a70 100644
--- a/tool/ruby_vm/views/insns_info.inc.erb
+++ b/tool/ruby_vm/views/insns_info.inc.erb
@@ -19,3 +19,4 @@
<%= render 'sp_inc_helpers' %>
<%= render 'attributes' %>
<%= render 'insn_stack_increase' %>
+<%= render 'insn_sp_pc_dependency' %>
diff --git a/tool/ruby_vm/views/mjit_compile.inc.erb b/tool/ruby_vm/views/mjit_compile.inc.erb
index a3e29116cf..1812dabf4a 100644
--- a/tool/ruby_vm/views/mjit_compile.inc.erb
+++ b/tool/ruby_vm/views/mjit_compile.inc.erb
@@ -71,6 +71,12 @@ switch (insn) {
fprintf(stderr, "MJIT warning: Unexpected JIT stack_size on leave: %d\n", b->stack_size);
status->success = false;
}
+% # Special leave for an inlined call.
+ if (status->inlined_iseqs == NULL) { // the current ISeq is being inlined
+ fprintf(f, " return stack[0];\n");
+ b->stack_size += <%= insn.call_attribute('sp_inc') %>;
+ break;
+ }
% end
%
% # Main insn implementation generated by insns.def