Skip to content

Commit 4a396c1

Browse files
committed
ZJIT: Box Target::SideExit
Shrink `lir::Insn` from 184 to 144 bytes.
1 parent 6883139 commit 4a396c1

4 files changed

Lines changed: 15 additions & 14 deletions

File tree

zjit/src/backend/arm64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ mod tests {
17731773

17741774
let val64 = asm.add(CFP, Opnd::UImm(64));
17751775
asm.store(Opnd::mem(64, SP, 0x10), val64);
1776-
let side_exit = Target::SideExit { reason: SideExitReason::Interrupt, exit: SideExit { pc: 0.into(), iseq: std::ptr::null(), stack: vec![], locals: vec![], recompile: None } };
1776+
let side_exit = Target::SideExit { reason: SideExitReason::Interrupt, exit: Box::new(SideExit { pc: 0.into(), iseq: std::ptr::null(), stack: vec![], locals: vec![], recompile: None }) };
17771777
asm.push_insn(Insn::Joz(val64, side_exit));
17781778
asm.mov(C_ARG_OPNDS[0], C_RET_OPND.with_num_bits(32));
17791779
asm.mov(C_ARG_OPNDS[1], Opnd::mem(64, SP, -8));

zjit/src/backend/lir.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,9 @@ pub enum Target
577577
Block(BranchEdge),
578578
/// Side exit to the interpreter
579579
SideExit {
580-
/// Context used for compiling the side exit
581-
exit: SideExit,
580+
/// Context used for compiling the side exit. Boxed to keep `Target`
581+
/// (and every `Insn` variant that embeds it) small.
582+
exit: Box<SideExit>,
582583
/// We use this to increment exit counters
583584
reason: SideExitReason,
584585
},
@@ -851,9 +852,9 @@ pub enum Insn {
851852
macro_rules! target_for_each_operand_impl {
852853
($self:expr, $visit_many:ident) => {
853854
match $self {
854-
Target::SideExit { exit: SideExit { stack, locals, .. }, .. } => {
855-
visit_many!(stack);
856-
visit_many!(locals);
855+
Target::SideExit { exit, .. } => {
856+
visit_many!(exit.stack);
857+
visit_many!(exit.locals);
857858
}
858859
Target::Block(edge) => {
859860
visit_many!(edge.args);
@@ -2711,7 +2712,7 @@ impl Assembler
27112712
for ((block_id, idx), target) in targets {
27122713
// Compile a side exit. Note that this is past register assignment,
27132714
// so you can't use an instruction that returns a VReg.
2714-
if let Target::SideExit { exit: exit @ SideExit { pc, .. }, reason } = target {
2715+
if let Target::SideExit { exit, reason } = target {
27152716
// Only record the exit if `trace_side_exits` is defined and the counter is either the one specified
27162717
let should_record_exit = get_option!(trace_side_exits).map(|trace| match trace {
27172718
TraceExits::All => true,
@@ -2755,9 +2756,9 @@ impl Assembler
27552756
} else {
27562757
let new_exit = self.new_label("side_exit");
27572758
self.write_label(new_exit.clone());
2758-
asm_comment!(self, "Exit: {pc}");
2759+
asm_comment!(self, "Exit: {}", exit.pc);
27592760
compile_exit(self, &exit, None);
2760-
compiled_exits.insert(exit, new_exit.unwrap_label());
2761+
compiled_exits.insert(*exit, new_exit.unwrap_label());
27612762
new_exit
27622763
};
27632764

@@ -3838,7 +3839,7 @@ mod tests {
38383839

38393840
#[test]
38403841
fn test_size_of_insn() {
3841-
assert_eq!(std::mem::size_of::<Insn>(), 184);
3842+
assert_eq!(std::mem::size_of::<Insn>(), 144);
38423843
}
38433844

38443845
#[test]

zjit/src/backend/x86_64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ mod tests {
13871387

13881388
let val64 = asm.add(CFP, Opnd::UImm(64));
13891389
asm.store(Opnd::mem(64, SP, 0x10), val64);
1390-
let side_exit = Target::SideExit { reason: SideExitReason::Interrupt, exit: SideExit { pc: 0.into(), iseq: std::ptr::null(), stack: vec![], locals: vec![], recompile: None } };
1390+
let side_exit = Target::SideExit { reason: SideExitReason::Interrupt, exit: Box::new(SideExit { pc: 0.into(), iseq: std::ptr::null(), stack: vec![], locals: vec![], recompile: None }) };
13911391
asm.push_insn(Insn::Joz(val64, side_exit));
13921392
asm.mov(C_ARG_OPNDS[0], C_RET_OPND.with_num_bits(32));
13931393
asm.mov(C_ARG_OPNDS[1], Opnd::mem(64, SP, -8));

zjit/src/codegen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ fn gen_patch_point(jit: &mut JITState, asm: &mut Assembler, invariant: &Invarian
968968
let exit = build_side_exit(jit, state);
969969

970970
// Let compile_exits compile a side exit. Let scratch_split lower it with split_patch_point.
971-
asm.patch_point(Target::SideExit { exit, reason: PatchPoint(invariant) }, invariant, jit.version);
971+
asm.patch_point(Target::SideExit { exit: Box::new(exit), reason: PatchPoint(invariant) }, invariant, jit.version);
972972
}
973973

974974
/// This is used by scratch_split to lower PatchPoint into PadPatchPoint and PosMarker.
@@ -3179,7 +3179,7 @@ fn compile_iseq(iseq: IseqPtr) -> Result<Function, CompileError> {
31793179
/// Build a Target::SideExit
31803180
fn side_exit(jit: &JITState, state: &FrameState, reason: SideExitReason) -> Target {
31813181
let exit = build_side_exit(jit, state);
3182-
Target::SideExit { exit, reason }
3182+
Target::SideExit { exit: Box::new(exit), reason }
31833183
}
31843184

31853185
/// Build a Target::SideExit that optionally triggers exit_recompile on the exit path.
@@ -3189,7 +3189,7 @@ fn side_exit_with_recompile(jit: &JITState, state: &FrameState, reason: SideExit
31893189
compiled_iseq: Opnd::Value(VALUE::from(jit.iseq())),
31903190
insn_idx: state.insn_idx() as u32,
31913191
});
3192-
Target::SideExit { exit, reason }
3192+
Target::SideExit { exit: Box::new(exit), reason }
31933193
}
31943194

31953195
/// Build a side-exit context

0 commit comments

Comments
 (0)