diff options
author | eileencodes <eileencodes@gmail.com> | 2021-07-27 13:48:33 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:38 -0400 |
commit | 50029fb127c38b345dc781ea8f67bfc372cc5390 (patch) | |
tree | c946fb9fbeb02e4c01f89f949cc502fbe7ff388e | |
parent | 6aa4637272204b7017a0414393ab05be6fa07672 (diff) |
Add getglobal to yjit
Adds getglobal to yjit and a test for it.
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
-rw-r--r-- | bootstraptest/test_yjit.rb | 12 | ||||
-rw-r--r-- | common.mk | 2 | ||||
-rw-r--r-- | yjit_codegen.c | 23 |
3 files changed, 37 insertions, 0 deletions
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 @@ +# 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 @@ -16724,6 +16724,7 @@ yjit_codegen.$(OBJEXT): $(top_srcdir)/internal/object.h 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 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 @@ #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" @@ -3426,6 +3427,27 @@ gen_leave(jitstate_t* jit, ctx_t* ctx) 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) { VALUE jump_offset = jit_get_arg(jit, 0); @@ -3667,6 +3689,7 @@ yjit_init_codegen(void) 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(); |