Skip to content

Commit

Permalink
[PM] Add support for instrumented PGO in the new pass manager (clang-…
Browse files Browse the repository at this point in the history
…side)

Differential Revision:  https://reviews.llvm.org/D29309

llvm-svn: 294961
  • Loading branch information
dcci committed Feb 13, 2017
1 parent 509da1a commit 945de43
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 945de43

Please sign in to comment.