feat(jit): support multiple arg function call
note: performance regression?
This commit is contained in:
@@ -40,12 +40,14 @@ pub enum ValueTag {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct JITValue {
|
||||
tag: ValueTag,
|
||||
data: JITValueData,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub union JITValueData {
|
||||
int: i64,
|
||||
float: f64,
|
||||
@@ -365,11 +367,21 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
||||
.unwrap(),
|
||||
)?,
|
||||
OpCode::Call { arity } => {
|
||||
// TODO:
|
||||
assert_eq!(arity, 1);
|
||||
let mut args = Vec::with_capacity(arity);
|
||||
for _ in 0..arity {
|
||||
args.insert(0, stack.pop());
|
||||
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())?;
|
||||
}
|
||||
let func = self
|
||||
.builder
|
||||
@@ -385,7 +397,15 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
||||
.builder
|
||||
.build_direct_call(
|
||||
self.helpers.call,
|
||||
&[func.into(), args[0].into(), self.new_ptr(vm).into()],
|
||||
&[
|
||||
func.into(),
|
||||
args.into(),
|
||||
self.helpers
|
||||
.ptr_int_type
|
||||
.const_int(arity as u64, false)
|
||||
.into(),
|
||||
self.new_ptr(vm).into(),
|
||||
],
|
||||
"call",
|
||||
)?
|
||||
.try_as_basic_value()
|
||||
|
||||
Reference in New Issue
Block a user