diff options
author | Wei Mi <wmi@google.com> | 2018-09-06 22:03:37 +0000 |
---|---|---|
committer | Wei Mi <wmi@google.com> | 2018-09-06 22:03:37 +0000 |
commit | 94d44c97bcffbf157b05a45c2f0e56302db9a03c (patch) | |
tree | 4d7274c699daa90d327ad6709ec3250865917133 /llvm/lib/Transforms/IPO/SampleProfile.cpp | |
parent | a0a738b1840fa690a13937774a1a1e994cf58c4f (diff) | |
download | bcm5719-llvm-94d44c97bcffbf157b05a45c2f0e56302db9a03c.tar.gz bcm5719-llvm-94d44c97bcffbf157b05a45c2f0e56302db9a03c.zip |
[SampleFDO] Make sample profile loader unaware of compact format change.
The patch tries to make sample profile loader independent of profile format
change. It moves compact format related code into FunctionSamples and
SampleProfileReader classes, and sample profile loader only has to interact
with those two classes and will be unaware of profile format changes.
The cleanup also contain some fixes to further remove the difference between
compactbinary format and binary format. After the cleanup using different
formats originated from the same profile will generate the same binaries,
which we verified by compiling two large server benchmarks w/wo thinlto.
Differential Revision: https://reviews.llvm.org/D51643
llvm-svn: 341591
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfile.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index dcd24595f7e..b9b055d36f7 100644 --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -643,8 +643,6 @@ SampleProfileLoader::findCalleeFunctionSamples(const Instruction &Inst) const { if (FS == nullptr) return nullptr; - std::string CalleeGUID; - CalleeName = getRepInFormat(CalleeName, Reader->getFormat(), CalleeGUID); return FS->findFunctionSamplesAt(LineLocation(FunctionSamples::getOffset(DIL), DIL->getBaseDiscriminator()), CalleeName); @@ -685,7 +683,10 @@ SampleProfileLoader::findIndirectCallFunctionSamples( } llvm::sort(R.begin(), R.end(), [](const FunctionSamples *L, const FunctionSamples *R) { - return L->getEntrySamples() > R->getEntrySamples(); + if (L->getEntrySamples() != R->getEntrySamples()) + return L->getEntrySamples() > R->getEntrySamples(); + return FunctionSamples::getGUID(L->getName()) < + FunctionSamples::getGUID(R->getName()); }); } return R; @@ -760,7 +761,6 @@ bool SampleProfileLoader::inlineHotFunctions( Function &F, DenseSet<GlobalValue::GUID> &InlinedGUIDs) { DenseSet<Instruction *> PromotedInsns; bool Changed = false; - bool isCompact = (Reader->getFormat() == SPF_Compact_Binary); while (true) { bool LocalChanged = false; SmallVector<Instruction *, 10> CIS; @@ -792,19 +792,16 @@ bool SampleProfileLoader::inlineHotFunctions( for (const auto *FS : findIndirectCallFunctionSamples(*I, Sum)) { if (IsThinLTOPreLink) { FS->findInlinedFunctions(InlinedGUIDs, F.getParent(), - PSI->getOrCompHotCountThreshold(), - isCompact); + PSI->getOrCompHotCountThreshold()); continue; } - auto CalleeFunctionName = FS->getName(); + auto CalleeFunctionName = FS->getFuncNameInModule(F.getParent()); // 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. // clone the caller first, and inline the cloned caller if it is // recursive. As llvm does not inline recursive calls, we will // simply ignore it instead of handling it explicitly. - std::string FGUID; - auto Fname = getRepInFormat(F.getName(), Reader->getFormat(), FGUID); - if (CalleeFunctionName == Fname) + if (CalleeFunctionName == F.getName()) continue; const char *Reason = "Callee function not available"; @@ -834,8 +831,7 @@ bool SampleProfileLoader::inlineHotFunctions( LocalChanged = true; } else if (IsThinLTOPreLink) { findCalleeFunctionSamples(*I)->findInlinedFunctions( - InlinedGUIDs, F.getParent(), PSI->getOrCompHotCountThreshold(), - isCompact); + InlinedGUIDs, F.getParent(), PSI->getOrCompHotCountThreshold()); } } if (LocalChanged) { @@ -1177,7 +1173,7 @@ static SmallVector<InstrProfValueData, 2> SortCallTargets( const SampleRecord::CallTargetMap &M) { SmallVector<InstrProfValueData, 2> R; for (auto I = M.begin(); I != M.end(); ++I) - R.push_back({Function::getGUID(I->getKey()), I->getValue()}); + R.push_back({FunctionSamples::getGUID(I->getKey()), I->getValue()}); llvm::sort(R.begin(), R.end(), [](const InstrProfValueData &L, const InstrProfValueData &R) { if (L.Count == R.Count) @@ -1533,6 +1529,7 @@ ModulePass *llvm::createSampleProfileLoaderPass(StringRef Name) { bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM, ProfileSummaryInfo *_PSI) { + FunctionSamples::GUIDToFuncNameMapper Mapper(M); if (!ProfileIsValid) return false; |