From a1d8b9aa5bf8024ab8c0bd0128c419b051c5bea5 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 13 Jan 2020 15:40:09 +0100 Subject: [PATCH 1/3] Move backend_id to static str --- lib/clif-backend/src/code.rs | 6 ++++-- lib/llvm-backend/src/code.rs | 6 ++++-- lib/middleware-common-tests/src/lib.rs | 4 ++-- lib/runtime-core/src/codegen.rs | 4 ++-- lib/runtime-core/src/parse.rs | 2 +- lib/singlepass-backend/src/codegen_x64.rs | 6 ++++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/clif-backend/src/code.rs b/lib/clif-backend/src/code.rs index 390dbfecb53..74e59d3445b 100644 --- a/lib/clif-backend/src/code.rs +++ b/lib/clif-backend/src/code.rs @@ -32,6 +32,8 @@ use wasmer_runtime_core::{ }; use wasmparser::Type as WpType; +static BACKEND_ID: &str = "cranelift"; + pub struct CraneliftModuleCodeGenerator { isa: Box, signatures: Option>>, @@ -58,8 +60,8 @@ impl ModuleCodeGenerator unimplemented!("cross compilation is not available for clif backend") } - fn backend_id() -> String { - "cranelift".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> { diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 4333dbbf0b2..a892349bb4a 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -45,6 +45,8 @@ use wasmer_runtime_core::{ }; use wasmparser::{BinaryReaderError, MemoryImmediate, Operator, Type as WpType}; +static BACKEND_ID: &str = "llvm"; + fn func_sig_to_llvm<'ctx>( context: &'ctx Context, intrinsics: &Intrinsics<'ctx>, @@ -8721,8 +8723,8 @@ impl<'ctx> ModuleCodeGenerator, LLVMBackend, Cod } } - fn backend_id() -> String { - "llvm".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> { diff --git a/lib/middleware-common-tests/src/lib.rs b/lib/middleware-common-tests/src/lib.rs index 20d69bb3d0a..d3beeb8f786 100644 --- a/lib/middleware-common-tests/src/lib.rs +++ b/lib/middleware-common-tests/src/lib.rs @@ -110,7 +110,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), runnable_module: instance.module.runnable_module.clone(), }); true @@ -152,7 +152,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), runnable_module: instance.module.runnable_module.clone(), }); true diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index 376b8337e5e..9322b9d5bee 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -92,7 +92,7 @@ pub trait ModuleCodeGenerator, RM: RunnableModule, ) -> Self; /// Returns the backend id associated with this MCG. - fn backend_id() -> String; + fn backend_id() -> &'static str; /// It sets if the current compiler requires validation before compilation fn requires_pre_validation() -> bool { @@ -231,7 +231,7 @@ impl< validate_with_features(wasm, &compiler_config.features)?; } - let mut mcg = match MCG::backend_id().as_ref() { + let mut mcg = match MCG::backend_id() { "llvm" => MCG::new_with_target( compiler_config.triple.clone(), compiler_config.cpu_name.clone(), diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index 5a050f5c1b0..3d4e27b4154 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -82,7 +82,7 @@ pub fn read_module< func_assoc: Map::new(), signatures: Map::new(), - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), namespace_table: StringTable::new(), name_table: StringTable::new(), diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index e10b0fc98c4..3dc12ea291f 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -59,6 +59,8 @@ pub const INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS: usize = 7; /// Inline breakpoint size for aarch64. pub const INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS: usize = 12; +static BACKEND_ID: &str = "singlepass"; + #[cfg(target_arch = "x86_64")] lazy_static! { /// Performs a System V call to `target` with [stack_top..stack_base] as the argument list, from right to left. @@ -651,8 +653,8 @@ impl ModuleCodeGenerator false } - fn backend_id() -> String { - "singlepass".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn new_with_target(_: Option, _: Option, _: Option) -> Self { From 273a6307f797dbab70a10b18cea7cfea88f284d7 Mon Sep 17 00:00:00 2001 From: Syrus Date: Wed, 15 Jan 2020 14:04:08 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Use=20&=E2=80=99static=20str=20for=20backen?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/middleware-common-tests/src/lib.rs | 4 ++-- lib/runtime-core/src/state.rs | 2 +- src/bin/wasmer.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/middleware-common-tests/src/lib.rs b/lib/middleware-common-tests/src/lib.rs index d3beeb8f786..20d69bb3d0a 100644 --- a/lib/middleware-common-tests/src/lib.rs +++ b/lib/middleware-common-tests/src/lib.rs @@ -110,7 +110,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id().to_string(), + backend: MCG::backend_id(), runnable_module: instance.module.runnable_module.clone(), }); true @@ -152,7 +152,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id().to_string(), + backend: MCG::backend_id(), runnable_module: instance.module.runnable_module.clone(), }); true diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index 870e955a515..f7e9cc791b3 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -186,7 +186,7 @@ pub struct CodeVersion { pub base: usize, /// The backend used to compile this module. - pub backend: String, + pub backend: &'static str, /// `RunnableModule` for this code version. pub runnable_module: Arc>, diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 339b0a1bbac..7c4c0416139 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -486,7 +486,7 @@ fn execute_wasi( baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: options.backend.to_string().to_owned(), + backend: options.backend.to_string(), runnable_module: instance.module.runnable_module.clone(), }); true From 75d7f106f288049ad53ed3eb3ce16027b1e7d0b7 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 15 Jan 2020 10:28:06 -0800 Subject: [PATCH 3/3] Update remaining locations to use a &'static str for backend --- Cargo.lock | 32 +++++++++++++++++++++++++++++--- lib/runtime-core/src/tiering.rs | 10 +++++----- src/bin/wasmer.rs | 4 ++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1282e76f35d..90b0d753fd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,7 +558,7 @@ dependencies = [ "libc", "llvm-sys", "once_cell", - "parking_lot", + "parking_lot 0.10.0", "regex", ] @@ -827,6 +827,17 @@ dependencies = [ "md5", ] +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +dependencies = [ + "lock_api", + "parking_lot_core 0.6.2", + "rustc_version", +] + [[package]] name = "parking_lot" version = "0.10.0" @@ -834,7 +845,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.7.0", +] + +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "rustc_version", + "smallvec 0.6.13", + "winapi", ] [[package]] @@ -1800,7 +1826,7 @@ dependencies = [ "libc", "nix", "page_size", - "parking_lot", + "parking_lot 0.9.0", "rustc_version", "serde", "serde-bench", diff --git a/lib/runtime-core/src/tiering.rs b/lib/runtime-core/src/tiering.rs index 15dc1bd1937..83ebfd47159 100644 --- a/lib/runtime-core/src/tiering.rs +++ b/lib/runtime-core/src/tiering.rs @@ -43,7 +43,7 @@ struct OptimizationState { } struct OptimizationOutcome { - backend_id: String, + backend_id: &'static str, module: Module, } @@ -54,7 +54,7 @@ unsafe impl Sync for CtxWrapper {} unsafe fn do_optimize( binary: &[u8], - backend_id: String, + backend_id: &'static str, compiler: Box, ctx: &Mutex, state: &OptimizationState, @@ -87,8 +87,8 @@ pub unsafe fn run_tiering ShellExitOperation>( import_object: &ImportObject, start_raw: extern "C" fn(&mut Ctx), baseline: &mut Instance, - baseline_backend: String, - optimized_backends: Vec<(String, Box Box + Send>)>, + baseline_backend: &'static str, + optimized_backends: Vec<(&'static str, Box Box + Send>)>, interactive_shell: F, ) -> Result<(), String> { ensure_sighandler(); @@ -140,7 +140,7 @@ pub unsafe fn run_tiering ShellExitOperation>( })); loop { - let new_optimized: Option<(String, &mut Instance)> = { + let new_optimized: Option<(&'static str, &mut Instance)> = { let mut outcome = opt_state.outcome.lock().unwrap(); if let Some(x) = outcome.take() { let instance = x diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 7c4c0416139..ece6e7fb540 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -448,7 +448,7 @@ fn execute_wasi( &import_object, start_raw, &mut instance, - options.backend, + options.backend.to_string(), options .optimized_backends .iter() @@ -456,7 +456,7 @@ fn execute_wasi( |&backend| -> (Backend, Box Box + Send>) { let options = options.clone(); ( - backend, + backend.to_string(), Box::new(move || { get_compiler_by_backend(backend, &options).unwrap() }),