[前][次][番号順一覧][スレッド一覧]

ruby-changes:69228

From: eileencodes <ko1@a...>
Date: Thu, 21 Oct 2021 08:24:16 +0900 (JST)
Subject: [ruby-changes:69228] c8e157bb5c (master): Implement getclassvariable in yjit

https://git.ruby-lang.org/ruby.git/commit/?id=c8e157bb5c

From c8e157bb5c9553e7b444921878044996a1c24ca0 Mon Sep 17 00:00:00 2001
From: eileencodes <eileencodes@g...>
Date: Wed, 29 Sep 2021 16:06:40 -0400
Subject: Implement getclassvariable in yjit

Co-authored-by: Aaron Patterson <tenderlove@r...>
---
 test/ruby/test_yjit.rb |  5 +++++
 vm_insnhelper.c        | 12 ++++++++++++
 yjit_codegen.c         | 27 +++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index e00f15ecf5..d7dd599205 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -8,6 +8,11 @@ return unless YJIT.enabled? https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L8
 # Tests for YJIT with assertions on compilation and side exits
 # insipired by the MJIT tests in test/ruby/test_jit.rb
 class TestYJIT < Test::Unit::TestCase
+  def test_compile_getclassvariable
+    script = 'class Foo; @@foo = 1; def self.foo; @@foo; end; end; Foo.foo'
+    assert_compiles(script, insns: %i[getclassvariable], result: 1)
+  end
+
   def test_compile_putnil
     assert_compiles('nil', insns: %i[putnil], result: nil)
   end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index a33f6b5ea3..1f591b8323 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -835,6 +835,12 @@ vm_get_cref(const VALUE *ep) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L835
     }
 }
 
+rb_cref_t *
+rb_vm_get_cref(const VALUE *ep)
+{
+    return vm_get_cref(ep);
+}
+
 static rb_cref_t *
 vm_ec_cref(const rb_execution_context_t *ec)
 {
@@ -1336,6 +1342,12 @@ vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1342
     return update_classvariable_cache(iseq, klass, id, ic);
 }
 
+VALUE
+rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, ICVARC ic)
+{
+    return vm_getclassvariable(iseq, cref, cfp, id, ic);
+}
+
 static inline void
 vm_setclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic)
 {
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 9cc643654b..f6973b5a81 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -4110,6 +4110,32 @@ gen_getspecial(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4110
     }
 }
 
+VALUE
+rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, ICVARC ic);
+
+rb_cref_t *
+rb_vm_get_cref(const VALUE *ep);
+
+static codegen_status_t
+gen_getclassvariable(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb)
+{
+    mov(cb, C_ARG_REGS[0], member_opnd(REG_CFP, rb_control_frame_t, ep));
+    call_ptr(cb, REG0, (void *)rb_vm_get_cref);
+
+    mov(cb, C_ARG_REGS[0], member_opnd(REG_CFP, rb_control_frame_t, iseq));
+    mov(cb, C_ARG_REGS[1], RAX);
+    mov(cb, C_ARG_REGS[2], REG_CFP);
+    mov(cb, C_ARG_REGS[3], imm_opnd(jit_get_arg(jit, 0)));
+    mov(cb, C_ARG_REGS[4], imm_opnd(jit_get_arg(jit, 1)));
+
+    call_ptr(cb, REG0, (void *)rb_vm_getclassvariable);
+
+    x86opnd_t stack_top = ctx_stack_push(ctx, TYPE_UNKNOWN);
+    mov(cb, stack_top, RAX);
+
+    return YJIT_KEEP_COMPILING;
+}
+
 static codegen_status_t
 gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
 {
@@ -4500,6 +4526,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4526
     yjit_reg_op(BIN(tostring), gen_tostring);
     yjit_reg_op(BIN(toregexp), gen_toregexp);
     yjit_reg_op(BIN(getspecial), gen_getspecial);
+    yjit_reg_op(BIN(getclassvariable), gen_getclassvariable);
 
     yjit_method_codegen_table = st_init_numtable();
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]