diff options
author | Davide Italiano <davide@freebsd.org> | 2017-02-13 16:07:05 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-02-13 16:07:05 +0000 |
commit | 945de43dbe2f88d6af10bc440266b01ce1e2b833 (patch) | |
tree | 460eac9c6ce9fd337e923f1cd839a31813fc7ccd /clang/lib/CodeGen/BackendUtil.cpp | |
parent | 509da1a46da008e198ee4ba69ecb3bc004d6beb3 (diff) | |
download | llvm-945de43dbe2f88d6af10bc440266b01ce1e2b833.zip llvm-945de43dbe2f88d6af10bc440266b01ce1e2b833.tar.gz llvm-945de43dbe2f88d6af10bc440266b01ce1e2b833.tar.bz2 |
[PM] Add support for instrumented PGO in the new pass manager (clang-side)
Differential Revision: https://reviews.llvm.org/D29309
llvm-svn: 294961
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 11c8cd0..a1ec52a 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -61,6 +61,9 @@ using namespace llvm; namespace { +// Default filename used for profile generation. +static constexpr StringLiteral DefaultProfileGenName = "default_%m.profraw"; + class EmitAssemblyHelper { DiagnosticsEngine &Diags; const HeaderSearchOptions &HSOpts; @@ -448,7 +451,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, if (!CodeGenOpts.InstrProfileOutput.empty()) PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput; else - PMBuilder.PGOInstrGen = "default_%m.profraw"; + PMBuilder.PGOInstrGen = DefaultProfileGenName; } if (CodeGenOpts.hasProfileIRUse()) PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; @@ -775,7 +778,24 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( return; TheModule->setDataLayout(TM->createDataLayout()); - PassBuilder PB(TM.get()); + PGOOptions PGOOpt; + + // -fprofile-generate. + PGOOpt.RunProfileGen = CodeGenOpts.hasProfileIRInstr(); + if (PGOOpt.RunProfileGen) + PGOOpt.ProfileGenFile = CodeGenOpts.InstrProfileOutput.empty() ? + DefaultProfileGenName : CodeGenOpts.InstrProfileOutput; + + // -fprofile-use. + if (CodeGenOpts.hasProfileIRUse()) + PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; + + // Only pass a PGO options struct if -fprofile-generate or + // -fprofile-use were passed on the cmdline. + PassBuilder PB(TM.get(), + (PGOOpt.RunProfileGen || + !PGOOpt.ProfileUseFile.empty()) ? + Optional<PGOOptions>(PGOOpt) : None); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; |