From c4e90f729ca5e17a29a778ace7971aeda7c22391 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 8 Apr 2020 19:02:49 -0500 Subject: [PATCH] wasmtime: Pass around more contexts instead of fields (#1486) * wasmtime: Pass around more contexts instead of fields This commit refactors some wasmtime internals to pass around more context-style structures rather than individual fields of each structure. The intention here is to make the addition of fields to a structure easier to plumb throughout the internals of wasmtime. Currently you need to edit lots of functions to pass lots of parameters, but ideally after this you'll only need to edit one or two struct fields and then relevant locations have access to the information already. Updates in this commit are: * `debug_info` configuration is now folded into `Tunables`. Additionally a `wasmtime::Config` now holds a `Tunables` directly and is passed into an internal `Compiler`. Eventually this should allow for direct configuration of the `Tunables` attributes from the `wasmtime` API, but no new configuration is exposed at this time. * `ModuleTranslation` is now passed around as a whole rather than passing individual components to allow access to all the fields, including `Tunables`. This was motivated by investigating what it would take to optionally allow loops and such to get interrupted, but that sort of codegen setting was currently relatively difficult to plumb all the way through and now it's hoped to be largely just an addition to `Tunables`. * Fix lightbeam compile --- cranelift/codegen/src/isa/mod.rs | 2 +- crates/api/src/module.rs | 1 - crates/api/src/runtime.rs | 20 +++++-- crates/environ/src/compilation.rs | 12 ++-- crates/environ/src/cranelift.rs | 84 +++++++++++++--------------- crates/environ/src/lightbeam.rs | 22 +++----- crates/environ/src/module_environ.rs | 4 +- crates/environ/src/tunables.rs | 7 ++- crates/jit/src/compiler.rs | 32 ++++------- crates/jit/src/instantiate.rs | 24 +++----- crates/jit/src/lib.rs | 2 - crates/jit/src/target_tunables.rs | 22 -------- src/commands/wasm2obj.rs | 2 - src/obj.rs | 58 ++++++------------- 14 files changed, 112 insertions(+), 180 deletions(-) delete mode 100644 crates/jit/src/target_tunables.rs diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index eaa1e599b4..f6cf9148d9 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -176,7 +176,7 @@ pub type Legalize = /// This struct provides information that a frontend may need to know about a target to /// produce Cranelift IR for the target. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Hash)] pub struct TargetFrontendConfig { /// The default calling convention of the target. pub default_call_conv: CallConv, diff --git a/crates/api/src/module.rs b/crates/api/src/module.rs index ea8ae1809d..a618791fd8 100644 --- a/crates/api/src/module.rs +++ b/crates/api/src/module.rs @@ -366,7 +366,6 @@ impl Module { let compiled = CompiledModule::new( &mut store.compiler_mut(), binary, - store.engine().config().debug_info, &*store.engine().config().profiler, )?; diff --git a/crates/api/src/runtime.rs b/crates/api/src/runtime.rs index 1aa92d6066..369f767d3d 100644 --- a/crates/api/src/runtime.rs +++ b/crates/api/src/runtime.rs @@ -2,6 +2,7 @@ use crate::externals::MemoryCreator; use crate::trampoline::MemoryCreatorProxy; use anyhow::Result; use std::cell::RefCell; +use std::cmp::min; use std::fmt; use std::path::Path; use std::rc::Rc; @@ -9,6 +10,7 @@ use std::sync::Arc; use wasmparser::{OperatorValidatorConfig, ValidatingParserConfig}; use wasmtime_environ::settings::{self, Configurable}; use wasmtime_environ::CacheConfig; +use wasmtime_environ::Tunables; use wasmtime_jit::{native, CompilationStrategy, Compiler}; use wasmtime_profiling::{JitDumpAgent, NullProfilerAgent, ProfilingAgent, VTuneAgent}; use wasmtime_runtime::RuntimeMemoryCreator; @@ -26,7 +28,7 @@ use wasmtime_runtime::RuntimeMemoryCreator; pub struct Config { pub(crate) flags: settings::Builder, pub(crate) validating_config: ValidatingParserConfig, - pub(crate) debug_info: bool, + pub(crate) tunables: Tunables, pub(crate) strategy: CompilationStrategy, pub(crate) cache_config: CacheConfig, pub(crate) profiler: Arc, @@ -37,6 +39,15 @@ impl Config { /// Creates a new configuration object with the default configuration /// specified. pub fn new() -> Config { + let mut tunables = Tunables::default(); + if cfg!(windows) { + // For now, use a smaller footprint on Windows so that we don't + // don't outstrip the paging file. + tunables.static_memory_bound = min(tunables.static_memory_bound, 0x100); + tunables.static_memory_offset_guard_size = + min(tunables.static_memory_offset_guard_size, 0x10000); + } + let mut flags = settings::builder(); // There are two possible traps for division, and this way @@ -56,7 +67,7 @@ impl Config { .expect("should be valid flag"); Config { - debug_info: false, + tunables, validating_config: ValidatingParserConfig { operator_config: OperatorValidatorConfig { enable_threads: false, @@ -79,7 +90,7 @@ impl Config { /// /// By default this option is `false`. pub fn debug_info(&mut self, enable: bool) -> &mut Self { - self.debug_info = enable; + self.tunables.debug_info = enable; self } @@ -349,7 +360,7 @@ impl fmt::Debug for Config { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let features = &self.validating_config.operator_config; f.debug_struct("Config") - .field("debug_info", &self.debug_info) + .field("debug_info", &self.tunables.debug_info) .field("strategy", &self.strategy) .field("wasm_threads", &features.enable_threads) .field("wasm_reference_types", &features.enable_reference_types) @@ -503,6 +514,7 @@ impl Store { isa, engine.config.strategy, engine.config.cache_config.clone(), + engine.config.tunables.clone(), ); Store { inner: Rc::new(StoreInner { diff --git a/crates/environ/src/compilation.rs b/crates/environ/src/compilation.rs index 0a896316e1..8c7bde3621 100644 --- a/crates/environ/src/compilation.rs +++ b/crates/environ/src/compilation.rs @@ -2,12 +2,11 @@ //! module. use crate::cache::ModuleCacheDataTupleType; -use crate::module; -use crate::module_environ::FunctionBodyData; use crate::CacheConfig; +use crate::ModuleTranslation; use cranelift_codegen::{binemit, ir, isa, Context}; use cranelift_entity::PrimaryMap; -use cranelift_wasm::{DefinedFuncIndex, FuncIndex, ModuleTranslationState, WasmError}; +use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmError}; use serde::{Deserialize, Serialize}; use std::ops::Range; use thiserror::Error; @@ -287,12 +286,9 @@ pub enum CompileError { /// An implementation of a compiler from parsed WebAssembly module to native code. pub trait Compiler { /// Compile a parsed module with the given `TargetIsa`. - fn compile_module<'data, 'module>( - module: &'module module::Module, - module_translation: &ModuleTranslationState, - function_body_inputs: PrimaryMap>, + fn compile_module( + translation: &ModuleTranslation, isa: &dyn isa::TargetIsa, - generate_debug_info: bool, cache_config: &CacheConfig, ) -> Result; } diff --git a/crates/environ/src/cranelift.rs b/crates/environ/src/cranelift.rs index 4e8f65b8e0..061457b1d5 100644 --- a/crates/environ/src/cranelift.rs +++ b/crates/environ/src/cranelift.rs @@ -8,9 +8,7 @@ use crate::compilation::{ }; use crate::frame_layout::FrameLayout; use crate::func_environ::{get_func_name, FuncEnvironment}; -use crate::module::{Module, ModuleLocal}; -use crate::module_environ::FunctionBodyData; -use crate::CacheConfig; +use crate::{CacheConfig, FunctionBodyData, ModuleLocal, ModuleTranslation, Tunables}; use cranelift_codegen::ir::{self, ExternalName}; use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::{binemit, isa, Context}; @@ -196,72 +194,58 @@ impl crate::compilation::Compiler for Cranelift { /// Compile the module using Cranelift, producing a compilation result with /// associated relocations. fn compile_module( - module: &Module, - module_translation: &ModuleTranslationState, - function_body_inputs: PrimaryMap>, + translation: &ModuleTranslation, isa: &dyn isa::TargetIsa, - generate_debug_info: bool, cache_config: &CacheConfig, ) -> Result { let cache_entry = ModuleCacheEntry::new("cranelift", cache_config); let data = cache_entry.get_data( - ( - &module.local, - HashedModuleTranslationState(module_translation), - function_body_inputs, - Isa(isa), - generate_debug_info, - ), + CompileEnv { + local: &translation.module.local, + module_translation: HashedModuleTranslationState( + translation.module_translation.as_ref().unwrap(), + ), + function_body_inputs: &translation.function_body_inputs, + isa: Isa(isa), + tunables: &translation.tunables, + }, compile, )?; Ok(data.into_tuple()) } } -fn compile( - ( - module, - HashedModuleTranslationState(module_translation), - function_body_inputs, - Isa(isa), - generate_debug_info, - ): ( - &ModuleLocal, - HashedModuleTranslationState<'_>, - PrimaryMap>, - Isa<'_, '_>, - bool, - ), -) -> Result { - let mut functions = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut relocations = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut address_transforms = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut value_ranges = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut stack_slots = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut traps = PrimaryMap::with_capacity(function_body_inputs.len()); - let mut frame_layouts = PrimaryMap::with_capacity(function_body_inputs.len()); +fn compile(env: CompileEnv<'_>) -> Result { + let Isa(isa) = env.isa; + let mut functions = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut relocations = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut address_transforms = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut value_ranges = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut stack_slots = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut traps = PrimaryMap::with_capacity(env.function_body_inputs.len()); + let mut frame_layouts = PrimaryMap::with_capacity(env.function_body_inputs.len()); - function_body_inputs + env.function_body_inputs .into_iter() .collect::)>>() .par_iter() .map_init(FuncTranslator::new, |func_translator, (i, input)| { - let func_index = module.func_index(*i); + let func_index = env.local.func_index(*i); let mut context = Context::new(); context.func.name = get_func_name(func_index); - context.func.signature = module.signatures[module.functions[func_index]].clone(); + context.func.signature = env.local.signatures[env.local.functions[func_index]].clone(); context.func.collect_frame_layout_info(); - if generate_debug_info { + if env.tunables.debug_info { context.func.collect_debug_info(); } func_translator.translate( - module_translation, + env.module_translation.0, input.data, input.module_offset, &mut context.func, - &mut FuncEnvironment::new(isa.frontend_config(), module), + &mut FuncEnvironment::new(isa.frontend_config(), env.local), )?; let mut code_buf: Vec = Vec::new(); @@ -282,14 +266,14 @@ fn compile( let unwind_info = CompiledFunctionUnwindInfo::new(isa, &context); - let address_transform = if generate_debug_info { + let address_transform = if env.tunables.debug_info { let body_len = code_buf.len(); Some(get_function_address_map(&context, input, body_len, isa)) } else { None }; - let frame_layout = if generate_debug_info { + let frame_layout = if env.tunables.debug_info { let (initial_commands, commands) = get_frame_layout(&context, isa); Some(FrameLayout { call_conv: context.func.signature.call_conv, @@ -300,7 +284,7 @@ fn compile( None }; - let ranges = if generate_debug_info { + let ranges = if env.tunables.debug_info { let ranges = context.build_value_labels_ranges(isa).map_err(|error| { CompileError::Codegen(pretty_error(&context.func, Some(isa), error)) })?; @@ -366,6 +350,15 @@ fn compile( )) } +#[derive(Hash)] +struct CompileEnv<'a> { + local: &'a ModuleLocal, + module_translation: HashedModuleTranslationState<'a>, + function_body_inputs: &'a PrimaryMap>, + isa: Isa<'a, 'a>, + tunables: &'a Tunables, +} + /// This is a wrapper struct to hash the specific bits of `TargetIsa` that /// affect the output we care about. The trait itself can't implement `Hash` /// (it's not object safe) so we have to implement our own hashing. @@ -374,6 +367,7 @@ struct Isa<'a, 'b>(&'a (dyn isa::TargetIsa + 'b)); impl Hash for Isa<'_, '_> { fn hash(&self, hasher: &mut H) { self.0.triple().hash(hasher); + self.0.frontend_config().hash(hasher); // TODO: if this `to_string()` is too expensive then we should upstream // a native hashing ability of flags into cranelift itself, but diff --git a/crates/environ/src/lightbeam.rs b/crates/environ/src/lightbeam.rs index 53e833e04a..d182129047 100644 --- a/crates/environ/src/lightbeam.rs +++ b/crates/environ/src/lightbeam.rs @@ -3,15 +3,13 @@ use crate::cache::ModuleCacheDataTupleType; use crate::compilation::{Compilation, CompileError, Traps}; use crate::func_environ::FuncEnvironment; -use crate::module::Module; -use crate::module_environ::FunctionBodyData; +use crate::ModuleTranslation; // TODO: Put this in `compilation` use crate::address_map::{ModuleAddressMap, ValueLabelsRanges}; use crate::cranelift::RelocSink; use crate::CacheConfig; use cranelift_codegen::isa; use cranelift_entity::{PrimaryMap, SecondaryMap}; -use cranelift_wasm::{DefinedFuncIndex, ModuleTranslationState}; /// A compiler that compiles a WebAssembly module with Lightbeam, directly translating the Wasm file. pub struct Lightbeam; @@ -19,26 +17,22 @@ pub struct Lightbeam; impl crate::compilation::Compiler for Lightbeam { /// Compile the module using Lightbeam, producing a compilation result with /// associated relocations. - fn compile_module<'data, 'module>( - module: &'module Module, - _module_translation: &ModuleTranslationState, - function_body_inputs: PrimaryMap>, + fn compile_module( + translation: &ModuleTranslation, isa: &dyn isa::TargetIsa, - // TODO - generate_debug_info: bool, _cache_config: &CacheConfig, ) -> Result { - if generate_debug_info { + if translation.tunables.debug_info { return Err(CompileError::DebugInfoNotSupported); } - let env = FuncEnvironment::new(isa.frontend_config(), &module.local); + let env = FuncEnvironment::new(isa.frontend_config(), &translation.module.local); let mut relocations = PrimaryMap::new(); let mut codegen_session: lightbeam::CodeGenSession<_> = - lightbeam::CodeGenSession::new(function_body_inputs.len() as u32, &env); + lightbeam::CodeGenSession::new(translation.function_body_inputs.len() as u32, &env); - for (i, function_body) in &function_body_inputs { - let func_index = module.local.func_index(i); + for (i, function_body) in &translation.function_body_inputs { + let func_index = translation.module.local.func_index(i); let mut reloc_sink = RelocSink::new(func_index); lightbeam::translate_function( diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index 12bc68bdf8..b4489e45f4 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -62,14 +62,14 @@ pub struct ModuleEnvironment<'data> { impl<'data> ModuleEnvironment<'data> { /// Allocates the environment data structures. - pub fn new(target_config: TargetFrontendConfig, tunables: Tunables) -> Self { + pub fn new(target_config: TargetFrontendConfig, tunables: &Tunables) -> Self { Self { result: ModuleTranslation { target_config, module: Module::new(), function_body_inputs: PrimaryMap::new(), data_initializers: Vec::new(), - tunables, + tunables: tunables.clone(), module_translation: None, }, imports: 0, diff --git a/crates/environ/src/tunables.rs b/crates/environ/src/tunables.rs index 64032f1ddc..400b8ceb2b 100644 --- a/crates/environ/src/tunables.rs +++ b/crates/environ/src/tunables.rs @@ -1,5 +1,5 @@ /// Tunable parameters for WebAssembly compilation. -#[derive(Clone)] +#[derive(Clone, Hash)] pub struct Tunables { /// For static heaps, the size in wasm pages of the heap protected by bounds checking. pub static_memory_bound: u32, @@ -9,6 +9,9 @@ pub struct Tunables { /// The size in bytes of the offset guard for dynamic heaps. pub dynamic_memory_offset_guard_size: u64, + + /// Whether or not to generate DWARF debug information. + pub debug_info: bool, } impl Default for Tunables { @@ -39,6 +42,8 @@ impl Default for Tunables { /// Allocate a small guard to optimize common cases but without /// wasting too much memor. dynamic_memory_offset_guard_size: 0x1_0000, + + debug_info: false, } } } diff --git a/crates/jit/src/compiler.rs b/crates/jit/src/compiler.rs index edcc988311..30c212d591 100644 --- a/crates/jit/src/compiler.rs +++ b/crates/jit/src/compiler.rs @@ -2,25 +2,22 @@ use crate::code_memory::CodeMemory; use crate::instantiate::SetupError; -use crate::target_tunables::target_tunables; use cranelift_codegen::ir::ExternalName; use cranelift_codegen::ir::InstBuilder; use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::Context; use cranelift_codegen::{binemit, ir}; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; -use cranelift_wasm::ModuleTranslationState; use std::collections::HashMap; use std::convert::TryFrom; use wasmtime_debug::{emit_debugsections_image, DebugInfoData}; use wasmtime_environ::entity::{EntityRef, PrimaryMap}; use wasmtime_environ::isa::{TargetFrontendConfig, TargetIsa}; use wasmtime_environ::wasm::{DefinedFuncIndex, DefinedMemoryIndex, MemoryIndex}; -use wasmtime_environ::RelocationTarget; use wasmtime_environ::{ CacheConfig, CompileError, CompiledFunction, CompiledFunctionUnwindInfo, Compiler as _C, - FunctionBodyData, Module, ModuleMemoryOffset, ModuleVmctxInfo, Relocation, Relocations, Traps, - Tunables, VMOffsets, + ModuleMemoryOffset, ModuleTranslation, ModuleVmctxInfo, Relocation, RelocationTarget, + Relocations, Traps, Tunables, VMOffsets, }; use wasmtime_runtime::{ InstantiationError, SignatureRegistry, TrapRegistration, TrapRegistry, VMFunctionBody, @@ -57,6 +54,7 @@ pub struct Compiler { signatures: SignatureRegistry, strategy: CompilationStrategy, cache_config: CacheConfig, + tunables: Tunables, } impl Compiler { @@ -65,6 +63,7 @@ impl Compiler { isa: Box, strategy: CompilationStrategy, cache_config: CacheConfig, + tunables: Tunables, ) -> Self { Self { isa, @@ -73,6 +72,7 @@ impl Compiler { strategy, trap_registry: TrapRegistry::default(), cache_config, + tunables, } } } @@ -95,16 +95,14 @@ impl Compiler { } /// Return the tunables in use by this engine. - pub fn tunables(&self) -> Tunables { - target_tunables(self.isa.triple()) + pub fn tunables(&self) -> &Tunables { + &self.tunables } /// Compile the given function bodies. pub(crate) fn compile<'data>( &mut self, - module: &Module, - module_translation: &ModuleTranslationState, - function_body_inputs: PrimaryMap>, + translation: &ModuleTranslation, debug_data: Option, ) -> Result { let ( @@ -120,22 +118,16 @@ impl Compiler { // implementation. CompilationStrategy::Auto | CompilationStrategy::Cranelift => { wasmtime_environ::cranelift::Cranelift::compile_module( - module, - module_translation, - function_body_inputs, + translation, &*self.isa, - debug_data.is_some(), &self.cache_config, ) } #[cfg(feature = "lightbeam")] CompilationStrategy::Lightbeam => { wasmtime_environ::lightbeam::Lightbeam::compile_module( - module, - module_translation, - function_body_inputs, + translation, &*self.isa, - debug_data.is_some(), &self.cache_config, ) } @@ -164,7 +156,7 @@ impl Compiler { let mut cx = FunctionBuilderContext::new(); let mut trampolines = HashMap::new(); let mut trampoline_relocations = HashMap::new(); - for sig in module.local.signatures.values() { + for sig in translation.module.local.signatures.values() { let index = self.signatures.register(sig); if trampolines.contains_key(&index) { continue; @@ -190,7 +182,7 @@ impl Compiler { // Translate debug info (DWARF) only if at least one function is present. let dbg_image = if debug_data.is_some() && !finished_functions.is_empty() { let target_config = self.isa.frontend_config(); - let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local); + let ofs = VMOffsets::new(target_config.pointer_bytes(), &translation.module.local); let mut funcs = Vec::new(); for (i, allocated) in finished_functions.into_iter() { diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs index d1f4d75b32..e2b51d8db2 100644 --- a/crates/jit/src/instantiate.rs +++ b/crates/jit/src/instantiate.rs @@ -63,7 +63,6 @@ impl<'data> RawCompiledModule<'data> { fn new( compiler: &mut Compiler, data: &'data [u8], - debug_info: bool, profiler: &dyn ProfilingAgent, ) -> Result { let environ = ModuleEnvironment::new(compiler.frontend_config(), compiler.tunables()); @@ -72,20 +71,13 @@ impl<'data> RawCompiledModule<'data> { .translate(data) .map_err(|error| SetupError::Compile(CompileError::Wasm(error)))?; - let debug_data = if debug_info { + let mut debug_data = None; + if compiler.tunables().debug_info { // TODO Do we want to ignore invalid DWARF data? - let debug_data = read_debuginfo(&data)?; - Some(debug_data) - } else { - None - }; + debug_data = Some(read_debuginfo(&data)?); + } - let compilation = compiler.compile( - &translation.module, - translation.module_translation.as_ref().unwrap(), - translation.function_body_inputs, - debug_data, - )?; + let compilation = compiler.compile(&translation, debug_data)?; link_module(&translation.module, &compilation); @@ -148,10 +140,9 @@ impl CompiledModule { pub fn new<'data>( compiler: &mut Compiler, data: &'data [u8], - debug_info: bool, profiler: &dyn ProfilingAgent, ) -> Result { - let raw = RawCompiledModule::<'data>::new(compiler, data, debug_info, profiler)?; + let raw = RawCompiledModule::<'data>::new(compiler, data, profiler)?; Ok(Self::from_parts( raw.module, @@ -282,12 +273,11 @@ pub unsafe fn instantiate( compiler: &mut Compiler, data: &[u8], resolver: &mut dyn Resolver, - debug_info: bool, is_bulk_memory: bool, profiler: &dyn ProfilingAgent, mem_creator: Option<&dyn RuntimeMemoryCreator>, ) -> Result { - let instance = CompiledModule::new(compiler, data, debug_info, profiler)?.instantiate( + let instance = CompiledModule::new(compiler, data, profiler)?.instantiate( is_bulk_memory, resolver, compiler.signatures(), diff --git a/crates/jit/src/lib.rs b/crates/jit/src/lib.rs index c524b31a09..057e76c125 100644 --- a/crates/jit/src/lib.rs +++ b/crates/jit/src/lib.rs @@ -28,7 +28,6 @@ mod imports; mod instantiate; mod link; mod resolver; -mod target_tunables; pub mod native; pub mod trampoline; @@ -38,7 +37,6 @@ pub use crate::compiler::{make_trampoline, Compilation, CompilationStrategy, Com pub use crate::instantiate::{instantiate, CompiledModule, SetupError}; pub use crate::link::link_module; pub use crate::resolver::{NullResolver, Resolver}; -pub use crate::target_tunables::target_tunables; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/crates/jit/src/target_tunables.rs b/crates/jit/src/target_tunables.rs deleted file mode 100644 index 2fd5b4848f..0000000000 --- a/crates/jit/src/target_tunables.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::cmp::min; -use target_lexicon::{OperatingSystem, Triple}; -use wasmtime_environ::Tunables; - -/// Return a `Tunables` instance tuned for the given target platform. -pub fn target_tunables(triple: &Triple) -> Tunables { - let mut result = Tunables::default(); - - match triple.operating_system { - OperatingSystem::Windows => { - // For now, use a smaller footprint on Windows so that we don't - // don't outstrip the paging file. - // TODO: Make this configurable. - result.static_memory_bound = min(result.static_memory_bound, 0x100); - result.static_memory_offset_guard_size = - min(result.static_memory_offset_guard_size, 0x10000); - } - _ => {} - } - - result -} diff --git a/src/commands/wasm2obj.rs b/src/commands/wasm2obj.rs index dbfd89042b..0ab1a6711e 100644 --- a/src/commands/wasm2obj.rs +++ b/src/commands/wasm2obj.rs @@ -11,8 +11,6 @@ use std::{ use structopt::{clap::AppSettings, StructOpt}; use target_lexicon::Triple; use wasmtime_environ::CacheConfig; -#[cfg(feature = "lightbeam")] -use wasmtime_environ::Lightbeam; /// The after help text for the `wasm2obj` command. pub const WASM2OBJ_AFTER_HELP: &str = "The translation is dependent on the environment chosen.\n\ diff --git a/src/obj.rs b/src/obj.rs index 8684c500c5..f51022843b 100644 --- a/src/obj.rs +++ b/src/obj.rs @@ -54,29 +54,14 @@ pub fn compile_to_obj( let mut obj = Artifact::new(isa.triple().clone(), artifact_name); // TODO: Expose the tunables as command-line flags. - let tunables = Tunables::default(); + let mut tunables = Tunables::default(); + tunables.debug_info = debug_info; - let ( - module, - module_translation, - lazy_function_body_inputs, - lazy_data_initializers, - target_config, - ) = { - let environ = ModuleEnvironment::new(isa.frontend_config(), tunables); + let environ = ModuleEnvironment::new(isa.frontend_config(), &tunables); - let translation = environ - .translate(wasm) - .context("failed to translate module")?; - - ( - translation.module, - translation.module_translation.unwrap(), - translation.function_body_inputs, - translation.data_initializers, - translation.target_config, - ) - }; + let translation = environ + .translate(wasm) + .context("failed to translate module")?; // TODO: use the traps information let ( @@ -88,23 +73,11 @@ pub fn compile_to_obj( _traps, frame_layouts, ) = match strategy { - Strategy::Auto | Strategy::Cranelift => Cranelift::compile_module( - &module, - &module_translation, - lazy_function_body_inputs, - &*isa, - debug_info, - cache_config, - ), + Strategy::Auto | Strategy::Cranelift => { + Cranelift::compile_module(&translation, &*isa, cache_config) + } #[cfg(feature = "lightbeam")] - Strategy::Lightbeam => Lightbeam::compile_module( - &module, - &module_translation, - lazy_function_body_inputs, - &*isa, - debug_info, - cache_config, - ), + Strategy::Lightbeam => Lightbeam::compile_module(&translation, &*isa, cache_config), #[cfg(not(feature = "lightbeam"))] Strategy::Lightbeam => bail!("lightbeam support not enabled"), other => bail!("unsupported compilation strategy {:?}", other), @@ -116,7 +89,10 @@ pub fn compile_to_obj( } let module_vmctx_info = { - let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local); + let ofs = VMOffsets::new( + translation.target_config.pointer_bytes(), + &translation.module.local, + ); ModuleVmctxInfo { memory_offset: if ofs.num_imported_memories > 0 { ModuleMemoryOffset::Imported(ofs.vmctx_vmmemory_import(MemoryIndex::new(0))) @@ -133,11 +109,11 @@ pub fn compile_to_obj( emit_module( &mut obj, - &module, + &translation.module, &compilation, &relocations, - &lazy_data_initializers, - &target_config, + &translation.data_initializers, + &translation.target_config, ) .map_err(|e| anyhow!(e)) .context("failed to emit module")?;