ZJIT: Generate code for ArrayExtend

This commit is contained in:
Max Bernstein 2025-08-28 10:36:13 -04:00 committed by Max Bernstein
parent 07e28ba486
commit 8521725225
4 changed files with 18 additions and 2 deletions

View File

@ -139,6 +139,15 @@ class TestZJIT < Test::Unit::TestCase
}, insns: [:splatarray]
end
def test_concattoarray
assert_compiles '[1, 2, 3]', %q{
def test(*a)
[1, 2, *a]
end
test 3
}, insns: [:concattoarray]
end
def test_definedivar
assert_compiles '[nil, "instance-variable", nil]', %q{
def test

View File

@ -145,6 +145,7 @@ fn main() {
.allowlist_function("rb_ary_store")
.allowlist_function("rb_ary_resurrect")
.allowlist_function("rb_ary_cat")
.allowlist_function("rb_ary_concat")
.allowlist_function("rb_ary_clear")
.allowlist_function("rb_ary_dup")
.allowlist_function("rb_ary_push")

View File

@ -403,8 +403,8 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
&Insn::ToNewArray { val, state } => { gen_to_new_array(jit, asm, opnd!(val), &function.frame_state(state)) },
&Insn::ToArray { val, state } => { gen_to_array(jit, asm, opnd!(val), &function.frame_state(state)) },
&Insn::DefinedIvar { self_val, id, pushval, .. } => { gen_defined_ivar(asm, opnd!(self_val), id, pushval) },
&Insn::ArrayExtend { state, .. }
| &Insn::ArrayMax { state, .. }
&Insn::ArrayExtend { left, right, state } => { no_output!(gen_array_extend(jit, asm, opnd!(left), opnd!(right), &function.frame_state(state))) },
&Insn::ArrayMax { state, .. }
| &Insn::FixnumDiv { state, .. }
| &Insn::FixnumMod { state, .. }
| &Insn::Send { state, .. }
@ -708,6 +708,11 @@ fn gen_defined_ivar(asm: &mut Assembler, self_val: Opnd, id: ID, pushval: VALUE)
asm_ccall!(asm, rb_zjit_defined_ivar, self_val, id.0.into(), Opnd::Value(pushval))
}
fn gen_array_extend(jit: &mut JITState, asm: &mut Assembler, left: Opnd, right: Opnd, state: &FrameState) {
gen_prepare_non_leaf_call(jit, asm, state);
asm_ccall!(asm, rb_ary_concat, left, right);
}
/// Compile an interpreter entry block to be inserted into an ISEQ
fn gen_entry_prologue(asm: &mut Assembler, iseq: IseqPtr) {
asm_comment!(asm, "ZJIT entry point: {}", iseq_get_location(iseq, 0));

View File

@ -783,6 +783,7 @@ unsafe extern "C" {
pub fn rb_ary_cat(ary: VALUE, train: *const VALUE, len: ::std::os::raw::c_long) -> VALUE;
pub fn rb_ary_push(ary: VALUE, elem: VALUE) -> VALUE;
pub fn rb_ary_clear(ary: VALUE) -> VALUE;
pub fn rb_ary_concat(lhs: VALUE, rhs: VALUE) -> VALUE;
pub fn rb_hash_new() -> VALUE;
pub fn rb_hash_aref(hash: VALUE, key: VALUE) -> VALUE;
pub fn rb_hash_aset(hash: VALUE, key: VALUE, val: VALUE) -> VALUE;