Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompilerConfig opt to disable IR verification in debug mode #1332

Merged
merged 3 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#1332](https://github.com/wasmerio/wasmer/pull/1332) Add option to `CompilerConfig` to force compiler IR verification off even when `debug_assertions` are enabled. This can be used to make debug builds faster, which may be important if you're creating a library that wraps Wasmer and depend on the speed of debug builds.
- [#1320](https://github.com/wasmerio/wasmer/pull/1320) Change `custom_sections` field in `ModuleInfo` to be more standards compliant by allowing multiple custom sections with the same name. To get the old behavior with the new API, you can add `.last().unwrap()` to accesses. For example, `module_info.custom_sections["custom_section_name"].last().unwrap()`.
- [#1303](https://github.com/wasmerio/wasmer/pull/1303) NaN canonicalization for singlepass backend.
- [#1292](https://github.com/wasmerio/wasmer/pull/1292) Experimental Support for Android (x86_64 and AArch64)
Expand Down
19 changes: 14 additions & 5 deletions lib/clif-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,27 @@ fn get_isa(config: Option<&CompilerConfig>) -> Box<dyn isa::TargetIsa> {
builder.set("opt_level", "speed_and_size").unwrap();
builder.set("enable_jump_tables", "false").unwrap();

if cfg!(test) || cfg!(debug_assertions) {
builder.set("enable_verifier", "true").unwrap();
} else {
builder.set("enable_verifier", "false").unwrap();
}
let enable_verifier: bool;

if let Some(config) = config {
if config.nan_canonicalization {
builder.set("enable_nan_canonicalization", "true").unwrap();
}
enable_verifier = config.enable_verification;
} else {
// Set defaults if no config found.
// NOTE: cfg(test) probably does nothing when not running `cargo test`
// on this crate
enable_verifier = cfg!(test) || cfg!(debug_assertions);
}

builder
.set(
"enable_verifier",
if enable_verifier { "true" } else { "false" },
)
.unwrap();

let flags = settings::Flags::new(builder);
debug_assert_eq!(flags.opt_level(), settings::OptLevel::SpeedAndSize);
flags
Expand Down
16 changes: 8 additions & 8 deletions lib/clif-backend/src/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Trampolines {
let sig_index = module.func_assoc[*exported_func_index];
let func_sig = &module.signatures[sig_index];

let trampoline_func = generate_func(&func_sig);
let trampoline_func = generate_func(isa, &func_sig);

ctx.func = trampoline_func;

Expand Down Expand Up @@ -150,13 +150,13 @@ impl Trampolines {

/// This function generates a trampoline for the specific signature
/// passed into it.
fn generate_func(func_sig: &FuncSig) -> ir::Function {
let trampoline_sig = generate_trampoline_signature();
fn generate_func(isa: &dyn isa::TargetIsa, func_sig: &FuncSig) -> ir::Function {
let trampoline_sig = generate_trampoline_signature(isa);

let mut func =
ir::Function::with_name_signature(ir::ExternalName::testcase("trampln"), trampoline_sig);

let export_sig_ref = func.import_signature(generate_export_signature(func_sig));
let export_sig_ref = func.import_signature(generate_export_signature(isa, func_sig));

let entry_ebb = func.dfg.make_block();
let vmctx_ptr = func.dfg.append_block_param(entry_ebb, ir::types::I64);
Expand Down Expand Up @@ -211,8 +211,8 @@ fn wasm_ty_to_clif(ty: Type) -> ir::types::Type {
}
}

fn generate_trampoline_signature() -> ir::Signature {
let call_convention = super::get_isa(None).default_call_conv();
fn generate_trampoline_signature(isa: &dyn isa::TargetIsa) -> ir::Signature {
let call_convention = isa.default_call_conv();
let mut sig = ir::Signature::new(call_convention);

let ptr_param = ir::AbiParam {
Expand All @@ -227,8 +227,8 @@ fn generate_trampoline_signature() -> ir::Signature {
sig
}

fn generate_export_signature(func_sig: &FuncSig) -> ir::Signature {
let call_convention = super::get_isa(None).default_call_conv();
fn generate_export_signature(isa: &dyn isa::TargetIsa, func_sig: &FuncSig) -> ir::Signature {
let call_convention = isa.default_call_conv();
let mut export_clif_sig = ir::Signature::new(call_convention);

let func_sig_iter = func_sig.params().iter().map(|wasm_ty| ir::AbiParam {
Expand Down
33 changes: 32 additions & 1 deletion lib/runtime-core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl BackendCompilerConfig {
}

/// Configuration data for the compiler
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct CompilerConfig {
/// Symbol information generated from emscripten; used for more detailed debug messages
pub symbol_map: Option<HashMap<u32, String>>,
Expand Down Expand Up @@ -136,6 +136,13 @@ pub struct CompilerConfig {
/// Enabling this makes execution deterministic but increases runtime overhead.
pub nan_canonicalization: bool,

/// Turns on verification that is done by default when `debug_assertions` are enabled
/// (for example in 'debug' builds). Disabling this flag will make compilation faster
/// in debug mode at the cost of not detecting bugs in the compiler.
///
/// These verifications are disabled by default in 'release' builds.
pub enable_verification: bool,

pub features: Features,

// Target info. Presently only supported by LLVM.
Expand All @@ -148,6 +155,30 @@ pub struct CompilerConfig {
pub generate_debug_info: bool,
}

impl Default for CompilerConfig {
fn default() -> Self {
Self {
symbol_map: Default::default(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you use ..Default::default() for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would infinite loop I believe! My understanding of what ..Default::default() does is that it calls default on the type you're constructing and then overrides the fields you specified. Because we're defining default, I don't believe we can use that syntax here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just verified this:

warning: function cannot return without recursing
   --> lib/runtime-core/src/backend.rs:159:5
    |
159 |     fn default() -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
...
178 |             ..Default::default()
    |               ------------------ recursive call site
    |
    = note: `#[warn(unconditional_recursion)]` on by default
    = help: a `loop` may express intention better if this is on purpose

memory_bound_check_mode: Default::default(),
enforce_stack_check: Default::default(),
track_state: Default::default(),
full_preemption: Default::default(),
nan_canonicalization: Default::default(),
features: Default::default(),
triple: Default::default(),
cpu_name: Default::default(),
cpu_features: Default::default(),
backend_specific_config: Default::default(),
generate_debug_info: Default::default(),

// Default verification to 'on' when testing or running in debug mode.
// NOTE: cfg(test) probably does nothing when not running `cargo test`
// on this crate
enable_verification: cfg!(test) || cfg!(debug_assertions),
}
}
}

impl CompilerConfig {
/// Use this to check if we should be generating debug information.
/// This function takes into account the features that runtime-core was
Expand Down
5 changes: 5 additions & 0 deletions lib/spectests/tests/spectest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ mod tests {
threads: true,
},
nan_canonicalization: true,
enable_verification: true,
..Default::default()
};
let module = compile_with_config(&module.into_vec(), config)
Expand Down Expand Up @@ -776,6 +777,7 @@ mod tests {
threads: true,
},
nan_canonicalization: true,
enable_verification: true,
..Default::default()
};
compile_with_config(&module.into_vec(), config)
Expand Down Expand Up @@ -829,6 +831,7 @@ mod tests {
threads: true,
},
nan_canonicalization: true,
enable_verification: true,
..Default::default()
};
compile_with_config(&module.into_vec(), config)
Expand Down Expand Up @@ -881,6 +884,7 @@ mod tests {
threads: true,
},
nan_canonicalization: true,
enable_verification: true,
..Default::default()
};
let module = compile_with_config(&module.into_vec(), config)
Expand Down Expand Up @@ -977,6 +981,7 @@ mod tests {
threads: true,
},
nan_canonicalization: true,
enable_verification: true,
..Default::default()
};
let module = compile_with_config(&module.into_vec(), config)
Expand Down