mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Adapt cranelift imports to only use one context
This commit is contained in:
@@ -32,7 +32,7 @@ pub fn type_of_vmtable_definition_current_elements(vmoffsets: &VMOffsets) -> ir:
|
|||||||
ir::Type::int(u16::from(vmoffsets.size_of_vmtable_definition_current_elements()) * 8).unwrap()
|
ir::Type::int(u16::from(vmoffsets.size_of_vmtable_definition_current_elements()) * 8).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `FuncEnvironment` implementation for use by the `ModuleInfoEnvironment`.
|
/// The `FuncEnvironment` implementation for use by the `ModuleEnvironment`.
|
||||||
pub struct FuncEnvironment<'module_environment> {
|
pub struct FuncEnvironment<'module_environment> {
|
||||||
/// Target-specified configuration.
|
/// Target-specified configuration.
|
||||||
target_config: TargetFrontendConfig,
|
target_config: TargetFrontendConfig,
|
||||||
@@ -472,9 +472,9 @@ impl<'module_environment> TargetEnvironment for FuncEnvironment<'module_environm
|
|||||||
|
|
||||||
impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_environment> {
|
impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_environment> {
|
||||||
fn is_wasm_parameter(&self, _signature: &ir::Signature, index: usize) -> bool {
|
fn is_wasm_parameter(&self, _signature: &ir::Signature, index: usize) -> bool {
|
||||||
// The first two parameters are the vmctx and caller vmctx. The rest are
|
// The first parameter is the vmctx. The rest are
|
||||||
// the wasm parameters.
|
// the wasm parameters.
|
||||||
index >= 2
|
index >= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_table(&mut self, func: &mut ir::Function, index: TableIndex) -> WasmResult<ir::Table> {
|
fn make_table(&mut self, func: &mut ir::Function, index: TableIndex) -> WasmResult<ir::Table> {
|
||||||
@@ -802,7 +802,6 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut real_call_args = Vec::with_capacity(call_args.len() + 2);
|
let mut real_call_args = Vec::with_capacity(call_args.len() + 2);
|
||||||
let caller_vmctx = pos.func.special_param(ArgumentPurpose::VMContext).unwrap();
|
|
||||||
|
|
||||||
// First append the callee vmctx address.
|
// First append the callee vmctx address.
|
||||||
let vmctx = pos.ins().load(
|
let vmctx = pos.ins().load(
|
||||||
@@ -812,7 +811,6 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
|
|||||||
i32::from(self.offsets.vmcaller_checked_anyfunc_vmctx()),
|
i32::from(self.offsets.vmcaller_checked_anyfunc_vmctx()),
|
||||||
);
|
);
|
||||||
real_call_args.push(vmctx);
|
real_call_args.push(vmctx);
|
||||||
real_call_args.push(caller_vmctx);
|
|
||||||
|
|
||||||
// Then append the regular call arguments.
|
// Then append the regular call arguments.
|
||||||
real_call_args.extend_from_slice(call_args);
|
real_call_args.extend_from_slice(call_args);
|
||||||
@@ -828,17 +826,15 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
|
|||||||
call_args: &[ir::Value],
|
call_args: &[ir::Value],
|
||||||
) -> WasmResult<ir::Inst> {
|
) -> WasmResult<ir::Inst> {
|
||||||
let mut real_call_args = Vec::with_capacity(call_args.len() + 2);
|
let mut real_call_args = Vec::with_capacity(call_args.len() + 2);
|
||||||
let caller_vmctx = pos.func.special_param(ArgumentPurpose::VMContext).unwrap();
|
|
||||||
|
|
||||||
// Handle direct calls to locally-defined functions.
|
// Handle direct calls to locally-defined functions.
|
||||||
if !self.module.is_imported_function(callee_index) {
|
if !self.module.is_imported_function(callee_index) {
|
||||||
|
// Let's get the caller vmctx
|
||||||
|
let caller_vmctx = pos.func.special_param(ArgumentPurpose::VMContext).unwrap();
|
||||||
// First append the callee vmctx address, which is the same as the caller vmctx in
|
// First append the callee vmctx address, which is the same as the caller vmctx in
|
||||||
// this case.
|
// this case.
|
||||||
real_call_args.push(caller_vmctx);
|
real_call_args.push(caller_vmctx);
|
||||||
|
|
||||||
// Then append the caller vmctx address.
|
|
||||||
real_call_args.push(caller_vmctx);
|
|
||||||
|
|
||||||
// Then append the regular call arguments.
|
// Then append the regular call arguments.
|
||||||
real_call_args.extend_from_slice(call_args);
|
real_call_args.extend_from_slice(call_args);
|
||||||
|
|
||||||
@@ -864,7 +860,6 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
|
|||||||
i32::try_from(self.offsets.vmctx_vmfunction_import_vmctx(callee_index)).unwrap();
|
i32::try_from(self.offsets.vmctx_vmfunction_import_vmctx(callee_index)).unwrap();
|
||||||
let vmctx = pos.ins().load(pointer_type, mem_flags, base, vmctx_offset);
|
let vmctx = pos.ins().load(pointer_type, mem_flags, base, vmctx_offset);
|
||||||
real_call_args.push(vmctx);
|
real_call_args.push(vmctx);
|
||||||
real_call_args.push(caller_vmctx);
|
|
||||||
|
|
||||||
// Then append the regular call arguments.
|
// Then append the regular call arguments.
|
||||||
real_call_args.extend_from_slice(call_args);
|
real_call_args.extend_from_slice(call_args);
|
||||||
|
|||||||
@@ -37,9 +37,6 @@ pub fn make_trampoline_dynamic_function(
|
|||||||
ir::ArgumentPurpose::VMContext,
|
ir::ArgumentPurpose::VMContext,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Add the caller/callee `vmctx` parameter.
|
|
||||||
stub_sig.params.push(ir::AbiParam::new(pointer_type));
|
|
||||||
|
|
||||||
// Add the `sig_index` parameter.
|
// Add the `sig_index` parameter.
|
||||||
stub_sig.params.push(ir::AbiParam::new(types::I32));
|
stub_sig.params.push(ir::AbiParam::new(types::I32));
|
||||||
|
|
||||||
@@ -49,7 +46,7 @@ pub fn make_trampoline_dynamic_function(
|
|||||||
// Compute the size of the values vector. The vmctx and caller vmctx are passed separately.
|
// Compute the size of the values vector. The vmctx and caller vmctx are passed separately.
|
||||||
let value_size = mem::size_of::<u128>();
|
let value_size = mem::size_of::<u128>();
|
||||||
let values_vec_len =
|
let values_vec_len =
|
||||||
(value_size * cmp::max(signature.params.len() - 2, signature.returns.len())) as u32;
|
(value_size * cmp::max(signature.params.len() - 1, signature.returns.len())) as u32;
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.func = Function::with_name_signature(ExternalName::user(0, 0), signature.clone());
|
context.func = Function::with_name_signature(ExternalName::user(0, 0), signature.clone());
|
||||||
@@ -70,29 +67,23 @@ pub fn make_trampoline_dynamic_function(
|
|||||||
let values_vec_ptr_val = builder.ins().stack_addr(pointer_type, ss, 0);
|
let values_vec_ptr_val = builder.ins().stack_addr(pointer_type, ss, 0);
|
||||||
let mflags = MemFlags::trusted();
|
let mflags = MemFlags::trusted();
|
||||||
// We only get the non-vmctx arguments
|
// We only get the non-vmctx arguments
|
||||||
for i in 2..signature.params.len() {
|
for i in 1..signature.params.len() {
|
||||||
let val = builder.func.dfg.block_params(block0)[i];
|
let val = builder.func.dfg.block_params(block0)[i];
|
||||||
builder.ins().store(
|
builder.ins().store(
|
||||||
mflags,
|
mflags,
|
||||||
val,
|
val,
|
||||||
values_vec_ptr_val,
|
values_vec_ptr_val,
|
||||||
((i - 2) * value_size) as i32,
|
((i - 1) * value_size) as i32,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let block_params = builder.func.dfg.block_params(block0);
|
let block_params = builder.func.dfg.block_params(block0);
|
||||||
let vmctx_ptr_val = block_params[0];
|
let vmctx_ptr_val = block_params[0];
|
||||||
let caller_vmctx_ptr_val = block_params[1];
|
|
||||||
|
|
||||||
// Get the signature index
|
// Get the signature index
|
||||||
let caller_sig_id = builder.ins().iconst(types::I32, sig_index.index() as i64);
|
let caller_sig_id = builder.ins().iconst(types::I32, sig_index.index() as i64);
|
||||||
|
|
||||||
let callee_args = vec![
|
let callee_args = vec![vmctx_ptr_val, caller_sig_id, values_vec_ptr_val];
|
||||||
vmctx_ptr_val,
|
|
||||||
caller_vmctx_ptr_val,
|
|
||||||
caller_sig_id,
|
|
||||||
values_vec_ptr_val,
|
|
||||||
];
|
|
||||||
|
|
||||||
let new_sig = builder.import_signature(stub_sig);
|
let new_sig = builder.import_signature(stub_sig);
|
||||||
|
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ pub fn make_trampoline_function_call(
|
|||||||
ir::ArgumentPurpose::VMContext,
|
ir::ArgumentPurpose::VMContext,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Add the caller `vmctx` parameter.
|
|
||||||
wrapper_sig.params.push(ir::AbiParam::new(pointer_type));
|
|
||||||
|
|
||||||
// Add the `callee_address` parameter.
|
// Add the `callee_address` parameter.
|
||||||
wrapper_sig.params.push(ir::AbiParam::new(pointer_type));
|
wrapper_sig.params.push(ir::AbiParam::new(pointer_type));
|
||||||
|
|
||||||
@@ -58,9 +55,9 @@ pub fn make_trampoline_function_call(
|
|||||||
builder.switch_to_block(block0);
|
builder.switch_to_block(block0);
|
||||||
builder.seal_block(block0);
|
builder.seal_block(block0);
|
||||||
|
|
||||||
let (vmctx_ptr_val, caller_vmctx_ptr_val, callee_value, values_vec_ptr_val) = {
|
let (vmctx_ptr_val, callee_value, values_vec_ptr_val) = {
|
||||||
let params = builder.func.dfg.block_params(block0);
|
let params = builder.func.dfg.block_params(block0);
|
||||||
(params[0], params[1], params[2], params[3])
|
(params[0], params[1], params[2])
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load the argument values out of `values_vec`.
|
// Load the argument values out of `values_vec`.
|
||||||
@@ -72,15 +69,14 @@ pub fn make_trampoline_function_call(
|
|||||||
.map(|(i, r)| {
|
.map(|(i, r)| {
|
||||||
match i {
|
match i {
|
||||||
0 => vmctx_ptr_val,
|
0 => vmctx_ptr_val,
|
||||||
1 => caller_vmctx_ptr_val,
|
|
||||||
_ =>
|
_ =>
|
||||||
// i - 2 because vmctx and caller vmctx aren't passed through `values_vec`.
|
// i - 1 because vmctx is not passed through `values_vec`.
|
||||||
{
|
{
|
||||||
builder.ins().load(
|
builder.ins().load(
|
||||||
r.value_type,
|
r.value_type,
|
||||||
mflags,
|
mflags,
|
||||||
values_vec_ptr_val,
|
values_vec_ptr_val,
|
||||||
((i - 2) * value_size) as i32,
|
((i - 1) * value_size) as i32,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +107,7 @@ pub fn make_trampoline_function_call(
|
|||||||
let mut reloc_sink = TrampolineRelocSink {};
|
let mut reloc_sink = TrampolineRelocSink {};
|
||||||
let mut trap_sink = binemit::NullTrapSink {};
|
let mut trap_sink = binemit::NullTrapSink {};
|
||||||
let mut stackmap_sink = binemit::NullStackmapSink {};
|
let mut stackmap_sink = binemit::NullStackmapSink {};
|
||||||
|
|
||||||
context
|
context
|
||||||
.compile_and_emit(
|
.compile_and_emit(
|
||||||
isa,
|
isa,
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ pub fn signature_to_cranelift_ir(
|
|||||||
0,
|
0,
|
||||||
AbiParam::special(target_config.pointer_type(), ir::ArgumentPurpose::VMContext),
|
AbiParam::special(target_config.pointer_type(), ir::ArgumentPurpose::VMContext),
|
||||||
);
|
);
|
||||||
// Prepend the caller vmctx argument.
|
|
||||||
sig.params
|
|
||||||
.insert(1, AbiParam::new(target_config.pointer_type()));
|
|
||||||
|
|
||||||
sig
|
sig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user