From b98b6205003fecfca2d75ebc3a3e173d960a159c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:36:54 +0100 Subject: [PATCH] Disable clif ir verifier by default It's been a while since it last found something outside of development, yet it is rather expensive. It is still enabled when debug assertions are enabled for cg_clif or when -Z verify-llvm-ir=yes is passed. --- src/base.rs | 11 +++++++++-- src/driver/aot.rs | 1 + src/driver/jit.rs | 15 +++++++++++++-- src/lib.rs | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index da3818ca2..922c9c412 100644 --- a/src/base.rs +++ b/src/base.rs @@ -14,6 +14,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; +use crate::BackendConfig; use crate::constant::ConstantCx; use crate::debuginfo::{FunctionDebugContext, TypeDebugContext}; use crate::inline_asm::codegen_naked_asm; @@ -30,6 +31,7 @@ pub(crate) struct CodegenedFunction { pub(crate) fn codegen_fn<'tcx>( tcx: TyCtxt<'tcx>, + backend_config: &BackendConfig, cx: &mut crate::CodegenCx, type_dbg: &mut TypeDebugContext<'tcx>, cached_func: Function, @@ -162,7 +164,7 @@ pub(crate) fn codegen_fn<'tcx>( } // Verify function - verify_func(tcx, &clif_comments, &func); + verify_func(tcx, backend_config, &clif_comments, &func); Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }) } @@ -264,11 +266,16 @@ pub(crate) fn compile_fn( }); } -pub(crate) fn verify_func( +fn verify_func( tcx: TyCtxt<'_>, + backend_config: &BackendConfig, writer: &crate::pretty_clif::CommentWriter, func: &Function, ) { + if !tcx.sess.verify_llvm_ir() && !backend_config.enable_verifier { + return; + } + tcx.prof.generic_activity("verify clif ir").run(|| { let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder()); match cranelift_codegen::verify_function(&func, &flags) { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 8eab73ad5..2baa0f7f6 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -516,6 +516,7 @@ fn module_codegen( MonoItem::Fn(inst) => { if let Some(codegened_function) = crate::base::codegen_fn( tcx, + &backend_config, &mut cx, &mut type_dbg, Function::new(), diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 0d62a13b4..1ec4d6b55 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -20,6 +20,7 @@ use crate::{BackendConfig, CodegenCx, CodegenMode}; struct JitState { jit_module: UnwindModule, + backend_config: BackendConfig, } thread_local! { @@ -115,6 +116,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { CodegenMode::Jit => { codegen_and_compile_fn( tcx, + &backend_config, &mut cx, &mut cached_context, &mut jit_module, @@ -169,7 +171,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { LAZY_JIT_STATE.with(|lazy_jit_state| { let mut lazy_jit_state = lazy_jit_state.borrow_mut(); assert!(lazy_jit_state.is_none()); - *lazy_jit_state = Some(JitState { jit_module }); + *lazy_jit_state = Some(JitState { jit_module, backend_config }); }); let f: extern "C" fn(c_int, *const *const c_char) -> c_int = @@ -205,6 +207,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { pub(crate) fn codegen_and_compile_fn<'tcx>( tcx: TyCtxt<'tcx>, + backend_config: &BackendConfig, cx: &mut crate::CodegenCx, cached_context: &mut Context, module: &mut dyn Module, @@ -221,6 +224,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>( let cached_func = std::mem::replace(&mut cached_context.func, Function::new()); if let Some(codegened_func) = crate::base::codegen_fn( tcx, + &backend_config, cx, &mut TypeDebugContext::default(), cached_func, @@ -282,7 +286,14 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> false, Symbol::intern("dummy_cgu_name"), ); - codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance); + codegen_and_compile_fn( + tcx, + &lazy_jit_state.backend_config, + &mut cx, + &mut Context::new(), + jit_module, + instance, + ); assert!(cx.global_asm.is_empty()); jit_module.finalize_definitions(); diff --git a/src/lib.rs b/src/lib.rs index 19a1de53d..e201a43bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,7 +278,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc