Skip to content

Commit 353f0ac

Browse files
committed
Rename the MatchState value
1 parent 0dc2c79 commit 353f0ac

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ class SampleProfileMatcher {
446446

447447
// Match state for an anchor/callsite.
448448
enum class MatchState {
449-
Matched = 0,
450-
Mismatched = 1,
451-
// Stay Matched after profile matching.
452-
StayMatched = 2,
453-
// Recovered from Mismatched after profile matching.
454-
Recovered = 3,
449+
InitialMatch = 0,
450+
InitialMismatch = 1,
451+
// From initial mismatch to final match.
452+
RecoveredMismatch = 2,
453+
// From initial match to final mismatch.
454+
RemovedMatch = 3,
455455
Unknown = 32,
456456
};
457457

@@ -500,9 +500,9 @@ class SampleProfileMatcher {
500500
void findProfileAnchors(
501501
const FunctionSamples &FS,
502502
std::map<LineLocation, std::unordered_set<FunctionId>> &ProfileAnchors);
503-
// Compute the callsite match states for profile staleness report, the result
503+
// Record the callsite match states for profile staleness report, the result
504504
// is saved in FuncCallsiteMatchStates.
505-
void computeCallsiteMatchStates(
505+
void recordCallsiteMatchStates(
506506
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
507507
const std::map<LineLocation, std::unordered_set<FunctionId>>
508508
&ProfileAnchors,
@@ -2376,7 +2376,7 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
23762376

23772377
// Compute the callsite match states for profile staleness report.
23782378
if (ReportProfileStaleness || PersistProfileStaleness)
2379-
computeCallsiteMatchStates(F, IRAnchors, ProfileAnchors, nullptr);
2379+
recordCallsiteMatchStates(F, IRAnchors, ProfileAnchors, nullptr);
23802380

23812381
// Run profile matching for checksum mismatched profile, currently only
23822382
// support for pseudo-probe.
@@ -2389,12 +2389,12 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
23892389
IRToProfileLocationMap);
23902390
// Find and update callsite match states after matching.
23912391
if (ReportProfileStaleness || PersistProfileStaleness)
2392-
computeCallsiteMatchStates(F, IRAnchors, ProfileAnchors,
2393-
&IRToProfileLocationMap);
2392+
recordCallsiteMatchStates(F, IRAnchors, ProfileAnchors,
2393+
&IRToProfileLocationMap);
23942394
}
23952395
}
23962396

2397-
void SampleProfileMatcher::computeCallsiteMatchStates(
2397+
void SampleProfileMatcher::recordCallsiteMatchStates(
23982398
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
23992399
const std::map<LineLocation, std::unordered_set<FunctionId>>
24002400
&ProfileAnchors,
@@ -2434,15 +2434,12 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
24342434
IsCallsiteMatched = true;
24352435

24362436
if (IsCallsiteMatched) {
2437-
auto R = CallsiteMatchStates.emplace(ProfileLoc, MatchState::Matched);
2437+
auto R =
2438+
CallsiteMatchStates.emplace(ProfileLoc, MatchState::InitialMatch);
24382439
// When there is an existing state, we know it's in post-match phrase.
24392440
// Update the matching state accordingly.
2440-
if (!R.second) {
2441-
if (R.first->second == MatchState::Mismatched)
2442-
R.first->second = MatchState::Recovered;
2443-
if (R.first->second == MatchState::Matched)
2444-
R.first->second = MatchState::StayMatched;
2445-
}
2441+
if (!R.second && R.first->second == MatchState::InitialMismatch)
2442+
R.first->second = MatchState::RecoveredMismatch;
24462443
}
24472444
}
24482445

@@ -2454,11 +2451,10 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
24542451
assert(!Callees.empty() && "Callees should not be empty");
24552452
auto It = CallsiteMatchStates.find(Loc);
24562453
if (It == CallsiteMatchStates.end())
2457-
CallsiteMatchStates.emplace(Loc, MatchState::Mismatched);
2458-
// In post-match, if the state is not updated to Recovered or StayMatched,
2459-
// update it to Mismatched.
2460-
else if (IsPostMatch && It->second == MatchState::Matched)
2461-
CallsiteMatchStates.emplace(Loc, MatchState::Mismatched);
2454+
CallsiteMatchStates.emplace(Loc, MatchState::InitialMismatch);
2455+
// The inital match is removed in post-match.
2456+
else if (IsPostMatch && It->second == MatchState::InitialMatch)
2457+
CallsiteMatchStates.emplace(Loc, MatchState::RemovedMatch);
24622458
}
24632459
}
24642460

@@ -2505,11 +2501,16 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
25052501
return It->second;
25062502
};
25072503

2504+
auto IsMismatchState = [&](const enum MatchState &State) {
2505+
return State == MatchState::InitialMismatch ||
2506+
State == MatchState::RemovedMatch;
2507+
};
2508+
25082509
auto AttributeMismatchedSamples = [&](const enum MatchState &State,
25092510
uint64_t Samples) {
2510-
if (State == MatchState::Mismatched)
2511+
if (IsMismatchState(State))
25112512
MismatchedCallsiteSamples += Samples;
2512-
else if (State == MatchState::Recovered)
2513+
else if (State == MatchState::RecoveredMismatch)
25132514
RecoveredCallsiteSamples += Samples;
25142515
};
25152516

@@ -2526,7 +2527,7 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
25262527
CallsiteSamples += CS.second.getTotalSamples();
25272528
AttributeMismatchedSamples(State, CallsiteSamples);
25282529

2529-
if (State == MatchState::Mismatched)
2530+
if (IsMismatchState(State))
25302531
continue;
25312532

25322533
// When the current level of inlined call site matches the profiled call
@@ -2545,9 +2546,10 @@ void SampleProfileMatcher::countMismatchCallsites(const FunctionSamples &FS) {
25452546
const auto &MatchStates = It->second;
25462547
for (const auto &I : MatchStates) {
25472548
TotalProfiledCallsites++;
2548-
if (I.second == MatchState::Mismatched)
2549+
if (I.second == MatchState::InitialMismatch ||
2550+
I.second == MatchState::RemovedMatch)
25492551
NumMismatchedCallsites++;
2550-
else if (I.second == MatchState::Recovered)
2552+
else if (I.second == MatchState::RecoveredMismatch)
25512553
NumRecoveredCallsites++;
25522554
}
25532555
}

0 commit comments

Comments
 (0)