зеркало из https://github.com/github/ruby.git
MJIT: Refactor CDHASH handling
Converting a CDHASH into a safe Hash is a lot of work, but retrieving just values is much easier.
This commit is contained in:
Родитель
44165df121
Коммит
8a0acbea4c
|
@ -544,12 +544,12 @@ class RubyVM::MJIT::Compiler
|
|||
when /\A\s+JUMP\((?<dest>[^)]+)\);\s+\z/
|
||||
dest = Regexp.last_match[:dest]
|
||||
if insn.name == :opt_case_dispatch # special case... TODO: use another macro to avoid checking name
|
||||
hash_offsets = C.rb_hash_values(operands[0])
|
||||
else_offset = cast_offset(operands[1])
|
||||
cdhash = C.cdhash_to_hash(operands[0])
|
||||
base_pos = pos + insn_len
|
||||
|
||||
src << " switch (#{dest}) {\n"
|
||||
cdhash.each do |_key, offset|
|
||||
hash_offsets.each do |offset|
|
||||
src << " case #{offset}:\n"
|
||||
src << " goto label_#{base_pos + offset};\n"
|
||||
end
|
||||
|
|
|
@ -5,8 +5,8 @@ module RubyVM::MJIT
|
|||
# This `class << C` section is for calling C functions. For importing variables
|
||||
# or macros as is, please consider using tool/mjit/bindgen.rb instead.
|
||||
class << C
|
||||
def cdhash_to_hash(cdhash_addr)
|
||||
Primitive.cdhash_to_hash(cdhash_addr)
|
||||
def rb_hash_values(cdhash_addr)
|
||||
Primitive.cexpr! 'rb_hash_values((VALUE)NUM2PTR(cdhash_addr))'
|
||||
end
|
||||
|
||||
def builtin_compiler(f, bf, index, stack_size, builtin_inline_p)
|
||||
|
|
|
@ -27,12 +27,6 @@
|
|||
#include "insns.inc"
|
||||
#include "insns_info.inc"
|
||||
|
||||
struct case_dispatch_var {
|
||||
FILE *f;
|
||||
unsigned int base_pos;
|
||||
VALUE last_value;
|
||||
};
|
||||
|
||||
// Returns true if call cache is still not obsoleted and vm_cc_cme(cc)->def->type is available.
|
||||
static bool
|
||||
has_valid_method_type(CALL_CACHE cc)
|
||||
|
@ -52,37 +46,6 @@ fastpath_applied_iseq_p(const CALL_INFO ci, const CALL_CACHE cc, const rb_iseq_t
|
|||
&& vm_call_iseq_optimizable_p(ci, cc); // CC_SET_FASTPATH condition
|
||||
}
|
||||
|
||||
#define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
|
||||
|
||||
// TODO: Share this with iseq.c
|
||||
static inline VALUE
|
||||
obj_resurrect(VALUE obj)
|
||||
{
|
||||
if (hidden_obj_p(obj)) {
|
||||
switch (BUILTIN_TYPE(obj)) {
|
||||
case T_STRING:
|
||||
obj = rb_str_resurrect(obj);
|
||||
break;
|
||||
case T_ARRAY:
|
||||
obj = rb_ary_resurrect(obj);
|
||||
break;
|
||||
case T_HASH:
|
||||
obj = rb_hash_resurrect(obj);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
static int
|
||||
cdhash_each(VALUE key, VALUE value, VALUE hash)
|
||||
{
|
||||
rb_hash_aset(hash, obj_resurrect(key), value);
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
#include "mjit_compile_attr.inc"
|
||||
|
||||
#if SIZEOF_LONG == SIZEOF_VOIDP
|
||||
|
@ -120,14 +83,6 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id)
|
|||
// Primitive.methods
|
||||
//
|
||||
|
||||
static VALUE
|
||||
cdhash_to_hash(rb_execution_context_t *ec, VALUE self, VALUE cdhash_addr)
|
||||
{
|
||||
VALUE hash = rb_hash_new();
|
||||
rb_hash_foreach((VALUE)NUM2PTR(cdhash_addr), cdhash_each, hash);
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
builtin_compile(rb_execution_context_t *ec, VALUE self, VALUE buf, VALUE bf_addr, VALUE index, VALUE stack_size, VALUE builtin_inline_p)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче