Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Add codegen for Array#<< #7645

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions yjit/bindgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn main() {
.allowlist_function("rb_ary_resurrect")
.allowlist_function("rb_ary_clear")
.allowlist_function("rb_ary_dup")
.allowlist_function("rb_ary_push")
.allowlist_function("rb_ary_unshift_m")
.allowlist_function("rb_yjit_rb_ary_subseq_length")

Expand Down
26 changes: 26 additions & 0 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4542,6 +4542,31 @@ fn jit_rb_ary_empty_p(
return true;
}

fn jit_rb_ary_push(
jit: &mut JITState,
ctx: &mut Context,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
_ci: *const rb_callinfo,
_cme: *const rb_callable_method_entry_t,
_block: Option<IseqPtr>,
_argc: i32,
_known_recv_class: *const VALUE,
) -> bool {
asm.comment("Array#<<");

// rb_ary_push allocates memory for buffer extension
jit_prepare_routine_call(jit, ctx, asm);

let item_opnd = ctx.stack_pop(1);
let ary_opnd = ctx.stack_pop(1);
let ret = asm.ccall(rb_ary_push as *const u8, vec![ary_opnd, item_opnd]);

let ret_opnd = ctx.stack_push(Type::TArray);
asm.mov(ret_opnd, ret);
true
}

fn jit_obj_respond_to(
jit: &mut JITState,
ctx: &mut Context,
Expand Down Expand Up @@ -8071,6 +8096,7 @@ impl CodegenGlobals {

// rb_ary_empty_p() method in array.c
self.yjit_reg_method(rb_cArray, "empty?", jit_rb_ary_empty_p);
self.yjit_reg_method(rb_cArray, "<<", jit_rb_ary_push);

self.yjit_reg_method(rb_mKernel, "respond_to?", jit_obj_respond_to);
self.yjit_reg_method(rb_mKernel, "block_given?", jit_rb_f_block_given_p);
Expand Down
1 change: 1 addition & 0 deletions yjit/src/cruby_bindings.inc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ extern "C" {
pub fn rb_ary_store(ary: VALUE, key: ::std::os::raw::c_long, val: VALUE);
pub fn rb_ary_dup(ary: VALUE) -> VALUE;
pub fn rb_ary_resurrect(ary: VALUE) -> VALUE;
pub fn rb_ary_push(ary: VALUE, elem: VALUE) -> VALUE;
pub fn rb_ary_clear(ary: VALUE) -> VALUE;
pub fn rb_hash_new() -> VALUE;
pub fn rb_hash_aref(hash: VALUE, key: VALUE) -> VALUE;
Expand Down