Explicitly register GCOV profiling pass as well
This commit is contained in:
parent
5ecbe7fcf8
commit
db140de8f2
4 changed files with 30 additions and 23 deletions
|
@ -473,6 +473,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
|
||||||
pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
|
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()),
|
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
|
||||||
config.instrument_coverage,
|
config.instrument_coverage,
|
||||||
|
config.instrument_gcov,
|
||||||
llvm_selfprofiler,
|
llvm_selfprofiler,
|
||||||
selfprofile_before_pass_callback,
|
selfprofile_before_pass_callback,
|
||||||
selfprofile_after_pass_callback,
|
selfprofile_after_pass_callback,
|
||||||
|
@ -546,15 +547,6 @@ pub(crate) unsafe fn optimize(
|
||||||
llvm::LLVMRustAddPass(fpm, find_pass("lint").unwrap());
|
llvm::LLVMRustAddPass(fpm, find_pass("lint").unwrap());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if pass_name == "insert-gcov-profiling" {
|
|
||||||
// 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) {
|
if let Some(pass) = find_pass(pass_name) {
|
||||||
extra_passes.push(pass);
|
extra_passes.push(pass);
|
||||||
|
@ -567,6 +559,14 @@ pub(crate) unsafe fn optimize(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
if config.instrument_gcov {
|
||||||
|
llvm::LLVMRustAddPass(mpm, find_pass("insert-gcov-profiling").unwrap());
|
||||||
|
}
|
||||||
if config.instrument_coverage {
|
if config.instrument_coverage {
|
||||||
llvm::LLVMRustAddPass(mpm, find_pass("instrprof").unwrap());
|
llvm::LLVMRustAddPass(mpm, find_pass("instrprof").unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2204,6 +2204,7 @@ extern "C" {
|
||||||
PGOGenPath: *const c_char,
|
PGOGenPath: *const c_char,
|
||||||
PGOUsePath: *const c_char,
|
PGOUsePath: *const c_char,
|
||||||
InstrumentCoverage: bool,
|
InstrumentCoverage: bool,
|
||||||
|
InstrumentGCOV: bool,
|
||||||
llvm_selfprofiler: *mut c_void,
|
llvm_selfprofiler: *mut c_void,
|
||||||
begin_callback: SelfProfileBeforePassCallback,
|
begin_callback: SelfProfileBeforePassCallback,
|
||||||
end_callback: SelfProfileAfterPassCallback,
|
end_callback: SelfProfileAfterPassCallback,
|
||||||
|
|
|
@ -85,6 +85,7 @@ pub struct ModuleConfig {
|
||||||
pub pgo_gen: SwitchWithOptPath,
|
pub pgo_gen: SwitchWithOptPath,
|
||||||
pub pgo_use: Option<PathBuf>,
|
pub pgo_use: Option<PathBuf>,
|
||||||
pub instrument_coverage: bool,
|
pub instrument_coverage: bool,
|
||||||
|
pub instrument_gcov: bool,
|
||||||
|
|
||||||
pub sanitizer: SanitizerSet,
|
pub sanitizer: SanitizerSet,
|
||||||
pub sanitizer_recover: SanitizerSet,
|
pub sanitizer_recover: SanitizerSet,
|
||||||
|
@ -166,19 +167,7 @@ impl ModuleConfig {
|
||||||
};
|
};
|
||||||
|
|
||||||
ModuleConfig {
|
ModuleConfig {
|
||||||
passes: if_regular!(
|
passes: if_regular!(sess.opts.cg.passes.clone(), vec![]),
|
||||||
{
|
|
||||||
let mut passes = sess.opts.cg.passes.clone();
|
|
||||||
// compiler_builtins overrides the codegen-units settings,
|
|
||||||
// which is incompatible with -Zprofile which requires that
|
|
||||||
// only a single codegen unit is used per crate.
|
|
||||||
if sess.opts.debugging_opts.profile && !is_compiler_builtins {
|
|
||||||
passes.push("insert-gcov-profiling".to_owned());
|
|
||||||
}
|
|
||||||
passes
|
|
||||||
},
|
|
||||||
vec![]
|
|
||||||
),
|
|
||||||
|
|
||||||
opt_level: opt_level_and_size,
|
opt_level: opt_level_and_size,
|
||||||
opt_size: opt_level_and_size,
|
opt_size: opt_level_and_size,
|
||||||
|
@ -189,6 +178,13 @@ impl ModuleConfig {
|
||||||
),
|
),
|
||||||
pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None),
|
pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None),
|
||||||
instrument_coverage: if_regular!(sess.instrument_coverage(), false),
|
instrument_coverage: if_regular!(sess.instrument_coverage(), false),
|
||||||
|
instrument_gcov: if_regular!(
|
||||||
|
// compiler_builtins overrides the codegen-units settings,
|
||||||
|
// which is incompatible with -Zprofile which requires that
|
||||||
|
// only a single codegen unit is used per crate.
|
||||||
|
sess.opts.debugging_opts.profile && !is_compiler_builtins,
|
||||||
|
false
|
||||||
|
),
|
||||||
|
|
||||||
sanitizer: if_regular!(sess.opts.debugging_opts.sanitizer, SanitizerSet::empty()),
|
sanitizer: if_regular!(sess.opts.debugging_opts.sanitizer, SanitizerSet::empty()),
|
||||||
sanitizer_recover: if_regular!(
|
sanitizer_recover: if_regular!(
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
|
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
|
||||||
#include "llvm/Support/TimeProfiler.h"
|
#include "llvm/Support/TimeProfiler.h"
|
||||||
|
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
|
||||||
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
|
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
|
||||||
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
||||||
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
|
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
|
||||||
|
@ -745,7 +746,8 @@ LLVMRustOptimizeWithNewPassManager(
|
||||||
bool MergeFunctions, bool UnrollLoops, bool SLPVectorize, bool LoopVectorize,
|
bool MergeFunctions, bool UnrollLoops, bool SLPVectorize, bool LoopVectorize,
|
||||||
bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers,
|
bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers,
|
||||||
LLVMRustSanitizerOptions *SanitizerOptions,
|
LLVMRustSanitizerOptions *SanitizerOptions,
|
||||||
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
|
const char *PGOGenPath, const char *PGOUsePath,
|
||||||
|
bool InstrumentCoverage, bool InstrumentGCOV,
|
||||||
void* LlvmSelfProfiler,
|
void* LlvmSelfProfiler,
|
||||||
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
|
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
|
||||||
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
|
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
|
||||||
|
@ -835,6 +837,14 @@ LLVMRustOptimizeWithNewPassManager(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (InstrumentGCOV) {
|
||||||
|
PipelineStartEPCallbacks.push_back(
|
||||||
|
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
|
||||||
|
MPM.addPass(GCOVProfilerPass(GCOVOptions::getDefault()));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (InstrumentCoverage) {
|
if (InstrumentCoverage) {
|
||||||
PipelineStartEPCallbacks.push_back(
|
PipelineStartEPCallbacks.push_back(
|
||||||
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
|
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue