summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/LLVMBuild.txt2
-rw-r--r--llvm/lib/Transforms/IPO/PassManagerBuilder.cpp29
2 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/LLVMBuild.txt b/llvm/lib/Transforms/IPO/LLVMBuild.txt
index b5410f5f775..bc3df98d504 100644
--- a/llvm/lib/Transforms/IPO/LLVMBuild.txt
+++ b/llvm/lib/Transforms/IPO/LLVMBuild.txt
@@ -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
diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
index b5b948b3001..9d4fa68c67c 100644
--- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -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::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.
@@ -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;
@@ -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
OpenPOWER on IntegriCloud