Skip to content

Commit 6ba43c9

Browse files
committed
Auto merge of #51230 - nikic:no-verify-lto, r=<try>
Respect -Z no-verify during LTO Currently -Z no-verify only controls IR verification prior to LLVM codegen, while verification is performed unconditionally both before and after linking with (Thin)LTO. Also wondering what the sentiment is on disabling verification by default (and e.g. only enabling it on ALT builds with assertions). This does not seem terribly useful outside of rustc development and it does seem to show up in profiles (at something like 3%).
2 parents cd11054 + 3f18a41 commit 6ba43c9

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@
356356
# Print backtrace on internal compiler errors during bootstrap
357357
#backtrace-on-ice = false
358358

359+
# Whether to verify generated LLVM IR
360+
#verify-llvm-ir = false
361+
359362
# =============================================================================
360363
# Options for specific targets
361364
#

src/bootstrap/bin/rustc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ fn main() {
283283
cmd.arg("--cfg").arg("parallel_queries");
284284
}
285285

286+
if env::var_os("RUSTC_VERIFY_LLVM_IR").is_some() {
287+
cmd.arg("-Z").arg("verify-llvm-ir");
288+
}
289+
286290
let color = match env::var("RUSTC_COLOR") {
287291
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
288292
Err(_) => 0,

src/bootstrap/builder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ impl<'a> Builder<'a> {
898898
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
899899
}
900900

901+
if self.config.rust_verify_llvm_ir {
902+
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
903+
}
904+
901905
cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));
902906

903907
// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct Config {
105105
pub rust_dist_src: bool,
106106
pub rust_codegen_backends: Vec<Interned<String>>,
107107
pub rust_codegen_backends_dir: String,
108+
pub rust_verify_llvm_ir: bool,
108109

109110
pub build: Interned<String>,
110111
pub hosts: Vec<Interned<String>>,
@@ -311,6 +312,7 @@ struct Rust {
311312
lld: Option<bool>,
312313
deny_warnings: Option<bool>,
313314
backtrace_on_ice: Option<bool>,
315+
verify_llvm_ir: Option<bool>,
314316
}
315317

316318
/// TOML representation of how each build target is configured.
@@ -542,6 +544,7 @@ impl Config {
542544
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
543545
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
544546
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
547+
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
545548

546549
if let Some(ref backends) = rust.codegen_backends {
547550
config.rust_codegen_backends = backends.iter()

src/librustc/session/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11521152
"gather codegen statistics"),
11531153
asm_comments: bool = (false, parse_bool, [TRACKED],
11541154
"generate comments into the assembly (may change behavior)"),
1155-
no_verify: bool = (false, parse_bool, [TRACKED],
1156-
"skip LLVM verification"),
1155+
verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
1156+
"verify LLVM IR"),
11571157
borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
11581158
"gather borrowck statistics"),
11591159
no_landing_pads: bool = (false, parse_bool, [TRACKED],
@@ -3097,7 +3097,7 @@ mod tests {
30973097
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
30983098

30993099
opts = reference.clone();
3100-
opts.debugging_opts.no_verify = true;
3100+
opts.debugging_opts.verify_llvm_ir = true;
31013101
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
31023102

31033103
opts = reference.clone();

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ impl Session {
513513
pub fn asm_comments(&self) -> bool {
514514
self.opts.debugging_opts.asm_comments
515515
}
516-
pub fn no_verify(&self) -> bool {
517-
self.opts.debugging_opts.no_verify
516+
pub fn verify_llvm_ir(&self) -> bool {
517+
self.opts.debugging_opts.verify_llvm_ir
518518
}
519519
pub fn borrowck_stats(&self) -> bool {
520520
self.opts.debugging_opts.borrowck_stats

src/librustc_codegen_llvm/back/lto.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,12 @@ fn run_pass_manager(cgcx: &CodegenContext,
461461
unsafe {
462462
let pm = llvm::LLVMCreatePassManager();
463463
llvm::LLVMRustAddAnalysisPasses(tm, pm, llmod);
464-
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
465-
assert!(!pass.is_null());
466-
llvm::LLVMRustAddPass(pm, pass);
464+
465+
if config.verify_llvm_ir {
466+
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
467+
assert!(!pass.is_null());
468+
llvm::LLVMRustAddPass(pm, pass);
469+
}
467470

468471
// When optimizing for LTO we don't actually pass in `-O0`, but we force
469472
// it to always happen at least with `-O1`.
@@ -494,9 +497,11 @@ fn run_pass_manager(cgcx: &CodegenContext,
494497
}
495498
});
496499

497-
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
498-
assert!(!pass.is_null());
499-
llvm::LLVMRustAddPass(pm, pass);
500+
if config.verify_llvm_ir {
501+
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
502+
assert!(!pass.is_null());
503+
llvm::LLVMRustAddPass(pm, pass);
504+
}
500505

501506
time_ext(cgcx.time_passes, None, "LTO passes", ||
502507
llvm::LLVMRunPassManager(pm, llmod));

src/librustc_codegen_llvm/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub struct ModuleConfig {
232232
emit_obj: bool,
233233
// Miscellaneous flags. These are mostly copied from command-line
234234
// options.
235-
no_verify: bool,
235+
pub verify_llvm_ir: bool,
236236
no_prepopulate_passes: bool,
237237
no_builtins: bool,
238238
time_passes: bool,
@@ -271,7 +271,7 @@ impl ModuleConfig {
271271
embed_bitcode_marker: false,
272272
no_integrated_as: false,
273273

274-
no_verify: false,
274+
verify_llvm_ir: false,
275275
no_prepopulate_passes: false,
276276
no_builtins: false,
277277
time_passes: false,
@@ -283,7 +283,7 @@ impl ModuleConfig {
283283
}
284284

285285
fn set_flags(&mut self, sess: &Session, no_builtins: bool) {
286-
self.no_verify = sess.no_verify();
286+
self.verify_llvm_ir = sess.verify_llvm_ir();
287287
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
288288
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
289289
self.time_passes = sess.time_passes();
@@ -542,7 +542,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
542542
true
543543
};
544544

545-
if !config.no_verify { assert!(addpass("verify")); }
545+
if config.verify_llvm_ir { assert!(addpass("verify")); }
546546
if !config.no_prepopulate_passes {
547547
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
548548
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);

0 commit comments

Comments
 (0)