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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -366,7 +366,6 @@ impl Module {
|
||||
let compiled = CompiledModule::new(
|
||||
&mut store.compiler_mut(),
|
||||
binary,
|
||||
store.engine().config().debug_info,
|
||||
&*store.engine().config().profiler,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -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<dyn ProfilingAgent>,
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<DefinedFuncIndex, FunctionBodyData<'data>>,
|
||||
fn compile_module(
|
||||
translation: &ModuleTranslation,
|
||||
isa: &dyn isa::TargetIsa,
|
||||
generate_debug_info: bool,
|
||||
cache_config: &CacheConfig,
|
||||
) -> Result<ModuleCacheDataTupleType, CompileError>;
|
||||
}
|
||||
|
||||
@@ -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<DefinedFuncIndex, FunctionBodyData<'_>>,
|
||||
translation: &ModuleTranslation,
|
||||
isa: &dyn isa::TargetIsa,
|
||||
generate_debug_info: bool,
|
||||
cache_config: &CacheConfig,
|
||||
) -> Result<ModuleCacheDataTupleType, CompileError> {
|
||||
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<DefinedFuncIndex, FunctionBodyData<'_>>,
|
||||
Isa<'_, '_>,
|
||||
bool,
|
||||
),
|
||||
) -> Result<ModuleCacheDataTupleType, CompileError> {
|
||||
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<ModuleCacheDataTupleType, CompileError> {
|
||||
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::<Vec<(DefinedFuncIndex, &FunctionBodyData<'_>)>>()
|
||||
.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<u8> = 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<DefinedFuncIndex, FunctionBodyData<'a>>,
|
||||
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<H: Hasher>(&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
|
||||
|
||||
@@ -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<DefinedFuncIndex, FunctionBodyData<'data>>,
|
||||
fn compile_module(
|
||||
translation: &ModuleTranslation,
|
||||
isa: &dyn isa::TargetIsa,
|
||||
// TODO
|
||||
generate_debug_info: bool,
|
||||
_cache_config: &CacheConfig,
|
||||
) -> Result<ModuleCacheDataTupleType, CompileError> {
|
||||
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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<dyn TargetIsa>,
|
||||
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<DefinedFuncIndex, FunctionBodyData<'data>>,
|
||||
translation: &ModuleTranslation,
|
||||
debug_data: Option<DebugInfoData>,
|
||||
) -> Result<Compilation, SetupError> {
|
||||
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() {
|
||||
|
||||
@@ -63,7 +63,6 @@ impl<'data> RawCompiledModule<'data> {
|
||||
fn new(
|
||||
compiler: &mut Compiler,
|
||||
data: &'data [u8],
|
||||
debug_info: bool,
|
||||
profiler: &dyn ProfilingAgent,
|
||||
) -> Result<Self, SetupError> {
|
||||
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<Self, SetupError> {
|
||||
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<InstanceHandle, SetupError> {
|
||||
let instance = CompiledModule::new(compiler, data, debug_info, profiler)?.instantiate(
|
||||
let instance = CompiledModule::new(compiler, data, profiler)?.instantiate(
|
||||
is_bulk_memory,
|
||||
resolver,
|
||||
compiler.signatures(),
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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\
|
||||
|
||||
52
src/obj.rs
52
src/obj.rs
@@ -54,30 +54,15 @@ 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,
|
||||
)
|
||||
};
|
||||
|
||||
// TODO: use the traps information
|
||||
let (
|
||||
compilation,
|
||||
@@ -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")?;
|
||||
|
||||
Reference in New Issue
Block a user