From 330086d3f6d0f05ef6ccdf1e512c19e94e7104f3 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 12 Mar 2023 22:07:02 -0700 Subject: [PATCH] RJIT: Implement definedivar --- lib/ruby_vm/rjit/insn_compiler.rb | 37 ++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb index c23c55e5f05a4d..50cafb2b92860e 100644 --- a/lib/ruby_vm/rjit/insn_compiler.rb +++ b/lib/ruby_vm/rjit/insn_compiler.rb @@ -18,7 +18,7 @@ def compile(jit, ctx, asm, insn) asm.incr_counter(:rjit_insns_count) asm.comment("Insn: #{insn.name}") - # 72/101 + # 73/102 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -64,6 +64,7 @@ def compile(jit, ctx, asm, insn) when :setn then setn(jit, ctx, asm) when :adjuststack then adjuststack(jit, ctx, asm) when :defined then defined(jit, ctx, asm) + when :definedvar then definedivar(jit, ctx, asm) # checkmatch # checkkeyword # checktype @@ -1038,6 +1039,40 @@ def defined(jit, ctx, asm) KeepCompiling end + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] + def definedivar(jit, ctx, asm) + ivar_name = jit.operand(0) + pushval = jit.operand(2) + + # Get the receiver + asm.mov(:rcx, [CFP, C.rb_control_frame_t.offsetof(:self)]) + + # Save the PC and SP because the callee may allocate + # Note that this modifies REG_SP, which is why we do it first + jit_prepare_routine_call(jit, ctx, asm) # clobbers :rax + + # Call rb_ivar_defined(recv, ivar_name) + asm.mov(C_ARGS[0], :rcx) + asm.mov(C_ARGS[1], ivar_name) + asm.call(C.rb_ivar_defined) + + # if (rb_ivar_defined(recv, ivar_name)) { + # val = pushval; + # } + asm.test(C_RET, 255) + asm.mov(:rax, Qnil) + asm.mov(:rcx, pushval) + asm.cmovnz(:rax, :rcx) + + # Push the return value onto the stack + stack_ret = ctx.stack_push + asm.mov(stack_ret, :rax) + + KeepCompiling + end + # checkmatch # checkkeyword # checktype