[llvm] [SampleFDO] Improve stale profile matching by diff algorithm (PR #87375)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 22:40:39 PDT 2024
================
@@ -171,43 +215,37 @@ void SampleProfileMatcher::runStaleProfileMatching(
// Use function's beginning location as the initial anchor.
int32_t LocationDelta = 0;
SmallVector<LineLocation> LastMatchedNonAnchors;
-
for (const auto &IR : IRAnchors) {
const auto &Loc = IR.first;
- auto CalleeName = IR.second;
+ [[maybe_unused]] StringRef CalleeName = IR.second.stringRef();
bool IsMatchedAnchor = false;
- // Match the anchor location in lexical order.
- if (!CalleeName.empty()) {
- auto CandidateAnchors =
- CalleeToCallsitesMap.find(getRepInFormat(CalleeName));
- if (CandidateAnchors != CalleeToCallsitesMap.end() &&
- !CandidateAnchors->second.empty()) {
- auto CI = CandidateAnchors->second.begin();
- const auto Candidate = *CI;
- CandidateAnchors->second.erase(CI);
- InsertMatching(Loc, Candidate);
- LLVM_DEBUG(dbgs() << "Callsite with callee:" << CalleeName
- << " is matched from " << Loc << " to " << Candidate
- << "\n");
- LocationDelta = Candidate.LineOffset - Loc.LineOffset;
-
- // Match backwards for non-anchor locations.
- // The locations in LastMatchedNonAnchors have been matched forwards
- // based on the previous anchor, spilt it evenly and overwrite the
- // second half based on the current anchor.
- for (size_t I = (LastMatchedNonAnchors.size() + 1) / 2;
- I < LastMatchedNonAnchors.size(); I++) {
- const auto &L = LastMatchedNonAnchors[I];
- uint32_t CandidateLineOffset = L.LineOffset + LocationDelta;
- LineLocation Candidate(CandidateLineOffset, L.Discriminator);
- InsertMatching(L, Candidate);
- LLVM_DEBUG(dbgs() << "Location is rematched backwards from " << L
- << " to " << Candidate << "\n");
- }
- IsMatchedAnchor = true;
- LastMatchedNonAnchors.clear();
+ // Match the anchor location in lexical order.
+ auto R = MatchedAnchors.find(Loc);
+ if (R != MatchedAnchors.end()) {
+ const auto &Candidate = R->second;
+ InsertMatching(Loc, Candidate);
+ LLVM_DEBUG(dbgs() << "Callsite with callee:" << CalleeName
----------------
WenleiHe wrote:
nit: fold `IR.second.stringRef()` to use here so you don't have to use `[[maybe_unused]]` to suppress warning for non-debug builds.
https://github.com/llvm/llvm-project/pull/87375
More information about the llvm-commits
mailing list