summaryrefslogtreecommitdiff
path: root/yjit
diff options
context:
space:
mode:
authorKevin Menard <kevin.menard@shopify.com>2024-04-24 10:31:35 -0400
committerGitHub <noreply@github.com>2024-04-24 10:31:35 -0400
commitafc7799c3271aab7792c178ab9aee15b87468341 (patch)
treeaf5b29d52cb0774ca2bfdf8cc808a96daa1a0d47 /yjit
parent480287d14056ca7366477ad39b944195185a6d7e (diff)
YJIT: Add a specialized codegen function for `Class#superclass`. (#10613)
Add a specialized codegen function for `Class#superclass`. Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Takashi Kokubun (k0kubun) <takashikkbn@gmail.com> Co-authored-by: Randy Stauner <randy.stauner@shopify.com> Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Diffstat (limited to 'yjit')
-rw-r--r--yjit/bindgen/src/main.rs1
-rw-r--r--yjit/src/codegen.rs32
-rw-r--r--yjit/src/cruby_bindings.inc.rs1
3 files changed, 34 insertions, 0 deletions
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<crate::codegen::BlockHandler>,
+ _argc: i32,
+ _known_recv_class: Option<VALUE>,
+) -> 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;