diff options
| author | David Blaikie <dblaikie@gmail.com> | 2018-01-09 22:03:47 +0000 |
|---|---|---|
| committer | David Blaikie <dblaikie@gmail.com> | 2018-01-09 22:03:47 +0000 |
| commit | 7a4f7f56e5a5d7d70daf6fa50f0e752fbd0b9776 (patch) | |
| tree | 5f2d1a257d9dd1684f8208677a9a516bfff7218a /clang/lib/CodeGen | |
| parent | abdea268c1ff58f159e3aaa59fb7ccc56c316004 (diff) | |
| download | bcm5719-llvm-7a4f7f56e5a5d7d70daf6fa50f0e752fbd0b9776.tar.gz bcm5719-llvm-7a4f7f56e5a5d7d70daf6fa50f0e752fbd0b9776.zip | |
Wire up GCOV to the new pass manager
GCOV in the old pass manager also strips debug info (if debug info is
disabled/only produced for profiling anyway) after the GCOV pass runs.
I think the strip pass hasn't been ported to the new pass manager, so it
might take me a little while to wire that up.
llvm-svn: 322126
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index c4a37dfc8b3..ef974946e1d 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -26,6 +26,7 @@ #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/CodeGen/RegAllocRegistry.h" #include "llvm/CodeGen/SchedulerRegistry.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LegacyPassManager.h" @@ -44,8 +45,8 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/Transforms/Coroutines.h" +#include "llvm/Transforms/GCOVProfiler.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" @@ -471,6 +472,23 @@ static void initTargetOptions(llvm::TargetOptions &Options, Options.MCOptions.IASSearchPaths.push_back( Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path); } +static Optional<GCOVOptions> getGCOVOptions(const CodeGenOptions &CodeGenOpts) { + if (CodeGenOpts.DisableGCov) + return None; + if (!CodeGenOpts.EmitGcovArcs && !CodeGenOpts.EmitGcovNotes) + return None; + // Not using 'GCOVOptions::getDefault' allows us to avoid exiting if + // LLVM's -default-gcov-version flag is set to something invalid. + GCOVOptions Options; + Options.EmitNotes = CodeGenOpts.EmitGcovNotes; + Options.EmitData = CodeGenOpts.EmitGcovArcs; + llvm::copy(CodeGenOpts.CoverageVersion, std::begin(Options.Version)); + Options.UseCfgChecksum = CodeGenOpts.CoverageExtraChecksum; + Options.NoRedZone = CodeGenOpts.DisableRedZone; + Options.FunctionNamesInData = !CodeGenOpts.CoverageNoFunctionNamesInData; + Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody; + return Options; +} void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM) { @@ -613,20 +631,8 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, if (!CodeGenOpts.RewriteMapFiles.empty()) addSymbolRewriterPass(CodeGenOpts, &MPM); - if (!CodeGenOpts.DisableGCov && - (CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes)) { - // Not using 'GCOVOptions::getDefault' allows us to avoid exiting if - // LLVM's -default-gcov-version flag is set to something invalid. - GCOVOptions Options; - Options.EmitNotes = CodeGenOpts.EmitGcovNotes; - Options.EmitData = CodeGenOpts.EmitGcovArcs; - memcpy(Options.Version, CodeGenOpts.CoverageVersion, 4); - Options.UseCfgChecksum = CodeGenOpts.CoverageExtraChecksum; - Options.NoRedZone = CodeGenOpts.DisableRedZone; - Options.FunctionNamesInData = - !CodeGenOpts.CoverageNoFunctionNamesInData; - Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody; - MPM.add(createGCOVProfilerPass(Options)); + if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts)) { + MPM.add(createGCOVProfilerPass(*Options)); if (CodeGenOpts.getDebugInfo() == codegenoptions::NoDebugInfo) MPM.add(createStripSymbolsPass(true)); } @@ -954,6 +960,9 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( 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 |

