optimize: make all call single arg
to allow more aggressive optimization
This commit is contained in:
@@ -95,8 +95,7 @@ impl<'ctx> Helpers<'ctx> {
|
||||
value_type.fn_type(
|
||||
&[
|
||||
value_type.into(),
|
||||
ptr_type.into(),
|
||||
ptr_int_type.into(),
|
||||
value_type.into(),
|
||||
ptr_type.into(),
|
||||
],
|
||||
false,
|
||||
@@ -317,21 +316,16 @@ extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
|
||||
extern "C" fn helper_call<'jit>(
|
||||
func: JITValue,
|
||||
args: *mut JITValue,
|
||||
arity: usize,
|
||||
arg: JITValue,
|
||||
vm: *const VM<'jit>,
|
||||
) -> JITValue {
|
||||
use ValueTag::*;
|
||||
let args = unsafe { Vec::from_raw_parts(args, arity, arity) }
|
||||
.into_iter()
|
||||
.map(Value::from)
|
||||
.collect();
|
||||
match func.tag {
|
||||
Function => {
|
||||
let func: Value = func.into();
|
||||
func.call(unsafe { vm.as_ref() }.unwrap(), args)
|
||||
.unwrap()
|
||||
.into()
|
||||
let mut func: Value = func.into();
|
||||
func.call(unsafe { vm.as_ref() }.unwrap(), arg.into())
|
||||
.unwrap();
|
||||
func.into()
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
||||
@@ -392,23 +392,8 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
||||
.left()
|
||||
.unwrap(),
|
||||
)?,
|
||||
OpCode::Call { arity } => {
|
||||
let args = self.builder.build_array_malloc(
|
||||
self.helpers.value_type,
|
||||
self.helpers.int_type.const_int(arity as u64, false),
|
||||
"malloc_args",
|
||||
)?;
|
||||
for i in 0..arity {
|
||||
let ptr = unsafe {
|
||||
self.builder.build_in_bounds_gep(
|
||||
self.helpers.value_type,
|
||||
args,
|
||||
&[self.helpers.int_type.const_int(i as u64, false)],
|
||||
"gep_arg",
|
||||
)?
|
||||
};
|
||||
self.builder.build_store(ptr, stack.pop())?;
|
||||
}
|
||||
OpCode::Call => {
|
||||
let arg = stack.pop();
|
||||
let func = self
|
||||
.builder
|
||||
.build_direct_call(
|
||||
@@ -425,11 +410,7 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
||||
self.helpers.call,
|
||||
&[
|
||||
func.into(),
|
||||
args.into(),
|
||||
self.helpers
|
||||
.ptr_int_type
|
||||
.const_int(arity as u64, false)
|
||||
.into(),
|
||||
arg.into(),
|
||||
self.new_ptr(vm).into(),
|
||||
],
|
||||
"call",
|
||||
|
||||
Reference in New Issue
Block a user