[PATCH] D157061: [SampleProfile] Potential use after move in SampleProfileLoader::promoteMergeNotInlinedContextSamples
William Junda Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 17:40:44 PDT 2023
huangjd updated this revision to Diff 550560.
huangjd added a comment.
Remove unused getOrCreateSamples function
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157061/new/
https://reviews.llvm.org/D157061
Files:
llvm/include/llvm/ProfileData/SampleProfReader.h
llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
llvm/lib/Transforms/IPO/SampleProfile.cpp
Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1619,7 +1619,12 @@
// Note that we have to do the merge right after processing function.
// This allows OutlineFS's profile to be used for annotation during
// top-down processing of functions' annotation.
- FunctionSamples *OutlineFS = Reader->getOrCreateSamplesFor(*Callee);
+ FunctionSamples *OutlineFS = Reader->getSamplesFor(*Callee);
+ // If outlined function does not exist in the profile, add it to a
+ // separate map so that it does not rehash the original profile.
+ if (!OutlineFS)
+ OutlineFS = &OutlineFunctionSamples[
+ FunctionSamples::getCanonicalFnName(Callee->getName())];
OutlineFS->merge(*FS, 1);
// Set outlined profile to be synthetic to not bias the inliner.
OutlineFS->SetContextSynthetic();
@@ -2571,8 +2576,24 @@
if (FunctionSamples::ProfileIsCS)
Samples = ContextTracker->getBaseSamplesFor(F);
- else
+ else {
Samples = Reader->getSamplesFor(F);
+ // Try search in previously inlined functions that were split or duplicated
+ // into base.
+ if (!Samples) {
+ StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
+ auto It = OutlineFunctionSamples.find(CanonName);
+ if (It != OutlineFunctionSamples.end()) {
+ Samples = &It->second;
+ } else if (auto Remapper = Reader->getRemapper()) {
+ if (auto RemppedName = Remapper->lookUpNameInProfile(CanonName)) {
+ It = OutlineFunctionSamples.find(*RemppedName);
+ if (It != OutlineFunctionSamples.end())
+ Samples = &It->second;
+ }
+ }
+ }
+ }
if (Samples && !Samples->empty())
return emitAnnotations(F);
Index: llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
+++ llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
@@ -265,6 +265,10 @@
/// Profile reader object.
std::unique_ptr<SampleProfileReader> Reader;
+ /// Synthetic samples created by duplicating the samples of inlined functions
+ /// from the original profile as if they were top level sample profiles.
+ SampleProfileMap OutlineFunctionSamples;
+
// A pseudo probe helper to correlate the imported sample counts.
std::unique_ptr<PseudoProbeManager> ProbeManager;
Index: llvm/include/llvm/ProfileData/SampleProfReader.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProfReader.h
+++ llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -407,22 +407,6 @@
return getSamplesFor(CanonName);
}
- /// Return the samples collected for function \p F, create empty
- /// FunctionSamples if it doesn't exist.
- FunctionSamples *getOrCreateSamplesFor(const Function &F) {
- std::string FGUID;
- StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
- CanonName = getRepInFormat(CanonName, useMD5(), FGUID);
- auto It = Profiles.find(CanonName);
- if (It != Profiles.end())
- return &It->second;
- if (!FGUID.empty()) {
- assert(useMD5() && "New name should only be generated for md5 profile");
- CanonName = *MD5NameBuffer.insert(FGUID).first;
- }
- return &Profiles[CanonName];
- }
-
/// Return the samples collected for function \p F.
virtual FunctionSamples *getSamplesFor(StringRef Fname) {
std::string FGUID;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157061.550560.patch
Type: text/x-patch
Size: 3705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230816/ff6fd9cf/attachment.bin>
More information about the llvm-commits
mailing list