mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 14:45:40 +00:00
Merge #898
898: Disable track-state by default, disable @llvm.experimental.stackmap emission in the LLVM backend when it's disabled. r=nlewycky a=nlewycky Co-authored-by: Nick Lewycky <nick@wasmer.io>
This commit is contained in:
commit
912beff1fe
@ -15,7 +15,7 @@ use std::cell::RefCell;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{Backend, CacheGen, Token},
|
backend::{Backend, CacheGen, CompilerConfig, Token},
|
||||||
cache::{Artifact, Error as CacheError},
|
cache::{Artifact, Error as CacheError},
|
||||||
codegen::*,
|
codegen::*,
|
||||||
memory::MemoryType,
|
memory::MemoryType,
|
||||||
@ -676,6 +676,7 @@ pub struct LLVMModuleCodeGenerator {
|
|||||||
personality_func: FunctionValue,
|
personality_func: FunctionValue,
|
||||||
module: Module,
|
module: Module,
|
||||||
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
||||||
|
track_state: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LLVMFunctionCodeGenerator {
|
pub struct LLVMFunctionCodeGenerator {
|
||||||
@ -693,6 +694,7 @@ pub struct LLVMFunctionCodeGenerator {
|
|||||||
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
||||||
index: usize,
|
index: usize,
|
||||||
opcode_offset: usize,
|
opcode_offset: usize,
|
||||||
|
track_state: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
||||||
@ -768,6 +770,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
let builder = self.builder.as_ref().unwrap();
|
let builder = self.builder.as_ref().unwrap();
|
||||||
let intrinsics = self.intrinsics.as_ref().unwrap();
|
let intrinsics = self.intrinsics.as_ref().unwrap();
|
||||||
|
|
||||||
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
emit_stack_map(
|
emit_stack_map(
|
||||||
&module_info,
|
&module_info,
|
||||||
@ -790,6 +793,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
::std::usize::MAX,
|
::std::usize::MAX,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -918,6 +922,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
|
|
||||||
builder.position_at_end(&loop_body);
|
builder.position_at_end(&loop_body);
|
||||||
|
|
||||||
|
if self.track_state {
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
emit_stack_map(
|
emit_stack_map(
|
||||||
@ -946,6 +951,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
state.push_loop(loop_body, loop_next, phis);
|
state.push_loop(loop_body, loop_next, phis);
|
||||||
}
|
}
|
||||||
@ -1215,6 +1221,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
// Comment out this `if` block to allow spectests to pass.
|
// Comment out this `if` block to allow spectests to pass.
|
||||||
// TODO: fix this
|
// TODO: fix this
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
emit_stack_map(
|
emit_stack_map(
|
||||||
&info,
|
&info,
|
||||||
@ -1238,6 +1245,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
builder.build_call(
|
builder.build_call(
|
||||||
intrinsics.throw_trap,
|
intrinsics.throw_trap,
|
||||||
@ -1495,6 +1503,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
state.popn(func_sig.params().len())?;
|
state.popn(func_sig.params().len())?;
|
||||||
|
if self.track_state {
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
emit_stack_map(
|
emit_stack_map(
|
||||||
@ -1510,7 +1519,9 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let call_site = builder.build_call(func_ptr, ¶ms, &state.var_name());
|
let call_site = builder.build_call(func_ptr, ¶ms, &state.var_name());
|
||||||
|
if self.track_state {
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
finalize_opcode_stack_map(
|
finalize_opcode_stack_map(
|
||||||
@ -1522,6 +1533,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(basic_value) = call_site.try_as_basic_value().left() {
|
if let Some(basic_value) = call_site.try_as_basic_value().left() {
|
||||||
match func_sig.returns().len() {
|
match func_sig.returns().len() {
|
||||||
@ -1704,6 +1716,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
"typed_func_ptr",
|
"typed_func_ptr",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if self.track_state {
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
emit_stack_map(
|
emit_stack_map(
|
||||||
@ -1719,7 +1732,9 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let call_site = builder.build_call(typed_func_ptr, &args, "indirect_call");
|
let call_site = builder.build_call(typed_func_ptr, &args, "indirect_call");
|
||||||
|
if self.track_state {
|
||||||
if let Some(offset) = opcode_offset {
|
if let Some(offset) = opcode_offset {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
finalize_opcode_stack_map(
|
finalize_opcode_stack_map(
|
||||||
@ -1731,6 +1746,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
offset,
|
offset,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match wasmer_fn_sig.returns() {
|
match wasmer_fn_sig.returns() {
|
||||||
[] => {}
|
[] => {}
|
||||||
@ -7242,6 +7258,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
func_import_count: 0,
|
func_import_count: 0,
|
||||||
personality_func,
|
personality_func,
|
||||||
stackmaps: Rc::new(RefCell::new(StackmapRegistry::default())),
|
stackmaps: Rc::new(RefCell::new(StackmapRegistry::default())),
|
||||||
|
track_state: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7341,6 +7358,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
stackmaps: self.stackmaps.clone(),
|
stackmaps: self.stackmaps.clone(),
|
||||||
index: local_func_index,
|
index: local_func_index,
|
||||||
opcode_offset: 0,
|
opcode_offset: 0,
|
||||||
|
track_state: self.track_state,
|
||||||
};
|
};
|
||||||
self.functions.push(code);
|
self.functions.push(code);
|
||||||
Ok(self.functions.last_mut().unwrap())
|
Ok(self.functions.last_mut().unwrap())
|
||||||
@ -7416,6 +7434,11 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
Ok((backend, Box::new(cache_gen)))
|
Ok((backend, Box::new(cache_gen)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn feed_compiler_config(&mut self, config: &CompilerConfig) -> Result<(), CodegenError> {
|
||||||
|
self.track_state = config.track_state;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
|
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
|
||||||
self.signatures = signatures
|
self.signatures = signatures
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -177,8 +177,8 @@ struct Run {
|
|||||||
|
|
||||||
/// Whether or not state tracking should be disabled during compilation.
|
/// Whether or not state tracking should be disabled during compilation.
|
||||||
/// State tracking is necessary for tier switching and backtracing.
|
/// State tracking is necessary for tier switching and backtracing.
|
||||||
#[structopt(long = "no-track-state")]
|
#[structopt(long = "track-state")]
|
||||||
no_track_state: bool,
|
track_state: bool,
|
||||||
|
|
||||||
/// The command name is a string that will override the first argument passed
|
/// The command name is a string that will override the first argument passed
|
||||||
/// to the wasm program. This is used in wapm to provide nicer output in
|
/// to the wasm program. This is used in wapm to provide nicer output in
|
||||||
@ -419,7 +419,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let track_state = !options.no_track_state;
|
let track_state = options.track_state;
|
||||||
|
|
||||||
#[cfg(feature = "loader-kernel")]
|
#[cfg(feature = "loader-kernel")]
|
||||||
let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader {
|
let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader {
|
||||||
|
Loading…
Reference in New Issue
Block a user