Skip to content

Commit 1cc1079

Browse files
committed
Remove enable_verifier from BackendConfig
1 parent ebacaee commit 1cc1079

File tree

5 files changed

+29
-64
lines changed

5 files changed

+29
-64
lines changed

src/base.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use rustc_middle::ty::adjustment::PointerCoercion;
1414
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
1616

17-
use crate::BackendConfig;
1817
use crate::constant::ConstantCx;
1918
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
19+
use crate::enable_verifier;
2020
use crate::inline_asm::codegen_naked_asm;
2121
use crate::prelude::*;
2222
use crate::pretty_clif::CommentWriter;
@@ -31,7 +31,6 @@ pub(crate) struct CodegenedFunction {
3131

3232
pub(crate) fn codegen_fn<'tcx>(
3333
tcx: TyCtxt<'tcx>,
34-
backend_config: &BackendConfig,
3534
cx: &mut crate::CodegenCx,
3635
type_dbg: &mut TypeDebugContext<'tcx>,
3736
cached_func: Function,
@@ -164,7 +163,7 @@ pub(crate) fn codegen_fn<'tcx>(
164163
}
165164

166165
// Verify function
167-
verify_func(tcx, backend_config, &clif_comments, &func);
166+
verify_func(tcx, &clif_comments, &func);
168167

169168
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
170169
}
@@ -266,13 +265,8 @@ pub(crate) fn compile_fn(
266265
});
267266
}
268267

