diff options
author | Xinliang David Li <davidxl@google.com> | 2016-05-07 05:39:12 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-05-07 05:39:12 +0000 |
commit | d55827f7b2a43d8f79cf54018760d64ee6837875 (patch) | |
tree | a933ca41f732960769d27228a6ff520b31b98dac | |
parent | 2266a8d473256630785f5803bb8de6c7e619ef9d (diff) | |
download | bcm5719-llvm-d55827f7b2a43d8f79cf54018760d64ee6837875.tar.gz bcm5719-llvm-d55827f7b2a43d8f79cf54018760d64ee6837875.zip |
[PM] code refactoring -- preparation for new PM porting /NFC
llvm-svn: 268851
-rw-r--r-- | llvm/include/llvm/InitializePasses.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/LinkAllPasses.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Transforms/Instrumentation.h | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/PassManagerBuilder.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/Instrumentation.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 49 |
6 files changed, 37 insertions, 22 deletions
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 19c7680a9c6..674cbe0f246 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -124,7 +124,7 @@ void initializeExpandPostRAPass(PassRegistry&); void initializeAAResultsWrapperPassPass(PassRegistry &); void initializeGCOVProfilerPass(PassRegistry&); void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&); -void initializePGOInstrumentationUsePass(PassRegistry&); +void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&); void initializePGOIndirectCallPromotionPass(PassRegistry&); void initializeInstrProfilingLegacyPassPass(PassRegistry &); void initializeAddressSanitizerPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 114adf0d107..bc6e0acf3c2 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -90,7 +90,7 @@ namespace { (void) llvm::createDomViewerPass(); (void) llvm::createGCOVProfilerPass(); (void) llvm::createPGOInstrumentationGenLegacyPass(); - (void) llvm::createPGOInstrumentationUsePass(); + (void) llvm::createPGOInstrumentationUseLegacyPass(); (void) llvm::createPGOIndirectCallPromotionPass(); (void) llvm::createInstrProfilingLegacyPass(); (void) llvm::createFunctionImportPass(); diff --git a/llvm/include/llvm/Transforms/Instrumentation.h b/llvm/include/llvm/Transforms/Instrumentation.h index 9b03900dd7b..24e4247e847 100644 --- a/llvm/include/llvm/Transforms/Instrumentation.h +++ b/llvm/include/llvm/Transforms/Instrumentation.h @@ -82,7 +82,7 @@ ModulePass *createGCOVProfilerPass(const GCOVOptions &Options = // PGO Instrumention ModulePass *createPGOInstrumentationGenLegacyPass(); ModulePass * -createPGOInstrumentationUsePass(StringRef Filename = StringRef("")); +createPGOInstrumentationUseLegacyPass(StringRef Filename = StringRef("")); ModulePass *createPGOIndirectCallPromotionPass(bool InLTO = false); /// Options for the frontend instrumentation based profiling pass. diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp index fd10c2bd06e..af2426324ee 100644 --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -219,7 +219,7 @@ void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) { MPM.add(createInstrProfilingLegacyPass(Options)); } if (!PGOInstrUse.empty()) - MPM.add(createPGOInstrumentationUsePass(PGOInstrUse)); + MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse)); } void PassManagerBuilder::addFunctionSimplificationPasses( legacy::PassManagerBase &MPM) { diff --git a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp index 5f47cf831d3..b31aaf319e7 100644 --- a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp @@ -61,7 +61,7 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) { initializeBoundsCheckingPass(Registry); initializeGCOVProfilerPass(Registry); initializePGOInstrumentationGenLegacyPassPass(Registry); - initializePGOInstrumentationUsePass(Registry); + initializePGOInstrumentationUseLegacyPassPass(Registry); initializePGOIndirectCallPromotionPass(Registry); initializeInstrProfilingLegacyPassPass(Registry); initializeMemorySanitizerPass(Registry); diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 500d08d46a0..90bbfa87944 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -134,16 +134,17 @@ private: } }; -class PGOInstrumentationUse : public ModulePass { +class PGOInstrumentationUseLegacyPass : public ModulePass { public: static char ID; // Provide the profile filename as the parameter. - PGOInstrumentationUse(std::string Filename = "") + PGOInstrumentationUseLegacyPass(std::string Filename = "") : ModulePass(ID), ProfileFileName(Filename) { if (!PGOTestProfileFile.empty()) ProfileFileName = PGOTestProfileFile; - initializePGOInstrumentationUsePass(*PassRegistry::getPassRegistry()); + initializePGOInstrumentationUseLegacyPassPass( + *PassRegistry::getPassRegistry()); } const char *getPassName() const override { @@ -151,6 +152,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; @@ -173,16 +177,16 @@ ModulePass *llvm::createPGOInstrumentationGenLegacyPass() { return new PGOInstrumentationGenLegacyPass(); } -char PGOInstrumentationUse::ID = 0; -INITIALIZE_PASS_BEGIN(PGOInstrumentationUse, "pgo-instr-use", +char PGOInstrumentationUseLegacyPass::ID = 0; +INITIALIZE_PASS_BEGIN(PGOInstrumentationUseLegacyPass, "pgo-instr-use", "Read PGO instrumentation profile.", false, false) INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass) -INITIALIZE_PASS_END(PGOInstrumentationUse, "pgo-instr-use", +INITIALIZE_PASS_END(PGOInstrumentationUseLegacyPass, "pgo-instr-use", "Read PGO instrumentation profile.", false, false) -ModulePass *llvm::createPGOInstrumentationUsePass(StringRef Filename) { - return new PGOInstrumentationUse(Filename.str()); +ModulePass *llvm::createPGOInstrumentationUseLegacyPass(StringRef Filename) { + return new PGOInstrumentationUseLegacyPass(Filename.str()); } namespace { @@ -832,10 +836,9 @@ static void setPGOCountOnFunc(PGOUseFunc &Func, } } -bool PGOInstrumentationUse::runOnModule(Module &M) { - if (skipModule(M)) - return false; - +bool PGOInstrumentationUseLegacyPass::annotateAllFunctions( + Module &M, function_ref<BranchProbabilityInfo &(Function &)> LookupBPI, + function_ref<BlockFrequencyInfo &(Function &)> LookupBFI) { DEBUG(dbgs() << "Read in profile counters: "); auto &Ctx = M.getContext(); // Read the counter array from file. @@ -864,11 +867,9 @@ bool PGOInstrumentationUse::runOnModule(Module &M) { for (auto &F : M) { if (F.isDeclaration()) continue; - BranchProbabilityInfo *BPI = - &(getAnalysis<BranchProbabilityInfoWrapperPass>(F).getBPI()); - BlockFrequencyInfo *BFI = - &(getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI()); - PGOUseFunc Func(F, &M, BPI, BFI); + auto &BPI = LookupBPI(F); + auto &BFI = LookupBFI(F); + PGOUseFunc Func(F, &M, &BPI, &BFI); setPGOCountOnFunc(Func, PGOReader.get()); PGOUseFunc::FuncFreqAttr FreqAttr = Func.getFuncFreqAttr(); if (FreqAttr == PGOUseFunc::FFA_Cold) @@ -890,3 +891,17 @@ bool PGOInstrumentationUse::runOnModule(Module &M) { return true; } + +bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) { + if (skipModule(M)) + return false; + + auto LookupBPI = [this](Function &F) -> BranchProbabilityInfo & { + return this->getAnalysis<BranchProbabilityInfoWrapperPass>(F).getBPI(); + }; + auto LookupBFI = [this](Function &F) -> BlockFrequencyInfo & { + return this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI(); + }; + + return annotateAllFunctions(M, LookupBPI, LookupBFI); +} |