mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Merge #1004
1004: Adapt backend usage depending on wasm file executed r=MarkMcCaskey a=d0iasm Adapt backend usage depending on wasm file executed in issue #998. Close #998 # Description Add `auto` backend into a runtime-core and use it as a default backend. The `auto` backend is equivalent to: * singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64. * cranelift otherwise. Co-authored-by: Asami Doi <doiasami1219@gmail.com>
This commit is contained in:
commit
19dfdec236
@ -4,6 +4,7 @@
|
||||
|
||||
- [#1006](https://github.com/wasmerio/wasmer/pull/1006) Fix minor panic issue when `wasmer::compile_with` called with llvm backend
|
||||
- [#1009](https://github.com/wasmerio/wasmer/pull/1009) Enable LLVM verifier for all tests, add new llvm-backend-tests crate.
|
||||
- [#1004](https://github.com/wasmerio/wasmer/pull/1004) Add the Auto backend to enable to adapt backend usage depending on wasm file executed.
|
||||
|
||||
## 0.11.0 - 2019-11-22
|
||||
|
||||
|
@ -28,6 +28,7 @@ pub enum Backend {
|
||||
Cranelift,
|
||||
Singlepass,
|
||||
LLVM,
|
||||
Auto,
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
@ -40,6 +41,7 @@ impl Backend {
|
||||
"singlepass",
|
||||
#[cfg(feature = "backend-llvm")]
|
||||
"llvm",
|
||||
"auto",
|
||||
]
|
||||
}
|
||||
|
||||
@ -50,6 +52,7 @@ impl Backend {
|
||||
Backend::Cranelift => "cranelift",
|
||||
Backend::Singlepass => "singlepass",
|
||||
Backend::LLVM => "llvm",
|
||||
Backend::Auto => "auto",
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,6 +70,7 @@ impl std::str::FromStr for Backend {
|
||||
"singlepass" => Ok(Backend::Singlepass),
|
||||
"cranelift" => Ok(Backend::Cranelift),
|
||||
"llvm" => Ok(Backend::LLVM),
|
||||
"auto" => Ok(Backend::Auto),
|
||||
_ => Err(format!("The backend {} doesn't exist", s)),
|
||||
}
|
||||
}
|
||||
|
@ -265,6 +265,7 @@ fn requires_pre_validation(backend: Backend) -> bool {
|
||||
Backend::Cranelift => true,
|
||||
Backend::LLVM => true,
|
||||
Backend::Singlepass => false,
|
||||
Backend::Auto => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,11 +254,6 @@ pub fn compiler_for_backend(backend: Backend) -> Option<Box<dyn Compiler>> {
|
||||
#[cfg(feature = "llvm")]
|
||||
Backend::LLVM => Some(Box::new(wasmer_llvm_backend::LLVMCompiler::new())),
|
||||
|
||||
#[cfg(any(
|
||||
not(feature = "llvm"),
|
||||
not(feature = "singlepass"),
|
||||
not(feature = "cranelift")
|
||||
))]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
extern crate structopt;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{read_to_string, File};
|
||||
use std::fs::{metadata, read_to_string, File};
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
@ -130,7 +130,7 @@ struct Run {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[structopt(
|
||||
long = "backend",
|
||||
default_value = "cranelift",
|
||||
default_value = "auto",
|
||||
case_insensitive = true,
|
||||
possible_values = Backend::variants(),
|
||||
)]
|
||||
@ -855,8 +855,30 @@ fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation {
|
||||
}
|
||||
}
|
||||
|
||||
fn run(options: Run) {
|
||||
match execute_wasm(&options) {
|
||||
fn update_backend(options: &mut Run) {
|
||||
let binary_size = match metadata(&options.path) {
|
||||
Ok(wasm_binary) => wasm_binary.len(),
|
||||
Err(_e) => 0,
|
||||
};
|
||||
|
||||
// Update backend when a backend flag is `auto`.
|
||||
// Use the Singlepass backend if it's enabled and the file provided is larger
|
||||
// than 10MiB (10485760 bytes), or it's enabled and the target architecture
|
||||
// is AArch64. Otherwise, use the Cranelift backend.
|
||||
if options.backend == Backend::Auto {
|
||||
if Backend::variants().contains(&Backend::Singlepass.to_string())
|
||||
&& (binary_size > 10485760 || cfg!(target_arch = "aarch64"))
|
||||
{
|
||||
options.backend = Backend::Singlepass;
|
||||
} else {
|
||||
options.backend = Backend::Cranelift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run(options: &mut Run) {
|
||||
update_backend(options);
|
||||
match execute_wasm(options) {
|
||||
Ok(()) => {}
|
||||
Err(message) => {
|
||||
eprintln!("Error: {}", message);
|
||||
@ -940,6 +962,7 @@ fn get_compiler_by_backend(backend: Backend, _opts: &Run) -> Option<Box<dyn Comp
|
||||
Backend::LLVM => Box::new(LLVMCompiler::new()),
|
||||
#[cfg(not(feature = "backend-llvm"))]
|
||||
Backend::LLVM => return None,
|
||||
Backend::Auto => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -958,7 +981,7 @@ fn main() {
|
||||
}
|
||||
});
|
||||
match options {
|
||||
CLIOptions::Run(options) => run(options),
|
||||
CLIOptions::Run(mut options) => run(&mut options),
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
CLIOptions::SelfUpdate => update::self_update(),
|
||||
#[cfg(target_os = "windows")]
|
||||
|
Loading…
Reference in New Issue
Block a user