From 5ecbe7fcf8bceb91d43a21be872aaef44c01073a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 5 Apr 2021 10:45:04 +0200 Subject: Explicitly register instrprof pass Don't use "passes" for this purpose, explicitly insert it into the correct place in the pipeline instead. --- compiler/rustc_codegen_llvm/src/back/write.rs | 7 ++++++- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 673f5c3c362..96d24e4f298 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -472,6 +472,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager( sanitizer_options.as_ref(), pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()), pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()), + config.instrument_coverage, llvm_selfprofiler, selfprofile_before_pass_callback, selfprofile_after_pass_callback, @@ -545,7 +546,7 @@ pub(crate) unsafe fn optimize( llvm::LLVMRustAddPass(fpm, find_pass("lint").unwrap()); continue; } - if pass_name == "insert-gcov-profiling" || pass_name == "instrprof" { + if pass_name == "insert-gcov-profiling" { // Instrumentation must be inserted before optimization, // otherwise LLVM may optimize some functions away which // breaks llvm-cov. @@ -566,6 +567,10 @@ pub(crate) unsafe fn optimize( } } + if config.instrument_coverage { + llvm::LLVMRustAddPass(mpm, find_pass("instrprof").unwrap()); + } + add_sanitizer_passes(config, &mut extra_passes); // Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 32b1526f6e4..9a7be031944 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2203,6 +2203,7 @@ extern "C" { SanitizerOptions: Option<&SanitizerOptions>, PGOGenPath: *const c_char, PGOUsePath: *const c_char, + InstrumentCoverage: bool, llvm_selfprofiler: *mut c_void, begin_callback: SelfProfileBeforePassCallback, end_callback: SelfProfileAfterPassCallback, -- cgit 1.4.1-3-g733a5