Skip to content

Commit 308cd59

Browse files
tekknolagik0kubun
authored andcommitted
Rewrite SendWithoutBlock to SendWithoutBlockDirect when possible
In calls to top-level functions, we assume that call targets will not get rewritten, so we can insert a PatchPoint and do the lookup at compile-time.
1 parent cfc9234 commit 308cd59

File tree

3 files changed

+269
-12
lines changed

3 files changed

+269
-12
lines changed

zjit/src/codegen.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ fn gen_insn(jit: &mut JITState, asm: &mut Assembler, function: &Function, insn_i
187187
Insn::Jump(branch) => return gen_jump(jit, asm, branch),
188188
Insn::IfTrue { val, target } => return gen_if_true(jit, asm, opnd!(val), target),
189189
Insn::IfFalse { val, target } => return gen_if_false(jit, asm, opnd!(val), target),
190-
Insn::SendWithoutBlock { call_info, cd, state, .. } => gen_send_without_block(jit, asm, call_info, *cd, function.frame_state(*state))?,
190+
Insn::SendWithoutBlock { call_info, cd, state, .. } | Insn::SendWithoutBlockDirect { call_info, cd, state, .. }
191+
=> gen_send_without_block(jit, asm, call_info, *cd, function.frame_state(*state))?,
191192
Insn::Return { val } => return Some(gen_return(asm, opnd!(val))?),
192193
Insn::FixnumAdd { left, right, state } => gen_fixnum_add(asm, opnd!(left), opnd!(right), function.frame_state(*state))?,
193194
Insn::FixnumSub { left, right, state } => gen_fixnum_sub(asm, opnd!(left), opnd!(right), function.frame_state(*state))?,
@@ -200,6 +201,7 @@ fn gen_insn(jit: &mut JITState, asm: &mut Assembler, function: &Function, insn_i
200201
Insn::FixnumGe { left, right } => gen_fixnum_ge(asm, opnd!(left), opnd!(right))?,
201202
Insn::Test { val } => gen_test(asm, opnd!(val))?,
202203
Insn::GuardType { val, guard_type, state } => gen_guard_type(asm, opnd!(val), *guard_type, function.frame_state(*state))?,
204+
Insn::GuardBitEquals { val, expected, state } => gen_guard_bit_equals(asm, opnd!(val), *expected, function.frame_state(*state))?,
203205
Insn::PatchPoint(_) => return Some(()), // For now, rb_zjit_bop_redefined() panics. TODO: leave a patch point and fix rb_zjit_bop_redefined()
204206
_ => {
205207
debug!("ZJIT: gen_function: unexpected insn {:?}", insn);
@@ -497,6 +499,13 @@ fn gen_guard_type(asm: &mut Assembler, val: lir::Opnd, guard_type: Type, state:
497499
Some(val)
498500
}
499501

502+
/// Compile an identity check with a side exit
503+
fn gen_guard_bit_equals(asm: &mut Assembler, val: lir::Opnd, expected: VALUE, state: &FrameState) -> Option<lir::Opnd> {
504+
asm.cmp(val, Opnd::UImm(expected.into()));
505+
asm.jnz(Target::SideExit(state.clone()));
506+
Some(val)
507+
}
508+
500509
/// Save the incremented PC on the CFP.
501510
/// This is necessary when callees can raise or allocate.
502511
fn gen_save_pc(asm: &mut Assembler, state: &FrameState) {

0 commit comments

Comments
 (0)