Add egraphs option to Wasmtime config, and add it to fuzzing config generation. (#5067)
* Add egraphs option to Wasmtime config, and add it to fuzzing config generation. This PR adds a wrapper method for Cranelift's `use_egraphs` setting to Wasmtime's `Config`, named `cranelift_use_egraphs` analogously to its existing `cranelift_opt_level`. Eventually this should become a no-op as egraph-based optimization becomes the default, but until then it makes sense to expose this as another kind of optimization option. This PR then adds the option to the `Arbitrary`-based config generation for fuzzing, so compilation with egraphs will be fuzzed (on its own and against other configurations and oracles). * Don't use `NamedTempFile` on Windows It looks like this prevents mmap-ing since the named temporary file holds a `File` open which conflicts with the rights we're trying to open the file for mmap-ing. Instead use a temporary directory to try to fix this issue. Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This commit is contained in:
@@ -163,6 +163,7 @@ impl Config {
|
||||
.native_unwind_info(self.wasmtime.native_unwind_info)
|
||||
.cranelift_nan_canonicalization(self.wasmtime.canonicalize_nans)
|
||||
.cranelift_opt_level(self.wasmtime.opt_level.to_wasmtime())
|
||||
.cranelift_use_egraphs(self.wasmtime.use_egraphs)
|
||||
.consume_fuel(self.wasmtime.consume_fuel)
|
||||
.epoch_interruption(self.wasmtime.epoch_interruption)
|
||||
.memory_init_cow(self.wasmtime.memory_init_cow)
|
||||
@@ -303,9 +304,10 @@ impl Config {
|
||||
// Don't propagate these errors to prevent them from accidentally being
|
||||
// interpreted as invalid wasm, these should never fail on a
|
||||
// well-behaved host system.
|
||||
let file = tempfile::NamedTempFile::new().unwrap();
|
||||
std::fs::write(file.path(), module.serialize().unwrap()).unwrap();
|
||||
unsafe { Ok(Module::deserialize_file(engine, file.path()).unwrap()) }
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
let file = dir.path().join("module.wasm");
|
||||
std::fs::write(&file, module.serialize().unwrap()).unwrap();
|
||||
unsafe { Ok(Module::deserialize_file(engine, &file).unwrap()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +371,7 @@ impl<'a> Arbitrary<'a> for Config {
|
||||
#[derive(Arbitrary, Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct WasmtimeConfig {
|
||||
opt_level: OptLevel,
|
||||
use_egraphs: bool,
|
||||
debug_info: bool,
|
||||
canonicalize_nans: bool,
|
||||
interruptable: bool,
|
||||
|
||||
@@ -853,6 +853,27 @@ impl Config {
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures the Cranelift code generator to use its
|
||||
/// "egraph"-based mid-end optimizer.
|
||||
///
|
||||
/// This optimizer is intended to replace the compiler's more
|
||||
/// traditional pipeline of optimization passes with a unified
|
||||
/// code-rewriting system. It is not yet on by default, but it is
|
||||
/// intended to become the default in a future version. It may
|
||||
/// result in faster code, at the cost of slightly more
|
||||
/// compilation-time work.
|
||||
///
|
||||
/// The default value for this is `false`.
|
||||
#[cfg(compiler)]
|
||||
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
|
||||
pub fn cranelift_use_egraphs(&mut self, enable: bool) -> &mut Self {
|
||||
let val = if enable { "true" } else { "false" };
|
||||
self.compiler_config
|
||||
.settings
|
||||
.insert("use_egraphs".to_string(), val.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures whether Cranelift should perform a NaN-canonicalization pass.
|
||||
///
|
||||
/// When Cranelift is used as a code generation backend this will configure
|
||||
|
||||
Reference in New Issue
Block a user