Remove enable_verifier from BackendConfig
This commit is contained in:
parent
ebacaee16b
commit
1cc10793f3
5 changed files with 29 additions and 64 deletions
14
src/base.rs
14
src/base.rs
|
@ -14,9 +14,9 @@ use rustc_middle::ty::adjustment::PointerCoercion;
|
||||||
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
|
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
|
|
||||||
use crate::BackendConfig;
|
|
||||||
use crate::constant::ConstantCx;
|
use crate::constant::ConstantCx;
|
||||||
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
|
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
|
||||||
|
use crate::enable_verifier;
|
||||||
use crate::inline_asm::codegen_naked_asm;
|
use crate::inline_asm::codegen_naked_asm;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::pretty_clif::CommentWriter;
|
use crate::pretty_clif::CommentWriter;
|
||||||
|
@ -31,7 +31,6 @@ pub(crate) struct CodegenedFunction {
|
||||||
|
|
||||||
pub(crate) fn codegen_fn<'tcx>(
|
pub(crate) fn codegen_fn<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
backend_config: &BackendConfig,
|
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
type_dbg: &mut TypeDebugContext<'tcx>,
|
type_dbg: &mut TypeDebugContext<'tcx>,
|
||||||
cached_func: Function,
|
cached_func: Function,
|
||||||
|
@ -164,7 +163,7 @@ pub(crate) fn codegen_fn<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify function
|
// Verify function
|
||||||
verify_func(tcx, backend_config, &clif_comments, &func);
|
verify_func(tcx, &clif_comments, &func);
|
||||||
|
|
||||||
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
|
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
|
||||||
}
|
}
|
||||||
|
@ -266,13 +265,8 @@ pub(crate) fn compile_fn(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_func(
|
fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
|
||||||
tcx: TyCtxt<'_>,
|
if !enable_verifier(tcx.sess) {
|
||||||
backend_config: &BackendConfig,
|
|
||||||
writer: &crate::pretty_clif::CommentWriter,
|
|
||||||
func: &Function,
|
|
||||||
) {
|
|
||||||
if !tcx.sess.verify_llvm_ir() && !backend_config.enable_verifier {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,6 @@ pub struct BackendConfig {
|
||||||
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
|
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
|
||||||
pub jit_args: Vec<String>,
|
pub jit_args: Vec<String>,
|
||||||
|
|
||||||
/// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
|
|
||||||
/// once before passing the clif ir to Cranelift for compilation.
|
|
||||||
///
|
|
||||||
/// Defaults to true when the `CG_CLIF_ENABLE_VERIFIER` env var is set to 1 or when cg_clif is
|
|
||||||
/// compiled with debug assertions enabled or false otherwise. Can be set using
|
|
||||||
/// `-Cllvm-args=enable_verifier=...`.
|
|
||||||
pub enable_verifier: bool,
|
|
||||||
|
|
||||||
/// Don't cache object files in the incremental cache. Useful during development of cg_clif
|
/// Don't cache object files in the incremental cache. Useful during development of cg_clif
|
||||||
/// to make it possible to use incremental mode for all analyses performed by rustc without
|
/// to make it possible to use incremental mode for all analyses performed by rustc without
|
||||||
/// caching object files when their content should have been changed by a change to cg_clif.
|
/// caching object files when their content should have been changed by a change to cg_clif.
|
||||||
|
@ -72,7 +64,6 @@ impl Default for BackendConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
|
|
||||||
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
|
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +86,6 @@ impl BackendConfig {
|
||||||
if let Some((name, value)) = opt.split_once('=') {
|
if let Some((name, value)) = opt.split_once('=') {
|
||||||
match name {
|
match name {
|
||||||
"mode" => config.codegen_mode = value.parse()?,
|
"mode" => config.codegen_mode = value.parse()?,
|
||||||
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
|
|
||||||
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
|
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
|
||||||
_ => return Err(format!("Unknown option `{}`", name)),
|
_ => return Err(format!("Unknown option `{}`", name)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,12 +322,8 @@ fn produce_final_output_artifacts(
|
||||||
// These are used in linking steps and will be cleaned up afterward.
|
// These are used in linking steps and will be cleaned up afterward.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_module(
|
fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
|
||||||
sess: &Session,
|
let isa = crate::build_isa(sess);
|
||||||
backend_config: &BackendConfig,
|
|
||||||
name: String,
|
|
||||||
) -> UnwindModule<ObjectModule> {
|
|
||||||
let isa = crate::build_isa(sess, backend_config);
|
|
||||||
|
|
||||||
let mut builder =
|
let mut builder =
|
||||||
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
|
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
|
||||||
|
@ -488,8 +484,7 @@ fn reuse_workproduct_for_cgu(
|
||||||
|
|
||||||
fn module_codegen(
|
fn module_codegen(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
(backend_config, global_asm_config, cgu_name, token): (
|
(global_asm_config, cgu_name, token): (
|
||||||
BackendConfig,
|
|
||||||
Arc<GlobalAsmConfig>,
|
Arc<GlobalAsmConfig>,
|
||||||
rustc_span::Symbol,
|
rustc_span::Symbol,
|
||||||
ConcurrencyLimiterToken,
|
ConcurrencyLimiterToken,
|
||||||
|
@ -500,7 +495,7 @@ fn module_codegen(
|
||||||
let cgu = tcx.codegen_unit(cgu_name);
|
let cgu = tcx.codegen_unit(cgu_name);
|
||||||
let mono_items = cgu.items_in_deterministic_order(tcx);
|
let mono_items = cgu.items_in_deterministic_order(tcx);
|
||||||
|
|
||||||
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
|
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
|
||||||
|
|
||||||
let mut cx = crate::CodegenCx::new(
|
let mut cx = crate::CodegenCx::new(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -516,7 +511,6 @@ fn module_codegen(
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
if let Some(codegened_function) = crate::base::codegen_fn(
|
if let Some(codegened_function) = crate::base::codegen_fn(
|
||||||
tcx,
|
tcx,
|
||||||
&backend_config,
|
|
||||||
&mut cx,
|
&mut cx,
|
||||||
&mut type_dbg,
|
&mut type_dbg,
|
||||||
Function::new(),
|
Function::new(),
|
||||||
|
@ -648,12 +642,7 @@ pub(crate) fn run_aot(
|
||||||
.with_task(
|
.with_task(
|
||||||
dep_node,
|
dep_node,
|
||||||
tcx,
|
tcx,
|
||||||
(
|
(global_asm_config.clone(), cgu.name(), concurrency_limiter.acquire(tcx.dcx())),
|
||||||
backend_config.clone(),
|
|
||||||
global_asm_config.clone(),
|
|
||||||
cgu.name(),
|
|
||||||
concurrency_limiter.acquire(tcx.dcx()),
|
|
||||||
),
|
|
||||||
module_codegen,
|
module_codegen,
|
||||||
Some(rustc_middle::dep_graph::hash_result),
|
Some(rustc_middle::dep_graph::hash_result),
|
||||||
)
|
)
|
||||||
|
@ -667,7 +656,7 @@ pub(crate) fn run_aot(
|
||||||
modules
|
modules
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
|
let mut allocator_module = make_module(tcx.sess, "allocator_shim".to_string());
|
||||||
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
|
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
|
||||||
|
|
||||||
let allocator_module = if created_alloc_shim {
|
let allocator_module = if created_alloc_shim {
|
||||||
|
|
|
@ -20,7 +20,6 @@ use crate::{BackendConfig, CodegenCx, CodegenMode};
|
||||||
|
|
||||||
struct JitState {
|
struct JitState {
|
||||||
jit_module: UnwindModule<JITModule>,
|
jit_module: UnwindModule<JITModule>,
|
||||||
backend_config: BackendConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
@ -60,14 +59,10 @@ impl UnsafeMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_jit_module(
|
fn create_jit_module(tcx: TyCtxt<'_>, hotswap: bool) -> (UnwindModule<JITModule>, CodegenCx) {
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
backend_config: &BackendConfig,
|
|
||||||
hotswap: bool,
|
|
||||||
) -> (UnwindModule<JITModule>, CodegenCx) {
|
|
||||||
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
|
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
|
||||||
|
|
||||||
let isa = crate::build_isa(tcx.sess, backend_config);
|
let isa = crate::build_isa(tcx.sess);
|
||||||
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
|
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
|
||||||
jit_builder.hotswap(hotswap);
|
jit_builder.hotswap(hotswap);
|
||||||
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
||||||
|
@ -91,11 +86,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||||
tcx.dcx().fatal("can't jit non-executable crate");
|
tcx.dcx().fatal("can't jit non-executable crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut jit_module, mut cx) = create_jit_module(
|
let (mut jit_module, mut cx) =
|
||||||
tcx,
|
create_jit_module(tcx, matches!(backend_config.codegen_mode, CodegenMode::JitLazy));
|
||||||
&backend_config,
|
|
||||||
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
|
|
||||||
);
|
|
||||||
let mut cached_context = Context::new();
|
let mut cached_context = Context::new();
|
||||||
|
|
||||||
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
||||||
|
@ -116,7 +108,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||||
CodegenMode::Jit => {
|
CodegenMode::Jit => {
|
||||||
codegen_and_compile_fn(
|
codegen_and_compile_fn(
|
||||||
tcx,
|
tcx,
|
||||||
&backend_config,
|
|
||||||
&mut cx,
|
&mut cx,
|
||||||
&mut cached_context,
|
&mut cached_context,
|
||||||
&mut jit_module,
|
&mut jit_module,
|
||||||
|
@ -171,7 +162,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||||
LAZY_JIT_STATE.with(|lazy_jit_state| {
|
LAZY_JIT_STATE.with(|lazy_jit_state| {
|
||||||
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
|
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
|
||||||
assert!(lazy_jit_state.is_none());
|
assert!(lazy_jit_state.is_none());
|
||||||
*lazy_jit_state = Some(JitState { jit_module, backend_config });
|
*lazy_jit_state = Some(JitState { jit_module });
|
||||||
});
|
});
|
||||||
|
|
||||||
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
|
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
|
||||||
|
@ -207,7 +198,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||||
|
|
||||||
pub(crate) fn codegen_and_compile_fn<'tcx>(
|
pub(crate) fn codegen_and_compile_fn<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
backend_config: &BackendConfig,
|
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
cached_context: &mut Context,
|
cached_context: &mut Context,
|
||||||
module: &mut dyn Module,
|
module: &mut dyn Module,
|
||||||
|
@ -224,7 +214,6 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
|
||||||
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
|
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
|
||||||
if let Some(codegened_func) = crate::base::codegen_fn(
|
if let Some(codegened_func) = crate::base::codegen_fn(
|
||||||
tcx,
|
tcx,
|
||||||
&backend_config,
|
|
||||||
cx,
|
cx,
|
||||||
&mut TypeDebugContext::default(),
|
&mut TypeDebugContext::default(),
|
||||||
cached_func,
|
cached_func,
|
||||||
|
@ -286,14 +275,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
|
||||||
false,
|
false,
|
||||||
Symbol::intern("dummy_cgu_name"),
|
Symbol::intern("dummy_cgu_name"),
|
||||||
);
|
);
|
||||||
codegen_and_compile_fn(
|
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
|
||||||
tcx,
|
|
||||||
&lazy_jit_state.backend_config,
|
|
||||||
&mut cx,
|
|
||||||
&mut Context::new(),
|
|
||||||
jit_module,
|
|
||||||
instance,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(cx.global_asm.is_empty());
|
assert!(cx.global_asm.is_empty());
|
||||||
jit_module.finalize_definitions();
|
jit_module.finalize_definitions();
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -35,6 +35,7 @@ extern crate rustc_driver;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
|
@ -249,6 +250,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determine if the Cranelift ir verifier should run.
|
||||||
|
///
|
||||||
|
/// Returns true when `-Zverify-llvm-ir` is passed, the `CG_CLIF_ENABLE_VERIFIER` env var is set to
|
||||||
|
/// 1 or when cg_clif is compiled with debug assertions enabled or false otherwise.
|
||||||
|
fn enable_verifier(sess: &Session) -> bool {
|
||||||
|
sess.verify_llvm_ir()
|
||||||
|
|| cfg!(debug_assertions)
|
||||||
|
|| env::var("CG_CLIF_ENABLE_VERIFIER").as_deref() == Ok("1")
|
||||||
|
}
|
||||||
|
|
||||||
fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
||||||
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
|
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
|
||||||
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
|
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
|
||||||
|
@ -258,15 +269,14 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIsa + 'static> {
|
fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
|
||||||
use target_lexicon::BinaryFormat;
|
use target_lexicon::BinaryFormat;
|
||||||
|
|
||||||
let target_triple = crate::target_triple(sess);
|
let target_triple = crate::target_triple(sess);
|
||||||
|
|
||||||
let mut flags_builder = settings::builder();
|
let mut flags_builder = settings::builder();
|
||||||
flags_builder.enable("is_pic").unwrap();
|
flags_builder.enable("is_pic").unwrap();
|
||||||
let enable_verifier =
|
let enable_verifier = if enable_verifier(sess) { "true" } else { "false" };
|
||||||
if sess.verify_llvm_ir() || backend_config.enable_verifier { "true" } else { "false" };
|
|
||||||
flags_builder.set("enable_verifier", enable_verifier).unwrap();
|
flags_builder.set("enable_verifier", enable_verifier).unwrap();
|
||||||
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
|
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue