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:
Lachlan Sneff
2019-03-08 15:15:16 -08:00
committed by GitHub
parent a8751b6bbc
commit 17eada53f3
11 changed files with 118 additions and 11 deletions

View File

@ -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,