diff options
author | Xinliang David Li <davidxl@google.com> | 2016-05-10 21:59:52 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-05-10 21:59:52 +0000 |
commit | da1955835d7e9ac5c85ab1cead49d866bcc5c2e2 (patch) | |
tree | 6f9fadad5db624c24d0b97dea83286cd00ae9d8e /llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | |
parent | 2ef275d3423e84655608c91a193351c4c6b0593d (diff) | |
download | llvm-da1955835d7e9ac5c85ab1cead49d866bcc5c2e2.zip llvm-da1955835d7e9ac5c85ab1cead49d866bcc5c2e2.tar.gz llvm-da1955835d7e9ac5c85ab1cead49d866bcc5c2e2.tar.bz2 |
[PM]: port IR based profUse pass to new pass manager
llvm-svn: 269129
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index ef49684..e5e798b 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -151,13 +151,9 @@ public: } private: - bool annotateAllFunctions( - Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI, - function_ref<BlockFrequencyInfo *(Function &)> LookupBFI); std::string ProfileFileName; - std::unique_ptr<IndexedInstrProfReader> PGOReader; - bool runOnModule(Module &M) override; + bool runOnModule(Module &M) override; void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<BlockFrequencyInfoWrapperPass>(); } @@ -835,8 +831,9 @@ static void setPGOCountOnFunc(PGOUseFunc &Func, } } -bool PGOInstrumentationUseLegacyPass::annotateAllFunctions( - Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI, +static bool annotateAllFunctions( + Module &M, StringRef ProfileFileName, + function_ref<BranchProbabilityInfo *(Function &)> LookupBPI, function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) { DEBUG(dbgs() << "Read in profile counters: "); auto &Ctx = M.getContext(); @@ -848,10 +845,11 @@ bool PGOInstrumentationUseLegacyPass::annotateAllFunctions( return false; } - PGOReader = std::move(ReaderOrErr.get()); + std::unique_ptr<IndexedInstrProfReader> PGOReader = + std::move(ReaderOrErr.get()); if (!PGOReader) { Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(), - "Cannot get PGOReader")); + StringRef("Cannot get PGOReader"))); return false; } // TODO: might need to change the warning once the clang option is finalized. @@ -891,6 +889,30 @@ bool PGOInstrumentationUseLegacyPass::annotateAllFunctions( return true; } +PGOInstrumentationUse::PGOInstrumentationUse(std::string Filename) + : ProfileFileName(Filename) { + if (!PGOTestProfileFile.empty()) + ProfileFileName = PGOTestProfileFile; +} + +PreservedAnalyses PGOInstrumentationUse::run(Module &M, + AnalysisManager<Module> &AM) { + + auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); + auto LookupBPI = [&FAM](Function &F) { + return &FAM.getResult<BranchProbabilityAnalysis>(F); + }; + + auto LookupBFI = [&FAM](Function &F) { + return &FAM.getResult<BlockFrequencyAnalysis>(F); + }; + + if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI)) + return PreservedAnalyses::all(); + + return PreservedAnalyses::none(); +} + bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) { if (skipModule(M)) return false; @@ -902,5 +924,5 @@ bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) { return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI(); }; - return annotateAllFunctions(M, LookupBPI, LookupBFI); + return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI); } |