mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-17 10:51:21 +00:00
feat(runtime) Get ready for tiering (#257)
* Add local_function field to context * Add local call indirection to llvm * local call indirection * Fix vm test * Fix cranelift local call indirection * Fix unwinding on nightly
This commit is contained in:
@ -664,14 +664,15 @@ fn parse_function(
|
||||
|
||||
let call_site = match func_index.local_or_import(info) {
|
||||
LocalOrImport::Local(local_func_index) => {
|
||||
let func_value = functions[local_func_index];
|
||||
let params: Vec<_> = [ctx.basic()]
|
||||
.iter()
|
||||
.chain(state.peekn(func_sig.params().len())?.iter())
|
||||
.map(|v| *v)
|
||||
.collect();
|
||||
|
||||
builder.build_call(func_value, ¶ms, &state.var_name())
|
||||
let func_ptr = ctx.local_func(local_func_index, llvm_sig);
|
||||
|
||||
builder.build_call(func_ptr, ¶ms, &state.var_name())
|
||||
}
|
||||
LocalOrImport::Import(import_func_index) => {
|
||||
let (func_ptr_untyped, ctx_ptr) = ctx.imported_func(import_func_index);
|
||||
|
@ -3,7 +3,7 @@ use inkwell::{
|
||||
builder::Builder,
|
||||
context::Context,
|
||||
module::Module,
|
||||
types::{BasicType, FloatType, IntType, PointerType, StructType, VoidType},
|
||||
types::{BasicType, FloatType, FunctionType, IntType, PointerType, StructType, VoidType},
|
||||
values::{
|
||||
BasicValue, BasicValueEnum, FloatValue, FunctionValue, InstructionValue, IntValue,
|
||||
PointerValue,
|
||||
@ -16,7 +16,8 @@ use wasmer_runtime_core::{
|
||||
module::ModuleInfo,
|
||||
structures::TypedIndex,
|
||||
types::{
|
||||
GlobalIndex, ImportedFuncIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type,
|
||||
GlobalIndex, ImportedFuncIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex,
|
||||
TableIndex, Type,
|
||||
},
|
||||
};
|
||||
|
||||
@ -161,6 +162,7 @@ impl Intrinsics {
|
||||
let imported_func_ty =
|
||||
context.struct_type(&[i8_ptr_ty_basic, ctx_ptr_ty.as_basic_type_enum()], false);
|
||||
let sigindex_ty = i32_ty;
|
||||
let local_function_ty = i8_ptr_ty;
|
||||
|
||||
let anyfunc_ty = context.struct_type(
|
||||
&[
|
||||
@ -203,6 +205,9 @@ impl Intrinsics {
|
||||
sigindex_ty
|
||||
.ptr_type(AddressSpace::Generic)
|
||||
.as_basic_type_enum(),
|
||||
local_function_ty
|
||||
.ptr_type(AddressSpace::Generic)
|
||||
.as_basic_type_enum(),
|
||||
],
|
||||
false,
|
||||
);
|
||||
@ -582,6 +587,36 @@ impl<'a> CtxType<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn local_func(&mut self, index: LocalFuncIndex, fn_ty: FunctionType) -> PointerValue {
|
||||
let local_func_array_ptr_ptr = unsafe {
|
||||
self.builder
|
||||
.build_struct_gep(self.ctx_ptr_value, 8, "local_func_array_ptr_ptr")
|
||||
};
|
||||
let local_func_array_ptr = self
|
||||
.builder
|
||||
.build_load(local_func_array_ptr_ptr, "local_func_array_ptr")
|
||||
.into_pointer_value();
|
||||
let local_func_ptr_ptr = unsafe {
|
||||
self.builder.build_in_bounds_gep(
|
||||
local_func_array_ptr,
|
||||
&[self
|
||||
.intrinsics
|
||||
.i32_ty
|
||||
.const_int(index.index() as u64, false)],
|
||||
"local_func_ptr_ptr",
|
||||
)
|
||||
};
|
||||
let local_func_ptr = self
|
||||
.builder
|
||||
.build_load(local_func_ptr_ptr, "local_func_ptr")
|
||||
.into_pointer_value();
|
||||
self.builder.build_pointer_cast(
|
||||
local_func_ptr,
|
||||
fn_ty.ptr_type(AddressSpace::Generic),
|
||||
"local_func_ptr",
|
||||
)
|
||||
}
|
||||
|
||||
pub fn dynamic_sigindex(&mut self, index: SigIndex) -> IntValue {
|
||||
let (cached_sigindices, builder, info, ctx_ptr_value, intrinsics, cache_builder) = (
|
||||
&mut self.cached_sigindices,
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(nightly, feature(unwind_attributes))]
|
||||
|
||||
use inkwell::{
|
||||
execution_engine::JitFunction,
|
||||
targets::{CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetMachine},
|
||||
|
@ -41,6 +41,7 @@ pub unsafe fn visit_fde(addr: *mut u8, size: usize, visitor: extern "C" fn(*mut
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#[cfg_attr(nightly, unwind(allowed))]
|
||||
fn throw_trap(ty: i32) -> !;
|
||||
}
|
||||
|
||||
@ -50,12 +51,13 @@ pub unsafe fn install_signal_handler() {
|
||||
SaFlags::SA_ONSTACK | SaFlags::SA_SIGINFO,
|
||||
SigSet::empty(),
|
||||
);
|
||||
sigaction(SIGFPE, &sa).unwrap();
|
||||
sigaction(SIGILL, &sa).unwrap();
|
||||
// sigaction(SIGFPE, &sa).unwrap();
|
||||
// sigaction(SIGILL, &sa).unwrap();
|
||||
sigaction(SIGSEGV, &sa).unwrap();
|
||||
sigaction(SIGBUS, &sa).unwrap();
|
||||
}
|
||||
|
||||
#[cfg_attr(nightly, unwind(allowed))]
|
||||
extern "C" fn signal_trap_handler(
|
||||
signum: ::nix::libc::c_int,
|
||||
siginfo: *mut siginfo_t,
|
||||
|
Reference in New Issue
Block a user