Author: dblaikie Date: Mon Jan 22 17:25:24 2018 New Revision: 323167 URL: http://llvm.org/viewvc/llvm-project?rev=323167&view=rev Log: 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. Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/test/CodeGen/code-coverage.c Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=323167&r1=323166&r2=323167&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Jan 22 17:25:24 2018 @@ -909,6 +909,9 @@ void EmitAssemblyHelper::EmitAssemblyWit 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 @@ void EmitAssemblyHelper::EmitAssemblyWit [](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 @@ void EmitAssemblyHelper::EmitAssemblyWit 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 Modified: cfe/trunk/test/CodeGen/code-coverage.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/code-coverage.c?rev=323167&r1=323166&r2=323167&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/code-coverage.c (original) +++ cfe/trunk/test/CodeGen/code-coverage.c Mon Jan 22 17:25:24 2018 @@ -3,9 +3,15 @@ // RUN: %clang_cc1 -emit-llvm -disable-red-zone -femit-coverage-data -coverage-notes-file=aaa.gcno -coverage-data-file=bbb.gcda -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 %s -o - | FileCheck %s --check-prefix GCOV_FILE_INFO // RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -femit-coverage-data %s 2>&1 | FileCheck --check-prefix=NEWPM %s +// RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -femit-coverage-data -O3 %s 2>&1 | FileCheck --check-prefix=NEWPM-O3 %s +// NEWPM-NOT: Running pass // NEWPM: Running pass: GCOVProfilerPass +// NEWPM-O3-NOT: Running pass +// NEWPM-O3: Running pass: ForceFunctionAttrsPass +// NEWPM-O3: Running pass: GCOVProfilerPass + int test1(int a) { switch (a % 2) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits