diff options
| author | Dehao Chen <dehao@google.com> | 2017-10-01 05:24:51 +0000 |
|---|---|---|
| committer | Dehao Chen <dehao@google.com> | 2017-10-01 05:24:51 +0000 |
| commit | d26dae0d34cf13daab871fcffa513c6dd96a15bb (patch) | |
| tree | ebab447ed20bf788df4b4b11c3fd81c859b4d595 /llvm/lib | |
| parent | 0b9fbf97f0a5d5a4f6bd7d09aa1ec2fadae157bf (diff) | |
| download | bcm5719-llvm-d26dae0d34cf13daab871fcffa513c6dd96a15bb.tar.gz bcm5719-llvm-d26dae0d34cf13daab871fcffa513c6dd96a15bb.zip | |
Separate the logic when handling indirect calls in SamplePGO ThinLTO compile phase and other phases.
Summary: In SamplePGO ThinLTO compile phase, we will not invoke ICP as it may introduce confusion to the 2nd annotation. This patch extracted that logic and makes it clearer before profile annotation. In the mean time, we need to make function importing process both inlined callsites as well as not promoted indirect callsites.
Reviewers: tejohnson
Reviewed By: tejohnson
Subscribers: sanjoy, mehdi_amini, llvm-commits, inglorion
Differential Revision: https://reviews.llvm.org/D38094
llvm-svn: 314619
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp | 38 |
2 files changed, 28 insertions, 13 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index c277b5b14e7..c9cc0c5ae38 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -555,7 +555,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) { // Annotate sample profile right after early FPM to ensure freshness of // the debug info. - MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile)); + MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile, + Phase == ThinLTOPhase::PreLink)); // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard // for the profile annotation to be accurate in the ThinLTO backend. if (Phase != ThinLTOPhase::PreLink) diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index 93e697c9a7e..7dce904ff15 100644 --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -149,13 +149,14 @@ private: class SampleProfileLoader { public: SampleProfileLoader( - StringRef Name, + StringRef Name, bool IsThinLTOPreLink, std::function<AssumptionCache &(Function &)> GetAssumptionCache, std::function<TargetTransformInfo &(Function &)> GetTargetTransformInfo) : DT(nullptr), PDT(nullptr), LI(nullptr), GetAC(GetAssumptionCache), GetTTI(GetTargetTransformInfo), Reader(), Samples(nullptr), - Filename(Name), ProfileIsValid(false), TotalCollectedSamples(0), - ORE(nullptr) {} + Filename(Name), ProfileIsValid(false), + IsThinLTOPreLink(IsThinLTOPreLink), + TotalCollectedSamples(0), ORE(nullptr) {} bool doInitialization(Module &M); bool runOnModule(Module &M, ModuleAnalysisManager *AM); @@ -252,6 +253,12 @@ protected: /// \brief Flag indicating whether the profile input loaded successfully. bool ProfileIsValid; + /// \brief Flag indicating if the pass is invoked in ThinLTO compile phase. + /// + /// In this phase, in annotation, we should not promote indirect calls. + /// Instead, we will mark GUIDs that needs to be annotated to the function. + bool IsThinLTOPreLink; + /// \brief Total number of samples collected in this profile. /// /// This is the sum of all the samples collected in all the functions executed @@ -267,8 +274,9 @@ public: // Class identification, replacement for typeinfo static char ID; - SampleProfileLoaderLegacyPass(StringRef Name = SampleProfileFile) - : ModulePass(ID), SampleLoader(Name, + SampleProfileLoaderLegacyPass(StringRef Name = SampleProfileFile, + bool IsThinLTOPreLink = false) + : ModulePass(ID), SampleLoader(Name, IsThinLTOPreLink, [&](Function &F) -> AssumptionCache & { return ACT->getAssumptionCache(F); }, @@ -755,6 +763,12 @@ bool SampleProfileLoader::inlineHotFunctions( if (PromotedInsns.count(I)) continue; for (const auto *FS : findIndirectCallFunctionSamples(*I)) { + if (IsThinLTOPreLink) { + FS->findImportedFunctions(ImportGUIDs, F.getParent(), + Samples->getTotalSamples() * + SampleProfileHotThreshold / 100); + continue; + } auto CalleeFunctionName = FS->getName(); // If it is a recursive call, we do not inline it as it could bloat // the code exponentially. There is way to better handle this, e.g. @@ -783,16 +797,16 @@ bool SampleProfileLoader::inlineHotFunctions( inlineCallInstruction(DI)) LocalChanged = true; } else { - FS->findImportedFunctions(ImportGUIDs, F.getParent(), - Samples->getTotalSamples() * - SampleProfileHotThreshold / 100); + DEBUG(dbgs() + << "\nFailed to promote indirect call to " + << CalleeFunctionName << " because " << Reason << "\n"); } } } else if (CalledFunction && CalledFunction->getSubprogram() && !CalledFunction->isDeclaration()) { if (inlineCallInstruction(I)) LocalChanged = true; - } else { + } else if (IsThinLTOPreLink) { findCalleeFunctionSamples(*I)->findImportedFunctions( ImportGUIDs, F.getParent(), Samples->getTotalSamples() * SampleProfileHotThreshold / 100); @@ -1558,9 +1572,9 @@ PreservedAnalyses SampleProfileLoaderPass::run(Module &M, return FAM.getResult<TargetIRAnalysis>(F); }; - SampleProfileLoader SampleLoader(ProfileFileName.empty() ? SampleProfileFile - : ProfileFileName, - GetAssumptionCache, GetTTI); + SampleProfileLoader SampleLoader( + ProfileFileName.empty() ? SampleProfileFile : ProfileFileName, + IsThinLTOPreLink, GetAssumptionCache, GetTTI); SampleLoader.doInitialization(M); |

