mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
9b6b4674d7
based on inline cache when JIT cancel happens by that.
This feature was in the original MJIT implementation by Vladimir, but on
merging MJIT to Ruby it was removed for simplification. This commit adds
the functionality again for the following benchmark:
52f05781f6/concurrent-map/bench.rb
(shown float is duration seconds. shorter is better)
* Before
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6507579649914987
$ INHERIT=0 ruby -v --jit bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.5091587850474752
$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6124781150138006
$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.7495657080435194 # <-- this
```
* After
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.653559010999743
$ INHERIT=0 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.4738391840364784
$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.645227018976584
$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.523708809982054 # <-- this
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
57 lines
3 KiB
Text
57 lines
3 KiB
Text
% # -*- C -*-
|
|
% # 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.
|
|
%
|
|
% # Optimized case of get_instancevariable instruction.
|
|
#if OPT_IC_FOR_IVAR
|
|
{
|
|
% # compiler: Prepare operands which may be used by `insn.call_attribute`
|
|
% insn.opes.each_with_index do |ope, i|
|
|
MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>];
|
|
% end
|
|
% # compiler: Use copied IC to avoid race condition
|
|
IC ic_copy = &(status->is_entries + ((union iseq_inline_storage_entry *)ic - body->is_entries))->cache;
|
|
%
|
|
% # compiler: Consider cfp->self as T_OBJECT if ic_copy->ic_serial is set
|
|
if (!status->compile_info->disable_ivar_cache && ic_copy->ic_serial) {
|
|
% # JIT: optimize away motion of sp and pc. This path does not call rb_warning() and so it's always leaf and not `handles_sp`.
|
|
% # <%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%>
|
|
%
|
|
% # JIT: prepare vm_getivar's arguments and variables
|
|
fprintf(f, "{\n");
|
|
fprintf(f, " VALUE obj = GET_SELF();\n");
|
|
fprintf(f, " const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic_copy->ic_serial);
|
|
fprintf(f, " const st_index_t index = %"PRIuSIZE";\n", ic_copy->ic_value.index);
|
|
% # JIT: cache hit path of vm_getivar, or cancel JIT.
|
|
% if insn.name == 'setinstancevariable'
|
|
fprintf(f, " VALUE val = stack[%d];\n", b->stack_size - 1);
|
|
fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj))) {\n");
|
|
fprintf(f, " VALUE *ptr = ROBJECT_IVPTR(obj);\n");
|
|
fprintf(f, " RB_OBJ_WRITE(obj, &ptr[index], val);\n");
|
|
fprintf(f, " }\n");
|
|
% else
|
|
fprintf(f, " VALUE val;\n");
|
|
fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj) && (val = ROBJECT_IVPTR(obj)[index]) != Qundef)) {\n");
|
|
fprintf(f, " stack[%d] = val;\n", b->stack_size);
|
|
fprintf(f, " }\n");
|
|
% end
|
|
fprintf(f, " else {\n");
|
|
fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos);
|
|
fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size);
|
|
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_ivar);\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, " goto cancel;\n");
|
|
fprintf(f, " }\n");
|
|
|
|
% # compiler: Move JIT compiler's internal stack pointer
|
|
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
|
|
fprintf(f, "}\n");
|
|
break;
|
|
}
|
|
}
|
|
#endif /* OPT_IC_FOR_IVAR */
|