Remove dependency on TargetIsa from Wasmtime crates (#3178)
This commit started off by deleting the `cranelift_codegen::settings` reexport in the `wasmtime-environ` crate and then basically played whack-a-mole until everything compiled again. The main result of this is that the `wasmtime-*` family of crates have generally less of a dependency on the `TargetIsa` trait and type from Cranelift. While the dependency isn't entirely severed yet this is at least a significant start. This commit is intended to be largely refactorings, no functional changes are intended here. The refactorings are: * A `CompilerBuilder` trait has been added to `wasmtime_environ` which server as an abstraction used to create compilers and configure them in a uniform fashion. The `wasmtime::Config` type now uses this instead of cranelift-specific settings. The `wasmtime-jit` crate exports the ability to create a compiler builder from a `CompilationStrategy`, which only works for Cranelift right now. In a cranelift-less build of Wasmtime this is expected to return a trait object that fails all requests to compile. * The `Compiler` trait in the `wasmtime_environ` crate has been souped up with a number of methods that Wasmtime and other crates needed. * The `wasmtime-debug` crate is now moved entirely behind the `wasmtime-cranelift` crate. * The `wasmtime-cranelift` crate is now only depended on by the `wasmtime-jit` crate. * Wasm types in `cranelift-wasm` no longer contain their IR type, instead they only contain the `WasmType`. This is required to get everything to align correctly but will also be required in a future refactoring where the types used by `cranelift-wasm` will be extracted to a separate crate. * I moved around a fair bit of code in `wasmtime-cranelift`. * Some gdb-specific jit-specific code has moved from `wasmtime-debug` to `wasmtime-jit`.
This commit is contained in:
49
src/obj.rs
49
src/obj.rs
@@ -3,7 +3,7 @@ use object::write::Object;
|
||||
use target_lexicon::Triple;
|
||||
use wasmparser::WasmFeatures;
|
||||
use wasmtime::Strategy;
|
||||
use wasmtime_environ::{settings, settings::Configurable, ModuleEnvironment, Tunables};
|
||||
use wasmtime_environ::{ModuleEnvironment, Tunables};
|
||||
use wasmtime_jit::Compiler;
|
||||
|
||||
/// Creates object file from binary wasm data.
|
||||
@@ -15,57 +15,44 @@ pub fn compile_to_obj(
|
||||
opt_level: wasmtime::OptLevel,
|
||||
debug_info: bool,
|
||||
) -> Result<Object> {
|
||||
let isa_builder = match target {
|
||||
Some(target) => wasmtime_environ::isa::lookup(target.clone())?,
|
||||
None => cranelift_native::builder().unwrap(),
|
||||
let strategy = match strategy {
|
||||
Strategy::Auto => wasmtime_jit::CompilationStrategy::Auto,
|
||||
Strategy::Cranelift => wasmtime_jit::CompilationStrategy::Cranelift,
|
||||
#[cfg(feature = "lightbeam")]
|
||||
Strategy::Lightbeam => wasmtime_jit::CompilationStrategy::Lightbeam,
|
||||
#[cfg(not(feature = "lightbeam"))]
|
||||
Strategy::Lightbeam => bail!("lightbeam support not enabled"),
|
||||
s => bail!("unknown compilation strategy {:?}", s),
|
||||
};
|
||||
let mut flag_builder = settings::builder();
|
||||
let mut builder = Compiler::builder(strategy);
|
||||
if let Some(target) = target {
|
||||
builder.target(target.clone())?;
|
||||
}
|
||||
let mut features = WasmFeatures::default();
|
||||
|
||||
// There are two possible traps for division, and this way
|
||||
// we get the proper one if code traps.
|
||||
flag_builder.enable("avoid_div_traps").unwrap();
|
||||
|
||||
if enable_simd {
|
||||
flag_builder.enable("enable_simd").unwrap();
|
||||
builder.enable("enable_simd").unwrap();
|
||||
features.simd = true;
|
||||
}
|
||||
|
||||
match opt_level {
|
||||
wasmtime::OptLevel::None => {}
|
||||
wasmtime::OptLevel::Speed => {
|
||||
flag_builder.set("opt_level", "speed").unwrap();
|
||||
builder.set("opt_level", "speed").unwrap();
|
||||
}
|
||||
wasmtime::OptLevel::SpeedAndSize => {
|
||||
flag_builder.set("opt_level", "speed_and_size").unwrap();
|
||||
builder.set("opt_level", "speed_and_size").unwrap();
|
||||
}
|
||||
other => bail!("unknown optimization level {:?}", other),
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
|
||||
// TODO: Expose the tunables as command-line flags.
|
||||
let mut tunables = Tunables::default();
|
||||
tunables.generate_native_debuginfo = debug_info;
|
||||
tunables.parse_wasm_debuginfo = debug_info;
|
||||
|
||||
let compiler = Compiler::new(
|
||||
isa,
|
||||
match strategy {
|
||||
Strategy::Auto => wasmtime_jit::CompilationStrategy::Auto,
|
||||
Strategy::Cranelift => wasmtime_jit::CompilationStrategy::Cranelift,
|
||||
#[cfg(feature = "lightbeam")]
|
||||
Strategy::Lightbeam => wasmtime_jit::CompilationStrategy::Lightbeam,
|
||||
#[cfg(not(feature = "lightbeam"))]
|
||||
Strategy::Lightbeam => bail!("lightbeam support not enabled"),
|
||||
s => bail!("unknown compilation strategy {:?}", s),
|
||||
},
|
||||
tunables.clone(),
|
||||
features.clone(),
|
||||
true, // enable parallel compilation
|
||||
);
|
||||
|
||||
let environ = ModuleEnvironment::new(compiler.isa().frontend_config(), &tunables, &features);
|
||||
let compiler = Compiler::new(&*builder, tunables.clone(), features.clone(), true);
|
||||
let environ = ModuleEnvironment::new(&tunables, &features);
|
||||
let (_main_module, mut translation, types) = environ
|
||||
.translate(wasm)
|
||||
.context("failed to translate module")?;
|
||||
|
||||
Reference in New Issue
Block a user