mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 06:35: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,27 +770,29 @@ 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();
|
||||||
|
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if self.track_state {
|
||||||
emit_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
&module_info,
|
emit_stack_map(
|
||||||
&intrinsics,
|
&module_info,
|
||||||
&builder,
|
&intrinsics,
|
||||||
self.index,
|
&builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::FunctionHeader,
|
&mut *stackmaps,
|
||||||
&self.locals,
|
StackmapEntryKind::FunctionHeader,
|
||||||
&state,
|
&self.locals,
|
||||||
self.ctx.as_mut().unwrap(),
|
&state,
|
||||||
::std::usize::MAX,
|
self.ctx.as_mut().unwrap(),
|
||||||
);
|
::std::usize::MAX,
|
||||||
finalize_opcode_stack_map(
|
);
|
||||||
&intrinsics,
|
finalize_opcode_stack_map(
|
||||||
&builder,
|
&intrinsics,
|
||||||
self.index,
|
&builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::FunctionHeader,
|
&mut *stackmaps,
|
||||||
::std::usize::MAX,
|
StackmapEntryKind::FunctionHeader,
|
||||||
);
|
::std::usize::MAX,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -918,33 +922,35 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
|
|
||||||
builder.position_at_end(&loop_body);
|
builder.position_at_end(&loop_body);
|
||||||
|
|
||||||
if let Some(offset) = opcode_offset {
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if let Some(offset) = opcode_offset {
|
||||||
emit_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
&info,
|
emit_stack_map(
|
||||||
intrinsics,
|
&info,
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Loop,
|
&mut *stackmaps,
|
||||||
&self.locals,
|
StackmapEntryKind::Loop,
|
||||||
state,
|
&self.locals,
|
||||||
ctx,
|
state,
|
||||||
offset,
|
ctx,
|
||||||
);
|
offset,
|
||||||
let signal_mem = ctx.signal_mem();
|
);
|
||||||
let iv = builder
|
let signal_mem = ctx.signal_mem();
|
||||||
.build_store(signal_mem, context.i8_type().const_int(0 as u64, false));
|
let iv = builder
|
||||||
// Any 'store' can be made volatile.
|
.build_store(signal_mem, context.i8_type().const_int(0 as u64, false));
|
||||||
iv.set_volatile(true).unwrap();
|
// Any 'store' can be made volatile.
|
||||||
finalize_opcode_stack_map(
|
iv.set_volatile(true).unwrap();
|
||||||
intrinsics,
|
finalize_opcode_stack_map(
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Loop,
|
&mut *stackmaps,
|
||||||
offset,
|
StackmapEntryKind::Loop,
|
||||||
);
|
offset,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.push_loop(loop_body, loop_next, phis);
|
state.push_loop(loop_body, loop_next, phis);
|
||||||
@ -1215,28 +1221,30 @@ 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 {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if self.track_state {
|
||||||
emit_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
&info,
|
emit_stack_map(
|
||||||
intrinsics,
|
&info,
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Trappable,
|
&mut *stackmaps,
|
||||||
&self.locals,
|
StackmapEntryKind::Trappable,
|
||||||
state,
|
&self.locals,
|
||||||
ctx,
|
state,
|
||||||
offset,
|
ctx,
|
||||||
);
|
offset,
|
||||||
builder.build_call(intrinsics.trap, &[], "trap");
|
);
|
||||||
finalize_opcode_stack_map(
|
builder.build_call(intrinsics.trap, &[], "trap");
|
||||||
intrinsics,
|
finalize_opcode_stack_map(
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Trappable,
|
&mut *stackmaps,
|
||||||
offset,
|
StackmapEntryKind::Trappable,
|
||||||
);
|
offset,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.build_call(
|
builder.build_call(
|
||||||
@ -1495,32 +1503,36 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
state.popn(func_sig.params().len())?;
|
state.popn(func_sig.params().len())?;
|
||||||
if let Some(offset) = opcode_offset {
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if let Some(offset) = opcode_offset {
|
||||||
emit_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
&info,
|
emit_stack_map(
|
||||||
intrinsics,
|
&info,
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Call,
|
&mut *stackmaps,
|
||||||
&self.locals,
|
StackmapEntryKind::Call,
|
||||||
state,
|
&self.locals,
|
||||||
ctx,
|
state,
|
||||||
offset,
|
ctx,
|
||||||
)
|
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 let Some(offset) = opcode_offset {
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if let Some(offset) = opcode_offset {
|
||||||
finalize_opcode_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
intrinsics,
|
finalize_opcode_stack_map(
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Call,
|
&mut *stackmaps,
|
||||||
offset,
|
StackmapEntryKind::Call,
|
||||||
)
|
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() {
|
||||||
@ -1704,32 +1716,36 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
"typed_func_ptr",
|
"typed_func_ptr",
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(offset) = opcode_offset {
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if let Some(offset) = opcode_offset {
|
||||||
emit_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
&info,
|
emit_stack_map(
|
||||||
intrinsics,
|
&info,
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Call,
|
&mut *stackmaps,
|
||||||
&self.locals,
|
StackmapEntryKind::Call,
|
||||||
state,
|
&self.locals,
|
||||||
ctx,
|
state,
|
||||||
offset,
|
ctx,
|
||||||
)
|
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 let Some(offset) = opcode_offset {
|
if self.track_state {
|
||||||
let mut stackmaps = self.stackmaps.borrow_mut();
|
if let Some(offset) = opcode_offset {
|
||||||
finalize_opcode_stack_map(
|
let mut stackmaps = self.stackmaps.borrow_mut();
|
||||||
intrinsics,
|
finalize_opcode_stack_map(
|
||||||
builder,
|
intrinsics,
|
||||||
self.index,
|
builder,
|
||||||
&mut *stackmaps,
|
self.index,
|
||||||
StackmapEntryKind::Call,
|
&mut *stackmaps,
|
||||||
offset,
|
StackmapEntryKind::Call,
|
||||||
)
|
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