Update RJIT to support newarray_send

This also adds max / hash support
This commit is contained in:
Aaron Patterson 2023-04-18 13:53:37 -07:00 коммит произвёл Aaron Patterson
Родитель b816ea8772
Коммит bdffcd6df3
4 изменённых файлов: 78 добавлений и 3 удалений

Просмотреть файл

@ -91,8 +91,7 @@ module RubyVM::RJIT
when :opt_str_freeze then opt_str_freeze(jit, ctx, asm)
when :opt_nil_p then opt_nil_p(jit, ctx, asm)
# opt_str_uminus
# opt_newarray_max
when :opt_newarray_min then opt_newarray_min(jit, ctx, asm)
when :opt_newarray_send then opt_newarray_send(jit, ctx, asm)
when :invokesuper then invokesuper(jit, ctx, asm)
when :invokeblock then invokeblock(jit, ctx, asm)
when :leave then leave(jit, ctx, asm)
@ -1510,7 +1509,21 @@ module RubyVM::RJIT
end
# opt_str_uminus
# opt_newarray_max
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def opt_newarray_send(jit, ctx, asm)
type = C.ID2SYM jit.operand(1)
case type
when :min then opt_newarray_min(jit, ctx, asm)
when :max then opt_newarray_max(jit, ctx, asm)
when :hash then opt_newarray_hash(jit, ctx, asm)
else
return CantCompile
end
end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
@ -1537,6 +1550,56 @@ module RubyVM::RJIT
KeepCompiling
end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def opt_newarray_max(jit, ctx, asm)
num = jit.operand(0)
# Save the PC and SP because we may allocate
jit_prepare_routine_call(jit, ctx, asm)
offset_magnitude = C.VALUE.size * num
values_opnd = ctx.sp_opnd(-offset_magnitude)
asm.lea(:rax, values_opnd)
asm.mov(C_ARGS[0], EC)
asm.mov(C_ARGS[1], num)
asm.mov(C_ARGS[2], :rax)
asm.call(C.rb_vm_opt_newarray_max)
ctx.stack_pop(num)
stack_ret = ctx.stack_push(Type::Unknown)
asm.mov(stack_ret, C_RET)
KeepCompiling
end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def opt_newarray_hash(jit, ctx, asm)
num = jit.operand(0)
# Save the PC and SP because we may allocate
jit_prepare_routine_call(jit, ctx, asm)
offset_magnitude = C.VALUE.size * num
values_opnd = ctx.sp_opnd(-offset_magnitude)
asm.lea(:rax, values_opnd)
asm.mov(C_ARGS[0], EC)
asm.mov(C_ARGS[1], num)
asm.mov(C_ARGS[2], :rax)
asm.call(C.rb_vm_opt_newarray_hash)
ctx.stack_pop(num)
stack_ret = ctx.stack_push(Type::Unknown)
asm.mov(stack_ret, C_RET)
KeepCompiling
end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]

Просмотреть файл

@ -517,6 +517,8 @@ extern VALUE rb_vm_concat_array(VALUE ary1, VALUE ary2st);
extern VALUE rb_vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, VALUE allow_nil);
extern VALUE rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic);
extern VALUE rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
extern VALUE rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
extern VALUE rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
extern VALUE rb_vm_splat_array(VALUE flag, VALUE array);
extern bool rb_simple_iseq_p(const rb_iseq_t *iseq);
extern bool rb_vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE v);

Просмотреть файл

@ -724,6 +724,14 @@ module RubyVM::RJIT # :nodoc: all
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_ic_hit_p) }
end
def C.rb_vm_opt_newarray_hash
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_hash) }
end
def C.rb_vm_opt_newarray_max
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_max) }
end
def C.rb_vm_opt_newarray_min
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_min) }
end

Просмотреть файл

@ -539,6 +539,8 @@ generator = BindingGenerator.new(
rb_vm_getclassvariable
rb_vm_ic_hit_p
rb_vm_opt_newarray_min
rb_vm_opt_newarray_max
rb_vm_opt_newarray_hash
rb_vm_setinstancevariable
rb_vm_splat_array
rjit_full_cfunc_return