Skip to content

Commit 508a049

Browse files
tekknolagik0kubun
authored andcommitted
Use find() in frame_state()
We want to return representatives for the stack and locals.
1 parent 32374b7 commit 508a049

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

zjit/src/codegen.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,20 @@ fn gen_insn(jit: &mut JITState, asm: &mut Assembler, function: &Function, insn_i
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),
190190
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))?,
191+
=> gen_send_without_block(jit, asm, call_info, *cd, &function.frame_state(*state))?,
192192
Insn::Return { val } => return Some(gen_return(asm, opnd!(val))?),
193-
Insn::FixnumAdd { left, right, state } => gen_fixnum_add(asm, opnd!(left), opnd!(right), function.frame_state(*state))?,
194-
Insn::FixnumSub { left, right, state } => gen_fixnum_sub(asm, opnd!(left), opnd!(right), function.frame_state(*state))?,
195-
Insn::FixnumMult { left, right, state } => gen_fixnum_mult(asm, opnd!(left), opnd!(right), function.frame_state(*state))?,
193+
Insn::FixnumAdd { left, right, state } => gen_fixnum_add(asm, opnd!(left), opnd!(right), &function.frame_state(*state))?,
194+
Insn::FixnumSub { left, right, state } => gen_fixnum_sub(asm, opnd!(left), opnd!(right), &function.frame_state(*state))?,
195+
Insn::FixnumMult { left, right, state } => gen_fixnum_mult(asm, opnd!(left), opnd!(right), &function.frame_state(*state))?,
196196
Insn::FixnumEq { left, right } => gen_fixnum_eq(asm, opnd!(left), opnd!(right))?,
197197
Insn::FixnumNeq { left, right } => gen_fixnum_neq(asm, opnd!(left), opnd!(right))?,
198198
Insn::FixnumLt { left, right } => gen_fixnum_lt(asm, opnd!(left), opnd!(right))?,
199199
Insn::FixnumLe { left, right } => gen_fixnum_le(asm, opnd!(left), opnd!(right))?,
200200
Insn::FixnumGt { left, right } => gen_fixnum_gt(asm, opnd!(left), opnd!(right))?,
201201
Insn::FixnumGe { left, right } => gen_fixnum_ge(asm, opnd!(left), opnd!(right))?,
202202
Insn::Test { val } => gen_test(asm, opnd!(val))?,
203-
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))?,
203+
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))?,
205205
Insn::PatchPoint(_) => return Some(()), // For now, rb_zjit_bop_redefined() panics. TODO: leave a patch point and fix rb_zjit_bop_redefined()
206206
_ => {
207207
debug!("ZJIT: gen_function: unexpected insn {:?}", insn);

zjit/src/hir.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,9 @@ impl Function {
663663
self.insns.len()
664664
}
665665

666-
/// Return a reference to the FrameState at the given instruction index.
667-
pub fn frame_state(&self, insn_id: InsnId) -> &FrameState {
668-
match &self.insns[insn_id.0] {
666+
/// Return a FrameState at the given instruction index.
667+
pub fn frame_state(&self, insn_id: InsnId) -> FrameState {
668+
match self.find(insn_id) {
669669
Insn::Snapshot { state } => state,
670670
insn => panic!("Unexpected non-Snapshot {insn} when looking up FrameState"),
671671
}
@@ -712,8 +712,18 @@ impl Function {
712712
let insn_id = self.union_find.find_const(insn_id);
713713
use Insn::*;
714714
match &self.insns[insn_id.0] {
715-
result@(PutSelf | Const {..} | Param {..} | NewArray {..} | GetConstantPath {..} | Snapshot {..}
715+
result@(PutSelf | Const {..} | Param {..} | NewArray {..} | GetConstantPath {..}
716716
| Jump(_) | PatchPoint {..}) => result.clone(),
717+
Snapshot { state: FrameState { iseq, insn_idx, pc, stack, locals } } =>
718+
Snapshot {
719+
state: FrameState {
720+
iseq: *iseq,
721+
insn_idx: *insn_idx,
722+
pc: *pc,
723+
stack: stack.iter().map(|v| find!(*v)).collect(),
724+
locals: locals.iter().map(|v| find!(*v)).collect(),
725+
}
726+
},
717727
Return { val } => Return { val: find!(*val) },
718728
StringCopy { val } => StringCopy { val: find!(*val) },
719729
StringIntern { val } => StringIntern { val: find!(*val) },

0 commit comments

Comments
 (0)