[llvm] a3ac1cf - [SampleProfile] Fix non-determinism in promoteMergeNotInlinedContextSamples()
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 10:18:25 PDT 2022
Author: Arthur Eubanks
Date: 2022-08-12T10:13:25-07:00
New Revision: a3ac1cfaedf708dc6b0db060c24339adeeb7a1ec
URL: https://github.com/llvm/llvm-project/commit/a3ac1cfaedf708dc6b0db060c24339adeeb7a1ec
DIFF: https://github.com/llvm/llvm-project/commit/a3ac1cfaedf708dc6b0db060c24339adeeb7a1ec.diff
LOG: [SampleProfile] Fix non-determinism in promoteMergeNotInlinedContextSamples()
We're seeing non-determinism with loading sample profiles. It seems to
be related to the order in which we merge FunctionSamples in
promoteMergeNotInlinedContextSamples(). Use a MapVector to iterate over
NonInlinedCallSites in the order entries were inserted.
Reviewed By: wenlei, davidxl
Differential Revision: https://reviews.llvm.org/D131592
Added:
Modified:
llvm/lib/Transforms/IPO/SampleProfile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index f76b886e810a..bec390ef3755 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -25,6 +25,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PriorityQueue.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SmallVector.h"
@@ -475,7 +476,7 @@ class SampleProfileLoader final
const SmallVectorImpl<CallBase *> &Candidates, const Function &F,
bool Hot);
void promoteMergeNotInlinedContextSamples(
- DenseMap<CallBase *, const FunctionSamples *> NonInlinedCallSites,
+ MapVector<CallBase *, const FunctionSamples *> NonInlinedCallSites,
const Function &F);
std::vector<Function *> buildFunctionOrder(Module &M, CallGraph *CG);
std::unique_ptr<ProfiledCallGraph> buildProfiledCallGraph(CallGraph &CG);
@@ -1106,7 +1107,7 @@ bool SampleProfileLoader::inlineHotFunctions(
"ProfAccForSymsInList should be false when profile-sample-accurate "
"is enabled");
- DenseMap<CallBase *, const FunctionSamples *> LocalNotInlinedCallSites;
+ MapVector<CallBase *, const FunctionSamples *> LocalNotInlinedCallSites;
bool Changed = false;
bool LocalChanged = true;
while (LocalChanged) {
@@ -1126,7 +1127,7 @@ bool SampleProfileLoader::inlineHotFunctions(
AllCandidates.push_back(CB);
if (FS->getHeadSamplesEstimate() > 0 ||
FunctionSamples::ProfileIsCS)
- LocalNotInlinedCallSites.try_emplace(CB, FS);
+ LocalNotInlinedCallSites.insert({CB, FS});
if (callsiteIsHot(FS, PSI, ProfAccForSymsInList))
Hot = true;
else if (shouldInlineColdCallee(*CB))
@@ -1409,7 +1410,7 @@ bool SampleProfileLoader::inlineHotFunctionsWithPriority(
if (ExternalInlineAdvisor)
SizeLimit = std::numeric_limits<unsigned>::max();
- DenseMap<CallBase *, const FunctionSamples *> LocalNotInlinedCallSites;
+ MapVector<CallBase *, const FunctionSamples *> LocalNotInlinedCallSites;
// Perform iterative BFS call site prioritized inlining
bool Changed = false;
@@ -1466,7 +1467,7 @@ bool SampleProfileLoader::inlineHotFunctionsWithPriority(
ICPCount++;
Changed = true;
} else if (!ContextTracker) {
- LocalNotInlinedCallSites.try_emplace(I, FS);
+ LocalNotInlinedCallSites.insert({I, FS});
}
}
} else if (CalledFunction && CalledFunction->getSubprogram() &&
@@ -1479,7 +1480,7 @@ bool SampleProfileLoader::inlineHotFunctionsWithPriority(
}
Changed = true;
} else if (!ContextTracker) {
- LocalNotInlinedCallSites.try_emplace(I, Candidate.CalleeSamples);
+ LocalNotInlinedCallSites.insert({I, Candidate.CalleeSamples});
}
} else if (LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink) {
findExternalInlineCandidate(I, findCalleeFunctionSamples(*I),
@@ -1505,11 +1506,11 @@ bool SampleProfileLoader::inlineHotFunctionsWithPriority(
}
void SampleProfileLoader::promoteMergeNotInlinedContextSamples(
- DenseMap<CallBase *, const FunctionSamples *> NonInlinedCallSites,
+ MapVector<CallBase *, const FunctionSamples *> NonInlinedCallSites,
const Function &F) {
// Accumulate not inlined callsite information into notInlinedSamples
for (const auto &Pair : NonInlinedCallSites) {
- CallBase *I = Pair.getFirst();
+ CallBase *I = Pair.first;
Function *Callee = I->getCalledFunction();
if (!Callee || Callee->isDeclaration())
continue;
@@ -1521,7 +1522,7 @@ void SampleProfileLoader::promoteMergeNotInlinedContextSamples(
<< "' into '" << ore::NV("Caller", &F) << "'");
++NumCSNotInlined;
- const FunctionSamples *FS = Pair.getSecond();
+ const FunctionSamples *FS = Pair.second;
if (FS->getTotalSamples() == 0 && FS->getHeadSamplesEstimate() == 0) {
continue;
}
More information about the llvm-commits
mailing list