ruby-changes:69066
From: eileencodes <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:43 +0900 (JST)
Subject: [ruby-changes:69066] b91078ea74 (master): Add setglobal to yjit
https://git.ruby-lang.org/ruby.git/commit/?id=b91078ea74 From b91078ea743fda959ad42f17562c4f3091bcf585 Mon Sep 17 00:00:00 2001 From: eileencodes <eileencodes@g...> Date: Tue, 27 Jul 2021 14:57:30 -0400 Subject: Add setglobal to yjit Adds yjit support for setting global variables. Co-authored-by: Aaron Patterson <tenderlove@r...> Co-authored-by: John Hawthorn <john@h...> --- bootstraptest/test_yjit.rb | 10 +++++++++- test/ruby/test_yjit.rb | 4 ++++ yjit_codegen.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 91b63cf076..1a683c1c41 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -1,5 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1 -# Check that global variables work +# Check that global variable set works +assert_equal 'string', %q{ + def foo + $foo = "string" + end + foo +} + +# Check that global variables work assert_equal 'string', %q{ $foo = "string" diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 8b61a1dbfc..22b78a4e2d 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -55,6 +55,10 @@ class TestYJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L55 assert_compiles('-"foo" == -"bar"', insns: %i[opt_eq], result: false) end + def test_compile_set_and_get_global + assert_compiles('$foo = 123; $foo', insns: %i[setglobal], result: 123) + end + def test_getlocal_with_level assert_compiles(<<~RUBY, insns: %i[getlocal opt_plus], result: [[7]]) def foo(foo, bar) diff --git a/yjit_codegen.c b/yjit_codegen.c index 42beb7dd94..3658d208fa 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -3447,6 +3447,28 @@ gen_getglobal(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3447 return YJIT_KEEP_COMPILING; } +static codegen_status_t +gen_setglobal(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)); + + x86opnd_t val = ctx_stack_pop(ctx, 1); + + mov(cb, C_ARG_REGS[1], val); + + call_ptr(cb, REG0, (void *)&rb_gvar_set); + + // Load YJIT registers + yjit_load_regs(cb); + + return YJIT_KEEP_COMPILING; +} + static codegen_status_t gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx) { @@ -3690,6 +3712,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3712 yjit_reg_op(BIN(send), gen_send); yjit_reg_op(BIN(leave), gen_leave); yjit_reg_op(BIN(getglobal), gen_getglobal); + yjit_reg_op(BIN(setglobal), gen_setglobal); yjit_method_codegen_table = st_init_numtable(); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/