diff options
author | Xinliang David Li <davidxl@google.com> | 2016-05-06 05:49:19 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-05-06 05:49:19 +0000 |
commit | 8aebf44c97dba742cda0728ae7a26d641c296b77 (patch) | |
tree | 60e9a454fb54870313caa6166433d469db0adeb8 /llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | |
parent | 7946c3f0e2a2cf90e4ff433a408aa35112c5d98d (diff) | |
download | llvm-8aebf44c97dba742cda0728ae7a26d641c296b77.zip llvm-8aebf44c97dba742cda0728ae7a26d641c296b77.tar.gz llvm-8aebf44c97dba742cda0728ae7a26d641c296b77.tar.bz2 |
[PM] port IR based PGO prof-gen pass to new pass manager
llvm-svn: 268710
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 4c4bc5e..500d08d 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -48,6 +48,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/PGOInstrumentation.h" #include "CFGMST.h" #include "IndirectCallSiteVisitor.h" #include "llvm/ADT/STLExtras.h" @@ -71,6 +72,7 @@ #include "llvm/Support/JamCRC.h" #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" +#include <algorithm> #include <string> #include <utility> #include <vector> @@ -110,12 +112,13 @@ static cl::opt<unsigned> MaxNumAnnotations( "call callsite")); namespace { -class PGOInstrumentationGen : public ModulePass { +class PGOInstrumentationGenLegacyPass : public ModulePass { public: static char ID; - PGOInstrumentationGen() : ModulePass(ID) { - initializePGOInstrumentationGenPass(*PassRegistry::getPassRegistry()); + PGOInstrumentationGenLegacyPass() : ModulePass(ID), PGOInstrGen() { + initializePGOInstrumentationGenLegacyPassPass( + *PassRegistry::getPassRegistry()); } const char *getPassName() const override { @@ -123,6 +126,7 @@ public: } private: + PGOInstrumentationGen PGOInstrGen; bool runOnModule(Module &M) override; void getAnalysisUsage(AnalysisUsage &AU) const override { @@ -157,16 +161,16 @@ private: }; } // end anonymous namespace -char PGOInstrumentationGen::ID = 0; -INITIALIZE_PASS_BEGIN(PGOInstrumentationGen, "pgo-instr-gen", +char PGOInstrumentationGenLegacyPass::ID = 0; +INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen", "PGO instrumentation.", false, false) INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass) -INITIALIZE_PASS_END(PGOInstrumentationGen, "pgo-instr-gen", +INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass, "pgo-instr-gen", "PGO instrumentation.", false, false) -ModulePass *llvm::createPGOInstrumentationGenPass() { - return new PGOInstrumentationGen(); +ModulePass *llvm::createPGOInstrumentationGenLegacyPass() { + return new PGOInstrumentationGenLegacyPass(); } char PGOInstrumentationUse::ID = 0; @@ -788,7 +792,7 @@ static bool InstrumentAllFunctions( return true; } -bool PGOInstrumentationGen::runOnModule(Module &M) { +bool PGOInstrumentationGenLegacyPass::runOnModule(Module &M) { if (skipModule(M)) return false; @@ -801,6 +805,24 @@ bool PGOInstrumentationGen::runOnModule(Module &M) { return InstrumentAllFunctions(M, LookupBPI, LookupBFI); } +PreservedAnalyses PGOInstrumentationGen::run(Module &M, + AnalysisManager<Module> &AM) { + + auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); + auto LookupBPI = [&FAM](Function &F) -> BranchProbabilityInfo & { + return FAM.getResult<BranchProbabilityAnalysis>(F); + }; + + auto LookupBFI = [&FAM](Function &F) -> BlockFrequencyInfo & { + return FAM.getResult<BlockFrequencyAnalysis>(F); + }; + + if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI)) + return PreservedAnalyses::all(); + + return PreservedAnalyses::none(); +} + static void setPGOCountOnFunc(PGOUseFunc &Func, IndexedInstrProfReader *PGOReader) { if (Func.readCounters(PGOReader)) { |