From afc7799c3271aab7792c178ab9aee15b87468341 Mon Sep 17 00:00:00 2001 From: Kevin Menard Date: Wed, 24 Apr 2024 10:31:35 -0400 Subject: YJIT: Add a specialized codegen function for `Class#superclass`. (#10613) Add a specialized codegen function for `Class#superclass`. Co-authored-by: Maxime Chevalier-Boisvert Co-authored-by: Takashi Kokubun (k0kubun) Co-authored-by: Randy Stauner Co-authored-by: Alan Wu --- yjit/bindgen/src/main.rs | 1 + yjit/src/codegen.rs | 32 ++++++++++++++++++++++++++++++++ yjit/src/cruby_bindings.inc.rs | 1 + 3 files changed, 34 insertions(+) (limited to 'yjit') diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs index c58df7c377..c16617b3f0 100644 --- a/yjit/bindgen/src/main.rs +++ b/yjit/bindgen/src/main.rs @@ -174,6 +174,7 @@ fn main() { .allowlist_var("rb_cThread") .allowlist_var("rb_cArray") .allowlist_var("rb_cHash") + .allowlist_var("rb_cClass") // From include/ruby/internal/fl_type.h .allowlist_type("ruby_fl_type") diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index a7bf2e06f6..a927aa9684 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -6060,6 +6060,36 @@ fn gen_block_given( asm.mov(out_opnd, block_given); } +// Codegen for rb_class_superclass() +fn jit_rb_class_superclass( + jit: &mut JITState, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, + _ci: *const rb_callinfo, + cme: *const rb_callable_method_entry_t, + _block: Option, + _argc: i32, + _known_recv_class: Option, +) -> bool { + extern "C" { + fn rb_class_superclass(klass: VALUE) -> VALUE; + } + + if !jit_prepare_lazy_frame_call(jit, asm, cme, StackOpnd(0)) { + return false; + } + + asm_comment!(asm, "Class#superclass"); + let recv_opnd = asm.stack_opnd(0); + let ret = asm.ccall(rb_class_superclass as *const u8, vec![recv_opnd]); + + asm.stack_pop(1); + let ret_opnd = asm.stack_push(Type::Unknown); + asm.mov(ret_opnd, ret); + + true +} + fn jit_thread_s_current( _jit: &mut JITState, asm: &mut Assembler, @@ -10072,6 +10102,8 @@ pub fn yjit_reg_method_codegen_fns() { yjit_reg_method(rb_mKernel, "respond_to?", jit_obj_respond_to); yjit_reg_method(rb_mKernel, "block_given?", jit_rb_f_block_given_p); + yjit_reg_method(rb_cClass, "superclass", jit_rb_class_superclass); + yjit_reg_method(rb_singleton_class(rb_cThread), "current", jit_thread_s_current); } } diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index 359227d60d..bdaee0534c 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -962,6 +962,7 @@ extern "C" { pub static mut rb_mKernel: VALUE; pub static mut rb_cBasicObject: VALUE; pub static mut rb_cArray: VALUE; + pub static mut rb_cClass: VALUE; pub static mut rb_cFalseClass: VALUE; pub static mut rb_cFloat: VALUE; pub static mut rb_cHash: VALUE; -- cgit v1.2.3