604: Fix metering benchmark with LLVM. r=syrusakbary a=nlewycky

Makes "make bench-llvm" pass.

Co-authored-by: Nick Lewycky <nick@wasmer.io>
Co-authored-by: nlewycky <nick@wasmer.io>
This commit is contained in:
bors[bot] 2019-07-31 23:58:26 +00:00
commit d117a46647
3 changed files with 68 additions and 18 deletions

View File

@ -594,14 +594,6 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
fn feed_event(&mut self, event: Event, module_info: &ModuleInfo) -> Result<(), CodegenError> {
let op = match event {
Event::Wasm(x) => x,
Event::Internal(_x) => {
return Ok(());
}
Event::WasmOwned(ref x) => x,
};
let mut state = &mut self.state;
let builder = self.builder.as_ref().unwrap();
let context = self.context.as_ref().unwrap();
@ -612,6 +604,38 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
let signatures = &self.signatures;
let mut ctx = self.ctx.as_mut().unwrap();
let op = match event {
Event::Wasm(x) => x,
Event::WasmOwned(ref x) => x,
Event::Internal(x) => {
match x {
InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {
return Ok(());
}
InternalEvent::Breakpoint(_callback) => {
return Ok(());
}
InternalEvent::GetInternal(idx) => {
if state.reachable {
let idx = idx as usize;
let field_ptr = ctx.internal_field(idx, intrinsics, builder);
let result = builder.build_load(field_ptr, "get_internal");
state.push1(result);
}
}
InternalEvent::SetInternal(idx) => {
if state.reachable {
let idx = idx as usize;
let field_ptr = ctx.internal_field(idx, intrinsics, builder);
let v = state.pop1()?;
builder.build_store(field_ptr, v);
}
}
}
return Ok(());
}
};
if !state.reachable {
match *op {
Operator::Block { ty: _ } | Operator::Loop { ty: _ } | Operator::If { ty: _ } => {

View File

@ -18,7 +18,7 @@ use wasmer_runtime_core::{
GlobalIndex, ImportedFuncIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex,
TableIndex, Type,
},
vm::Ctx,
vm::{Ctx, INTERNALS_SIZE},
};
fn type_to_llvm_ptr(intrinsics: &Intrinsics, ty: Type) -> PointerType {
@ -942,4 +942,31 @@ impl<'a> CtxType<'a> {
(imported_func_cache.func_ptr, imported_func_cache.ctx_ptr)
}
pub fn internal_field(
&mut self,
index: usize,
intrinsics: &Intrinsics,
builder: &Builder,
) -> PointerValue {
assert!(index < INTERNALS_SIZE);
let local_internals_ptr_ptr = unsafe {
builder.build_struct_gep(
self.ctx_ptr_value,
offset_to_index(Ctx::offset_internals()),
"local_internals_ptr_ptr",
)
};
let local_internals_ptr = builder
.build_load(local_internals_ptr_ptr, "local_internals_ptr")
.into_pointer_value();
unsafe {
builder.build_in_bounds_gep(
local_internals_ptr,
&[intrinsics.i32_ty.const_int(index as u64, false)],
"local_internal_field_ptr",
)
}
}
}

View File

@ -135,16 +135,15 @@ static WAT_GAS: &'static str = r#"
#[cfg(feature = "llvm")]
fn get_compiler(limit: u64, metering: bool) -> impl Compiler {
use wasmer_llvm_backend::code::LLVMModuleCodeGenerator;
use wasmer_llvm_backend::ModuleCodeGenerator;
use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
let c: StreamingCompiler<LLVMModuleCodeGenerator, _, _, _, _> =
StreamingCompiler::new(move || {
let mut chain = MiddlewareChain::new();
if metering {
chain.push(Metering::new(limit));
}
chain
});
let c: StreamingCompiler<ModuleCodeGenerator, _, _, _, _> = StreamingCompiler::new(move || {
let mut chain = MiddlewareChain::new();
if metering {
chain.push(Metering::new(limit));
}
chain
});
c
}