From 7d59fb4661e02ab28a42348c317d12a223db3cc5 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 24 Mar 2020 14:47:00 -0700 Subject: [PATCH] Add `CompilerConifg` opt to disable IR verification in debug mode --- lib/clif-backend/src/lib.rs | 16 +++++++++++----- lib/clif-backend/src/trampoline.rs | 16 ++++++++-------- lib/runtime-core/src/backend.rs | 6 ++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index c4fb65736c3..02bf479aad7 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -43,16 +43,22 @@ fn get_isa(config: Option<&CompilerConfig>) -> Box { 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.disable_debug_mode_verification; + } else { + // Set defaults if no config found. + enable_verifier = true; + } + + if (cfg!(test) || cfg!(debug_assertions)) && enable_verifier { + builder.set("enable_verifier", "true").unwrap(); + } else { + builder.set("enable_verifier", "false").unwrap(); } let flags = settings::Flags::new(builder); diff --git a/lib/clif-backend/src/trampoline.rs b/lib/clif-backend/src/trampoline.rs index 6b6c5d7ea08..b792f95c285 100644 --- a/lib/clif-backend/src/trampoline.rs +++ b/lib/clif-backend/src/trampoline.rs @@ -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; @@ -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); @@ -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 { @@ -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 { diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index eabe526d8c7..2b0f54c4f0a 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -136,6 +136,12 @@ pub struct CompilerConfig { /// Enabling this makes execution deterministic but increases runtime overhead. pub nan_canonicalization: bool, + /// Turns off verification that is done by default when `debug_assertions` are enabled + /// (for example in 'debug' builds). Enabling this flag will make compilation faster at the + /// cost of not detecting bugs in the compiler. The verification steps that this flag + /// disables are disabled by default in 'release' builds. + pub disable_debug_mode_verification: bool, + pub features: Features, // Target info. Presently only supported by LLVM.