NewPM: Improve/fix GCOV - which needs to run early in the pass pipeline.
Using a new extension point in the new PM, register GCOV at the start of
the pipeline rather than the end.
llvm-svn: 323167
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index c755723..6d42aac 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -909,6 +909,9 @@
bool IsLTO = CodeGenOpts.PrepareForLTO;
if (CodeGenOpts.OptimizationLevel == 0) {
+ if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
+ MPM.addPass(GCOVProfilerPass(*Options));
+
// Build a minimal pipeline based on the semantics required by Clang,
// which is just that always inlining occurs.
MPM.addPass(AlwaysInlinerPass());
@@ -932,6 +935,10 @@
[](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
FPM.addPass(BoundsCheckingPass());
});
+ if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
+ PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
+ MPM.addPass(GCOVProfilerPass(*Options));
+ });
if (IsThinLTO) {
MPM = PB.buildThinLTOPreLinkDefaultPipeline(
@@ -945,9 +952,6 @@
CodeGenOpts.DebugPassManager);
}
}
- if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts)) {
- MPM.addPass(GCOVProfilerPass(*Options));
- }
}
// FIXME: We still use the legacy pass manager to do code generation. We