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

Disable clif ir verifier by default #1542

Merged
merged 1 commit into from
Nov 12, 2024
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
11 changes: 9 additions & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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 })
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 13 additions & 2 deletions src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{BackendConfig, CodegenCx, CodegenMode};

struct JitState {
jit_module: UnwindModule<JITModule>,
backend_config: BackendConfig,
}

thread_local! {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs

let mut flags_builder = settings::builder();
flags_builder.enable("is_pic").unwrap();
let enable_verifier = if backend_config.enable_verifier { "true" } else { "false" };
let enable_verifier =
if sess.verify_llvm_ir() || backend_config.enable_verifier { "true" } else { "false" };
flags_builder.set("enable_verifier", enable_verifier).unwrap();
flags_builder.set("regalloc_checker", enable_verifier).unwrap();

Expand Down