269-
fn verify_func(
270-
tcx: TyCtxt<'_>,
271-
backend_config: &BackendConfig,
272-
writer: &crate::pretty_clif::CommentWriter,
273-
func: &Function,
274-
) {
275-
if !tcx.sess.verify_llvm_ir() && !backend_config.enable_verifier {
268+
fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
269+
if !enable_verifier(tcx.sess) {
276270
return;
277271
}
278272

src/config.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ pub struct BackendConfig {
4242
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
4343
pub jit_args: Vec<String>,
4444

45-
/// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
46-
/// once before passing the clif ir to Cranelift for compilation.
47-
///
48-
/// Defaults to true when the `CG_CLIF_ENABLE_VERIFIER` env var is set to 1 or when cg_clif is
49-
/// compiled with debug assertions enabled or false otherwise. Can be set using
50-
/// `-Cllvm-args=enable_verifier=...`.
51-
pub enable_verifier: bool,
52-
5345
/// Don't cache object files in the incremental cache. Useful during development of cg_clif
5446
/// to make it possible to use incremental mode for all analyses performed by rustc without
5547
/// caching object files when their content should have been changed by a change to cg_clif.
@@ -72,7 +64,6 @@ impl Default for BackendConfig {
7264
}
7365
}
7466
},
75-
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
7667
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
7768
}
7869
}
@@ -95,7 +86,6 @@ impl BackendConfig {
9586
if let Some((name, value)) = opt.split_once('=') {
9687
match name {
9788
"mode" => config.codegen_mode = value.parse()?,
98-
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
9989
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
10090
_ => return Err(format!("Unknown option `{}`", name)),
10191
}

src/driver/aot.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,8 @@ fn produce_final_output_artifacts(
322322
// These are used in linking steps and will be cleaned up afterward.
323323
}
324324

325-
fn make_module(
326-
sess: &Session,
327-
backend_config: &BackendConfig,
328-
name: String,
329-
) -> UnwindModule<ObjectModule> {
330-
let isa = crate::build_isa(sess, backend_config);
325+
fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
326+
let isa = crate::build_isa(sess);
331327

332328
let mut builder =
333329
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
@@ -488,8 +484,7 @@ fn reuse_workproduct_for_cgu(
488484

489485
fn module_codegen(
490486
tcx: TyCtxt<'_>,
491-
(backend_config, global_asm_config, cgu_name, token): (
492-
BackendConfig,
487+
(global_asm_config, cgu_name, token): (
493488
Arc<GlobalAsmConfig>,
494489
rustc_span::Symbol,
495490
ConcurrencyLimiterToken,
@@ -500,7 +495,7 @@ fn module_codegen(
500495
let cgu = tcx.codegen_unit(cgu_name);
501496
let mono_items = cgu.items_in_deterministic_order(tcx);
502497

503-
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
498+
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
504499

505500
let mut cx = crate::CodegenCx::new(
506501
tcx,
@@ -516,7 +511,6 @@ fn module_codegen(
516511
MonoItem::Fn(inst) => {
517512
if let Some(codegened_function) = crate::base::codegen_fn(
518513
tcx,
519-
&backend_config,
520514
&mut cx,
521515
&mut type_dbg,
522516
Function::new(),
@@ -648,12 +642,7 @@ pub(crate) fn run_aot(
648642
.with_task(
649643
dep_node,
650644
tcx,
651-
(
652-
backend_config.clone(),
653-
global_asm_config.clone(),
654-
cgu.name(),
655-
concurrency_limiter.acquire(tcx.dcx()),
656-
),
645+
(global_asm_config.clone(), cgu.name(), concurrency_limiter.acquire(tcx.dcx())),
657646
module_codegen,
658647
Some(rustc_middle::dep_graph::hash_result),
659648
)
@@ -667,7 +656,7 @@ pub(crate) fn run_aot(
667656
modules
668657
});
669658

670-
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
659+
let mut allocator_module = make_module(tcx.sess, "allocator_shim".to_string());
671660
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
672661

673662
let allocator_module = if created_alloc_shim {

src/driver/jit.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::{BackendConfig, CodegenCx, CodegenMode};
2020

2121
struct JitState {
2222
jit_module: UnwindModule<JITModule>,
23-
backend_config: BackendConfig,
2423
}
2524

2625
thread_local! {
@@ -60,14 +59,10 @@ impl UnsafeMessage {
6059
}
6160
}
6261

63-
fn create_jit_module(
64-
tcx: TyCtxt<'_>,
65-
backend_config: &BackendConfig,
66-
hotswap: bool,
67-
) -> (UnwindModule<JITModule>, CodegenCx) {
62+
fn create_jit_module(tcx: TyCtxt<'_>, hotswap: bool) -> (UnwindModule<JITModule>, CodegenCx) {
6863
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
6964

70-
let isa = crate::build_isa(tcx.sess, backend_config);
65+
let isa = crate::build_isa(tcx.sess);
7166
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
7267
jit_builder.hotswap(hotswap);
7368
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
@@ -91,11 +86,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
9186
tcx.dcx().fatal("can't jit non-executable crate");
9287
}
9388

94-
let (mut jit_module, mut cx) = create_jit_module(
95-
tcx,
96-
&backend_config,
97-
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
98-
);
89+
let (mut jit_module, mut cx) =
90+
create_jit_module(tcx, matches!(backend_config.codegen_mode, CodegenMode::JitLazy));
9991
let mut cached_context = Context::new();
10092

10193
let (_, cgus) = tcx.collect_and_partition_mono_items(());
@@ -116,7 +108,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
116108
CodegenMode::Jit => {
117109
codegen_and_compile_fn(
118110
tcx,
119-
&backend_config,
120111
&mut cx,
121112
&mut cached_context,
122113
&mut jit_module,
@@ -171,7 +162,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
171162
LAZY_JIT_STATE.with(|lazy_jit_state| {
172163
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
173164
assert!(lazy_jit_state.is_none());
174-
*lazy_jit_state = Some(JitState { jit_module, backend_config });
165+
*lazy_jit_state = Some(JitState { jit_module });
175166
});
176167

177168
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) -> ! {
207198

208199
pub(crate) fn codegen_and_compile_fn<'tcx>(
209200
tcx: TyCtxt<'tcx>,
210-
backend_config: &BackendConfig,
211201
cx: &mut crate::CodegenCx,
212202
cached_context: &mut Context,
213203
module: &mut dyn Module,
@@ -224,7 +214,6 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
224214
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
225215
if let Some(codegened_func) = crate::base::codegen_fn(
226216
tcx,
227-
&backend_config,
228217
cx,
229218
&mut TypeDebugContext::default(),
230219
cached_func,
@@ -286,14 +275,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
286275
false,
287276
Symbol::intern("dummy_cgu_name"),
288277
);
289-
codegen_and_compile_fn(
290-
tcx,
291-
&lazy_jit_state.backend_config,
292-
&mut cx,
293-
&mut Context::new(),
294-
jit_module,
295-
instance,
296-
);
278+
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
297279

298280
assert!(cx.global_asm.is_empty());
299281
jit_module.finalize_definitions();

src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern crate rustc_driver;
3535

3636
use std::any::Any;
3737
use std::cell::{Cell, RefCell};
38+
use std::env;
3839
use std::sync::Arc;
3940

4041
use cranelift_codegen::isa::TargetIsa;
@@ -249,6 +250,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
249250
}
250251
}
251252

253+
/// Determine if the Cranelift ir verifier should run.
254+
///
255+
/// Returns true when `-Zverify-llvm-ir` is passed, the `CG_CLIF_ENABLE_VERIFIER` env var is set to
256+
/// 1 or when cg_clif is compiled with debug assertions enabled or false otherwise.
257+
fn enable_verifier(sess: &Session) -> bool {
258+
sess.verify_llvm_ir()
259+
|| cfg!(debug_assertions)
260+
|| env::var("CG_CLIF_ENABLE_VERIFIER").as_deref() == Ok("1")
261+
}
262+
252263
fn target_triple(sess: &Session) -> target_lexicon::Triple {
253264
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
254265
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
@@ -258,15 +269,14 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
258269
}
259270
}
260271

261-
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIsa + 'static> {
272+
fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
262273
use target_lexicon::BinaryFormat;
263274

264275
let target_triple = crate::target_triple(sess);
265276

266277
let mut flags_builder = settings::builder();
267278
flags_builder.enable("is_pic").unwrap();
268-
let enable_verifier =
269-
if sess.verify_llvm_ir() || backend_config.enable_verifier { "true" } else { "false" };
279+
let enable_verifier = if enable_verifier(sess) { "true" } else { "false" };
270280
flags_builder.set("enable_verifier", enable_verifier).unwrap();
271281
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
272282

0 commit comments

Comments
 (0)