Skip to content

Commit 9f3225d

Browse files
committed
YJIT: Properly preserve register mapping in cpush_all() and cpop_all()
Previously, cpop_all() did not in fact restore the register mapping state since it was effectively doing a no-op `self.ctx.set_reg_mapping(self.ctx.get_reg_mapping())`. This desync in bookkeeping led to issues with the --yjit-dump-insns option because print_str() used to use cpush_all() and cpop_all().
1 parent 9930468 commit 9f3225d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

yjit/src/backend/arm64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ mod tests {
14191419
fn test_emit_cpop_all() {
14201420
let (mut asm, mut cb) = setup_asm();
14211421

1422-
asm.cpop_all();
1422+
asm.cpop_all(crate::core::RegMapping::default());
14231423
asm.compile_with_num_regs(&mut cb, 0);
14241424
}
14251425

yjit/src/backend/ir.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,12 +1824,12 @@ impl Assembler {
18241824
out
18251825
}
18261826

1827-
pub fn cpop_all(&mut self) {
1827+
pub fn cpop_all(&mut self, reg_mapping: RegMapping) {
18281828
self.push_insn(Insn::CPopAll);
18291829

18301830
// Re-enable ccall's RegMappings assertion disabled by cpush_all.
18311831
// cpush_all + cpop_all preserve all stack temp registers, so it's safe.
1832-
self.set_reg_mapping(self.ctx.get_reg_mapping());
1832+
self.set_reg_mapping(reg_mapping);
18331833
}
18341834

18351835
pub fn cpop_into(&mut self, opnd: Opnd) {
@@ -1840,14 +1840,16 @@ impl Assembler {
18401840
self.push_insn(Insn::CPush(opnd));
18411841
}
18421842

1843-
pub fn cpush_all(&mut self) {
1843+
pub fn cpush_all(&mut self) -> RegMapping {
18441844
self.push_insn(Insn::CPushAll);
18451845

18461846
// Mark all temps as not being in registers.
18471847
// Temps will be marked back as being in registers by cpop_all.
18481848
// We assume that cpush_all + cpop_all are used for C functions in utils.rs
18491849
// that don't require spill_regs for GC.
1850+
let mapping = self.ctx.get_reg_mapping();
18501851
self.set_reg_mapping(RegMapping::default());
1852+
mapping
18511853
}
18521854

18531855
pub fn cret(&mut self, opnd: Opnd) {

yjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,7 +8314,7 @@ fn gen_send_iseq(
83148314
// We also do this after spill_regs() to avoid doubly spilling the same thing on asm.ccall().
83158315
if get_option!(gen_stats) {
83168316
// Protect caller-saved registers in case they're used for arguments
8317-
asm.cpush_all();
8317+
let mapping = asm.cpush_all();
83188318

83198319
// Assemble the ISEQ name string
83208320
let name_str = get_iseq_name(iseq);
@@ -8324,7 +8324,7 @@ fn gen_send_iseq(
83248324

83258325
// Increment the counter for this cfunc
83268326
asm.ccall(incr_iseq_counter as *const u8, vec![iseq_idx.into()]);
8327-
asm.cpop_all();
8327+
asm.cpop_all(mapping);
83288328
}
83298329

83308330
// The callee might change locals through Kernel#binding and other means.

0 commit comments

Comments
 (0)