Skip to content

Commit 743dcc8

Browse files
committed
WIP
1 parent e23d7cc commit 743dcc8

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

zjit/src/codegen.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
397397
&Insn::GuardBlockParamProxy { level, state } => no_output!(gen_guard_block_param_proxy(jit, asm, level, &function.frame_state(state))),
398398
Insn::PatchPoint { invariant, state } => no_output!(gen_patch_point(jit, asm, invariant, &function.frame_state(*state))),
399399
Insn::CCall { cfun, args, name: _, return_type: _, elidable: _ } => gen_ccall(asm, *cfun, opnds!(args)),
400-
Insn::CCallVariadic { cfun, recv, args, name: _, cme, state } => {
401-
gen_ccall_variadic(jit, asm, *cfun, opnd!(recv), opnds!(args), *cme, &function.frame_state(*state))
400+
Insn::CCallVariadic { cfun, recv, args_ptr, args_count, name: _, cme, state } => {
401+
gen_ccall_variadic(jit, asm, *cfun, opnd!(recv), opnd!(args_ptr), *args_count, *cme, &function.frame_state(*state))
402402
}
403403
Insn::GetIvar { self_val, id, state: _ } => gen_getivar(asm, opnd!(self_val), *id),
404404
Insn::SetGlobal { id, val, state } => no_output!(gen_setglobal(jit, asm, *id, opnd!(val), &function.frame_state(*state))),
@@ -656,21 +656,22 @@ fn gen_ccall_variadic(
656656
asm: &mut Assembler,
657657
cfun: *const u8,
658658
recv: Opnd,
659-
args: Vec<Opnd>,
659+
args_ptr: Opnd,
660+
args_count: usize,
660661
cme: *const rb_callable_method_entry_t,
661662
state: &FrameState,
662663
) -> lir::Opnd {
663664
gen_prepare_non_leaf_call(jit, asm, state);
664665

665-
gen_push_frame(asm, args.len(), state, ControlFrame {
666+
gen_push_frame(asm, args_count, state, ControlFrame {
666667
recv,
667668
iseq: None,
668669
cme,
669670
frame_type: VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL,
670671
});
671672

672673
asm_comment!(asm, "switch to new SP register");
673-
let sp_offset = (state.stack().len() - args.len() + VM_ENV_DATA_SIZE.as_usize()) * SIZEOF_VALUE;
674+
let sp_offset = (state.stack().len() - args_count + VM_ENV_DATA_SIZE.as_usize()) * SIZEOF_VALUE;
674675
let new_sp = asm.add(SP, sp_offset.into());
675676
asm.mov(SP, new_sp);
676677

@@ -679,9 +680,7 @@ fn gen_ccall_variadic(
679680
asm.mov(CFP, new_cfp);
680681
asm.store(Opnd::mem(64, EC, RUBY_OFFSET_EC_CFP), CFP);
681682

682-
let argv_ptr = gen_push_opnds(jit, asm, &args);
683-
let result = asm.ccall(cfun, vec![args.len().into(), argv_ptr, recv]);
684-
gen_pop_opnds(asm, &args);
683+
let result = asm.ccall(cfun, vec![args_count.into(), args_ptr, recv]);
685684

686685
asm_comment!(asm, "pop C frame");
687686
let new_cfp = asm.add(CFP, RUBY_SIZEOF_CONTROL_FRAME.into());

zjit/src/hir.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ pub enum Insn {
630630
CCallVariadic {
631631
cfun: *const u8,
632632
recv: InsnId,
633-
args: Vec<InsnId>,
633+
args_ptr: InsnId,
634+
args_count: usize,
634635
cme: *const rb_callable_method_entry_t,
635636
name: ID,
636637
state: InsnId,
@@ -954,12 +955,9 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
954955
}
955956
Ok(())
956957
},
957-
Insn::CCallVariadic { cfun, recv, args, name, .. } => {
958+
Insn::CCallVariadic { cfun, recv, args_ptr, args_count, name, .. } => {
958959
write!(f, "CCallVariadic {}@{:p}, {recv}", name.contents_lossy(), self.ptr_map.map_ptr(cfun))?;
959-
for arg in args {
960-
write!(f, ", {arg}")?;
961-
}
962-
Ok(())
960+
write!(f, ", {args_ptr} ({args_count})")
963961
},
964962
Insn::Snapshot { state } => write!(f, "Snapshot {}", state.print(self.ptr_map)),
965963
Insn::Defined { op_type, v, .. } => {
@@ -1458,8 +1456,8 @@ impl Function {
14581456
&ObjectAlloc { val, state } => ObjectAlloc { val: find!(val), state },
14591457
&ObjectAllocClass { class, state } => ObjectAllocClass { class, state: find!(state) },
14601458
&CCall { cfun, ref args, name, return_type, elidable } => CCall { cfun, args: find_vec!(args), name, return_type, elidable },
1461-
&CCallVariadic { cfun, recv, ref args, cme, name, state } => CCallVariadic {
1462-
cfun, recv: find!(recv), args: find_vec!(args), cme, name, state
1459+
&CCallVariadic { cfun, recv, args_ptr, args_count, cme, name, state } => CCallVariadic {
1460+
cfun, recv: find!(recv), args_ptr: find!(args_ptr), args_count, cme, name, state
14631461
},
14641462
&Defined { op_type, obj, pushval, v, state } => Defined { op_type, obj, pushval, v: find!(v), state: find!(state) },
14651463
&DefinedIvar { self_val, pushval, id, state } => DefinedIvar { self_val: find!(self_val), pushval, id, state },
@@ -2140,16 +2138,20 @@ impl Function {
21402138
});
21412139

21422140
let cfun = unsafe { get_mct_func(cfunc) }.cast();
2141+
let args_count = args.len();
2142+
let args_ptr = fun.push_insn(block, Insn::PushOpnds { opnds: args });
21432143
let ccall = fun.push_insn(block, Insn::CCallVariadic {
21442144
cfun,
21452145
recv,
2146-
args,
2146+
args_ptr,
2147+
args_count,
21472148
cme: method,
21482149
name: method_id,
21492150
state,
21502151
});
21512152

21522153
fun.make_equal_to(send_insn_id, ccall);
2154+
fun.push_insn(block, Insn::PopOpnds { count: args_count });
21532155
return Ok(());
21542156
}
21552157
// Fall through for complex cases (splat, kwargs, etc.)
@@ -2454,19 +2456,20 @@ impl Function {
24542456
worklist.push_back(val);
24552457
worklist.push_back(state);
24562458
}
2459+
&Insn::CCallVariadic { args_ptr, state, .. } => {
2460+
worklist.push_back(args_ptr);
2461+
worklist.push_back(state);
2462+
}
24572463
&Insn::Send { recv, ref args, state, .. }
24582464
| &Insn::SendForward { recv, ref args, state, .. }
24592465
| &Insn::SendWithoutBlock { recv, ref args, state, .. }
2460-
| &Insn::CCallVariadic { recv, ref args, state, .. }
24612466
| &Insn::SendWithoutBlockDirect { recv, ref args, state, .. }
24622467
| &Insn::InvokeSuper { recv, ref args, state, .. } => {
24632468
worklist.push_back(recv);
24642469
worklist.extend(args);
24652470
worklist.push_back(state);
24662471
}
2467-
&Insn::PushOpnds { ref opnds } => {
2468-
worklist.extend(opnds);
2469-
}
2472+
Insn::PushOpnds { opnds } => worklist.extend(opnds),
24702473
&Insn::InvokeBuiltin { ref args, state, .. }
24712474
| &Insn::InvokeBlock { ref args, state, .. } => {
24722475
worklist.extend(args);

0 commit comments

Comments
 (0)