Make use of Lightbeam configurable.
This adds a `--always-lightbeam` option as well as an `--always-cranelift` option, to allow the compilation strategy to be selected via the command-line. This also enables regular testing for Lightbeam.
This commit is contained in:
@@ -25,6 +25,20 @@ use wasmtime_runtime::{
|
||||
VMFunctionBody,
|
||||
};
|
||||
|
||||
/// Select which kind of compilation to use.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum CompilationStrategy {
|
||||
/// Let Wasmtime pick the strategy.
|
||||
Auto,
|
||||
|
||||
/// Compile all functions with Cranelift.
|
||||
AlwaysCranelift,
|
||||
|
||||
/// Compile all functions with Lightbeam.
|
||||
#[cfg(feature = "lightbeam")]
|
||||
AlwaysLightbeam,
|
||||
}
|
||||
|
||||
/// A WebAssembly code JIT compiler.
|
||||
///
|
||||
/// A `Compiler` instance owns the executable memory that it allocates.
|
||||
@@ -40,6 +54,7 @@ pub struct Compiler {
|
||||
trap_registration_guards: Vec<TrapRegistrationGuard>,
|
||||
trampoline_park: HashMap<*const VMFunctionBody, *const VMFunctionBody>,
|
||||
signatures: SignatureRegistry,
|
||||
strategy: CompilationStrategy,
|
||||
|
||||
/// The `FunctionBuilderContext`, shared between trampline function compilations.
|
||||
fn_builder_ctx: FunctionBuilderContext,
|
||||
@@ -47,7 +62,7 @@ pub struct Compiler {
|
||||
|
||||
impl Compiler {
|
||||
/// Construct a new `Compiler`.
|
||||
pub fn new(isa: Box<dyn TargetIsa>) -> Self {
|
||||
pub fn new(isa: Box<dyn TargetIsa>, strategy: CompilationStrategy) -> Self {
|
||||
Self {
|
||||
isa,
|
||||
code_memory: CodeMemory::new(),
|
||||
@@ -55,6 +70,7 @@ impl Compiler {
|
||||
trampoline_park: HashMap::new(),
|
||||
signatures: SignatureRegistry::new(),
|
||||
fn_builder_ctx: FunctionBuilderContext::new(),
|
||||
strategy,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,11 +89,6 @@ impl Drop for Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "lightbeam")]
|
||||
type DefaultCompiler = wasmtime_environ::lightbeam::Lightbeam;
|
||||
#[cfg(not(feature = "lightbeam"))]
|
||||
type DefaultCompiler = wasmtime_environ::cranelift::Cranelift;
|
||||
|
||||
impl Compiler {
|
||||
/// Return the target's frontend configuration settings.
|
||||
pub fn frontend_config(&self) -> TargetFrontendConfig {
|
||||
@@ -105,12 +116,27 @@ impl Compiler {
|
||||
SetupError,
|
||||
> {
|
||||
let (compilation, relocations, address_transform, value_ranges, stack_slots, traps) =
|
||||
DefaultCompiler::compile_module(
|
||||
module,
|
||||
function_body_inputs,
|
||||
&*self.isa,
|
||||
debug_data.is_some(),
|
||||
)
|
||||
match self.strategy {
|
||||
// For now, interpret `Auto` as `AlwaysCranelift` since that's the most stable
|
||||
// implementation.
|
||||
CompilationStrategy::Auto | CompilationStrategy::AlwaysCranelift => {
|
||||
wasmtime_environ::cranelift::Cranelift::compile_module(
|
||||
module,
|
||||
function_body_inputs,
|
||||
&*self.isa,
|
||||
debug_data.is_some(),
|
||||
)
|
||||
}
|
||||
#[cfg(feature = "lightbeam")]
|
||||
CompilationStrategy::AlwaysLightbeam => {
|
||||
wasmtime_environ::lightbeam::Lightbeam::compile_module(
|
||||
module,
|
||||
function_body_inputs,
|
||||
&*self.isa,
|
||||
debug_data.is_some(),
|
||||
)
|
||||
}
|
||||
}
|
||||
.map_err(SetupError::Compile)?;
|
||||
|
||||
let allocated_functions =
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::action::{get, inspect_memory, invoke};
|
||||
use crate::{
|
||||
instantiate, ActionError, ActionOutcome, Compiler, InstanceHandle, Namespace, RuntimeValue,
|
||||
SetupError,
|
||||
instantiate, ActionError, ActionOutcome, CompilationStrategy, Compiler, InstanceHandle,
|
||||
Namespace, RuntimeValue, SetupError,
|
||||
};
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use std::boxed::Box;
|
||||
@@ -103,8 +103,8 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Construct a new instance of `Context` with the given target.
|
||||
pub fn with_isa(isa: Box<dyn TargetIsa>) -> Self {
|
||||
Self::new(Box::new(Compiler::new(isa)))
|
||||
pub fn with_isa(isa: Box<dyn TargetIsa>, strategy: CompilationStrategy) -> Self {
|
||||
Self::new(Box::new(Compiler::new(isa, strategy)))
|
||||
}
|
||||
|
||||
/// Retrieve the context features
|
||||
|
||||
@@ -49,7 +49,7 @@ mod resolver;
|
||||
mod target_tunables;
|
||||
|
||||
pub use crate::action::{ActionError, ActionOutcome, RuntimeValue};
|
||||
pub use crate::compiler::Compiler;
|
||||
pub use crate::compiler::{CompilationStrategy, Compiler};
|
||||
pub use crate::context::{Context, ContextError, Features, UnknownInstance};
|
||||
pub use crate::instantiate::{instantiate, CompiledModule, SetupError};
|
||||
pub use crate::link::link_module;
|
||||
|
||||
Reference in New Issue
Block a user