[llvm] r258420 - [PGO] Passmanagerbuilder change that enable IR level PGO instrumentation
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 10:29:00 PST 2016
Author: xur
Date: Thu Jan 21 12:28:59 2016
New Revision: 258420
URL: http://llvm.org/viewvc/llvm-project?rev=258420&view=rev
Log:
[PGO] Passmanagerbuilder change that enable IR level PGO instrumentation
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
Modified:
llvm/trunk/include/llvm/Transforms/IPO/PassManagerBuilder.h
llvm/trunk/lib/Transforms/IPO/LLVMBuild.txt
llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
Modified: llvm/trunk/include/llvm/Transforms/IPO/PassManagerBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/PassManagerBuilder.h?rev=258420&r1=258419&r2=258420&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/PassManagerBuilder.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/PassManagerBuilder.h Thu Jan 21 12:28:59 2016
@@ -133,6 +133,11 @@ public:
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;
@@ -152,6 +157,7 @@ private:
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,
Modified: llvm/trunk/lib/Transforms/IPO/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LLVMBuild.txt?rev=258420&r1=258419&r2=258420&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LLVMBuild.txt (original)
+++ llvm/trunk/lib/Transforms/IPO/LLVMBuild.txt Thu Jan 21 12:28:59 2016
@@ -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
Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=258420&r1=258419&r2=258420&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Thu Jan 21 12:28:59 2016
@@ -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;
@@ -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;
@@ -123,6 +134,8 @@ PassManagerBuilder::PassManagerBuilder()
VerifyOutput = false;
MergeFunctions = false;
PrepareForLTO = false;
+ PGOInstrGen = RunPGOInstrGen;
+ PGOInstrUse = RunPGOInstrUse;
}
PassManagerBuilder::~PassManagerBuilder() {
@@ -186,6 +199,19 @@ void PassManagerBuilder::populateFunctio
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.
@@ -194,6 +220,7 @@ void PassManagerBuilder::populateModuleP
// 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;
@@ -237,6 +264,8 @@ void PassManagerBuilder::populateModuleP
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
More information about the llvm-commits
mailing list