ruby-changes:69058
From: eileencodes <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:42 +0900 (JST)
Subject: [ruby-changes:69058] 50029fb127 (master): Add getglobal to yjit
https://git.ruby-lang.org/ruby.git/commit/?id=50029fb127 From 50029fb127c38b345dc781ea8f67bfc372cc5390 Mon Sep 17 00:00:00 2001 From: eileencodes <eileencodes@g...> Date: Tue, 27 Jul 2021 13:48:33 -0400 Subject: Add getglobal to yjit Adds getglobal to yjit and a test for it. Co-authored-by: Aaron Patterson <tenderlove@r...> --- bootstraptest/test_yjit.rb | 12 ++++++++++++ common.mk | 2 ++ yjit_codegen.c | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 9bce707cb5..91b63cf076 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1 +# Check that global variables work + +assert_equal 'string', %q{ + $foo = "string" + + def foo + $foo + end + + foo +} + # Check that global tracepoints work assert_equal 'true', %q{ def foo diff --git a/common.mk b/common.mk index 348796c318..76d62915f6 100644 --- a/common.mk +++ b/common.mk @@ -16724,6 +16724,7 @@ yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/object.h https://github.com/ruby/ruby/blob/trunk/common.mk#L16724 yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/serial.h yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/static_assert.h yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/string.h +yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/variable.h yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/vm.h yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/warnings.h yjit_codegen.$(OBJEXT): {$(VPATH)}assert.h @@ -16739,6 +16740,7 @@ yjit_codegen.$(OBJEXT): {$(VPATH)}backward/2/stdalign.h https://github.com/ruby/ruby/blob/trunk/common.mk#L16740 yjit_codegen.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h yjit_codegen.$(OBJEXT): {$(VPATH)}builtin.h yjit_codegen.$(OBJEXT): {$(VPATH)}config.h +yjit_codegen.$(OBJEXT): {$(VPATH)}constant.h yjit_codegen.$(OBJEXT): {$(VPATH)}darray.h yjit_codegen.$(OBJEXT): {$(VPATH)}debug_counter.h yjit_codegen.$(OBJEXT): {$(VPATH)}defines.h diff --git a/yjit_codegen.c b/yjit_codegen.c index 28721585dd..42beb7dd94 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -9,6 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L9 #include "internal/class.h" #include "internal/object.h" #include "internal/string.h" +#include "internal/variable.h" #include "insns_info.inc" #include "yjit.h" #include "yjit_iface.h" @@ -3425,6 +3426,27 @@ gen_leave(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3426 RUBY_EXTERN rb_serial_t ruby_vm_global_constant_state; +static codegen_status_t +gen_getglobal(jitstate_t* jit, ctx_t* ctx) +{ + ID gid = jit_get_arg(jit, 0); + + // Save YJIT registers + yjit_save_regs(cb); + + mov(cb, C_ARG_REGS[0], imm_opnd(gid)); + + call_ptr(cb, REG0, (void *)&rb_gvar_get); + + // Load YJIT registers + yjit_load_regs(cb); + + x86opnd_t top = ctx_stack_push(ctx, TYPE_UNKNOWN); + mov(cb, top, RAX); + + return YJIT_KEEP_COMPILING; +} + static codegen_status_t gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx) { @@ -3667,6 +3689,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3689 yjit_reg_op(BIN(opt_send_without_block), gen_opt_send_without_block); yjit_reg_op(BIN(send), gen_send); yjit_reg_op(BIN(leave), gen_leave); + yjit_reg_op(BIN(getglobal), gen_getglobal); yjit_method_codegen_table = st_init_numtable(); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/