Auto merge of #83666 - Amanieu:instrprof-order, r=tmandry

Run LLVM coverage instrumentation passes before optimization passes

This matches the behavior of Clang and allows us to remove several
hacks which were needed to ensure functions weren't optimized away
before reaching the instrumentation pass.

Fixes #83429

cc `@richkadel`

r? `@tmandry`
This commit is contained in:
bors 2021-03-31 03:20:33 +00:00
commit 6ff482bde5
9 changed files with 29 additions and 60 deletions

View file

@ -548,6 +548,15 @@ pub(crate) unsafe fn optimize(
llvm::LLVMRustAddPass(fpm, find_pass("lint").unwrap());
continue;
}
if pass_name == "insert-gcov-profiling" || pass_name == "instrprof" {
// Instrumentation must be inserted before optimization,
// otherwise LLVM may optimize some functions away which
// breaks llvm-cov.
//
// This mirrors what Clang does in lib/CodeGen/BackendUtil.cpp.
llvm::LLVMRustAddPass(mpm, find_pass(pass_name).unwrap());
continue;
}
if let Some(pass) = find_pass(pass_name) {
extra_passes.push(pass);