Skip to content

Commit

Permalink
[PGO] Passmanagerbuilder change that enable IR level PGO instrumentation
Browse files Browse the repository at this point in the history
This patch includes the passmanagerbuilder change that enables IR level PGO instrumentation. It adds two passmanagerbuilder options: -profile-generate=<profile_filename> and -profile-use=<profile_filename>. The new options are primarily for debug purpose.

Reviewers: davidxl, silvas

Differential Revision: http://reviews.llvm.org/D15828

llvm-svn: 258420
  • Loading branch information
xur-llvm committed Jan 21, 2016
1 parent af76110 commit 34abbfb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
Expand Up @@ -133,6 +133,11 @@ class PassManagerBuilder {
bool MergeFunctions;
bool PrepareForLTO;

/// Profile data file name that the instrumentation will be written to.
std::string PGOInstrGen;
/// Path of the profile data file.
std::string PGOInstrUse;

private:
/// ExtensionList - This is list of all of the extensions that are registered.
std::vector<std::pair<ExtensionPointTy, ExtensionFn> > Extensions;
Expand All @@ -152,6 +157,7 @@ class PassManagerBuilder {
void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
void addPGOInstrPasses(legacy::PassManagerBase &MPM);

public:
/// populateFunctionPassManager - This fills in the function pass manager,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/LLVMBuild.txt
Expand Up @@ -20,4 +20,4 @@ type = Library
name = IPO
parent = Transforms
library_name = ipo
required_libraries = Analysis Core InstCombine IRReader Linker Object ProfileData Scalar Support TransformUtils Vectorize
required_libraries = Analysis Core InstCombine IRReader Linker Object ProfileData Scalar Support TransformUtils Vectorize Instrumentation
29 changes: 29 additions & 0 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Expand Up @@ -34,6 +34,7 @@
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Vectorize.h"
#include "llvm/Transforms/Instrumentation.h"

using namespace llvm;

Expand Down Expand Up @@ -105,6 +106,16 @@ static cl::opt<bool> EnableLoopLoadElim(
"enable-loop-load-elim", cl::init(false), cl::Hidden,
cl::desc("Enable the new, experimental LoopLoadElimination Pass"));

static cl::opt<std::string> RunPGOInstrGen(
"profile-generate", cl::init(""), cl::Hidden,
cl::desc("Enable generation phase of PGO instrumentation and specify the "
"path of profile data file"));

static cl::opt<std::string> RunPGOInstrUse(
"profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"),
cl::desc("Enable use phase of PGO instrumentation and specify the path "
"of profile data file"));

PassManagerBuilder::PassManagerBuilder() {
OptLevel = 2;
SizeLevel = 0;
Expand All @@ -123,6 +134,8 @@ PassManagerBuilder::PassManagerBuilder() {
VerifyOutput = false;
MergeFunctions = false;
PrepareForLTO = false;
PGOInstrGen = RunPGOInstrGen;
PGOInstrUse = RunPGOInstrUse;
}

PassManagerBuilder::~PassManagerBuilder() {
Expand Down Expand Up @@ -186,6 +199,19 @@ void PassManagerBuilder::populateFunctionPassManager(
FPM.add(createLowerExpectIntrinsicPass());
}

// Do PGO instrumentation generation or use pass as the option specified.
void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
if (!PGOInstrGen.empty()) {
MPM.add(createPGOInstrumentationGenPass());
// Add the profile lowering pass.
InstrProfOptions Options;
Options.InstrProfileOutput = PGOInstrGen;
MPM.add(createInstrProfilingPass(Options));
}
if (!PGOInstrUse.empty())
MPM.add(createPGOInstrumentationUsePass(PGOInstrUse));
}

void PassManagerBuilder::populateModulePassManager(
legacy::PassManagerBase &MPM) {
// Allow forcing function attributes as a debugging and tuning aid.
Expand All @@ -194,6 +220,7 @@ void PassManagerBuilder::populateModulePassManager(
// If all optimizations are disabled, just run the always-inline pass and,
// if enabled, the function merging pass.
if (OptLevel == 0) {
addPGOInstrPasses(MPM);
if (Inliner) {
MPM.add(Inliner);
Inliner = nullptr;
Expand Down Expand Up @@ -237,6 +264,8 @@ void PassManagerBuilder::populateModulePassManager(
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
}

addPGOInstrPasses(MPM);

if (EnableNonLTOGlobalsModRef)
// We add a module alias analysis pass here. In part due to bugs in the
// analysis infrastructure this "works" in that the analysis stays alive
Expand Down

0 comments on commit 34abbfb

Please sign in to comment.