Skip to content

Commit 15ca43a

Browse files
committed
Update comments
1 parent 854eaf4 commit 15ca43a

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ class SampleProfileMatcher {
455455
Unknown = 32,
456456
};
457457

458-
// For each function, store every callsite state into a map, of which each
459-
// entry is a pair of callsite location and MatchState. This is used for
460-
// profile stalness computation and report.
458+
// For each function, store every callsite a matching state into this map, of
459+
// which each entry is a pair of callsite location and MatchState. This is
460+
// used for profile stalness computation and report.
461461
StringMap<std::unordered_map<LineLocation, MatchState, LineLocationHash>>
462462
FuncCallsiteMatchStates;
463463

@@ -501,7 +501,7 @@ class SampleProfileMatcher {
501501
const FunctionSamples &FS,
502502
std::map<LineLocation, std::unordered_set<FunctionId>> &ProfileAnchors);
503503
// Compute the callsite match states for profile staleness report, the result
504-
// is save in FuncCallsiteMatchStates.
504+
// is saved in FuncCallsiteMatchStates.
505505
void computeCallsiteMatchStates(
506506
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
507507
const std::map<LineLocation, std::unordered_set<FunctionId>>
@@ -2403,8 +2403,8 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
24032403
auto &CallsiteMatchStates =
24042404
FuncCallsiteMatchStates[FunctionSamples::getCanonicalFnName(F.getName())];
24052405

2406-
// IRToProfileLocationMap is null before the matching.
24072406
auto MapIRLocToProfileLoc = [&](const LineLocation &IRLoc) {
2407+
// IRToProfileLocationMap is null in pre-match phrase.
24082408
if (!IRToProfileLocationMap)
24092409
return IRLoc;
24102410
const auto &ProfileLoc = IRToProfileLocationMap->find(IRLoc);
@@ -2435,8 +2435,8 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
24352435

24362436
if (IsCallsiteMatched) {
24372437
auto R = CallsiteMatchStates.emplace(Loc, MatchState::Matched);
2438-
// Update the post-match state when there is a existing state indicateing
2439-
// it's in post-match phrase.
2438+
// When there is an existing state, we know it's in post-match phrase.
2439+
// Update the matching state accordingly.
24402440
if (!R.second) {
24412441
if (R.first->second == MatchState::Mismatched)
24422442
R.first->second = MatchState::Recovered;
@@ -2447,15 +2447,15 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
24472447
}
24482448

24492449
// Check if there are any callsites in the profile that does not match to any
2450-
// IR callsites, those callsite samples will be discarded.
2450+
// IR callsites.
24512451
for (const auto &I : ProfileAnchors) {
24522452
const auto &Loc = I.first;
24532453
[[maybe_unused]] const auto &Callees = I.second;
24542454
assert(!Callees.empty() && "Callees should not be empty");
24552455
auto It = CallsiteMatchStates.find(Loc);
24562456
if (It == CallsiteMatchStates.end())
24572457
CallsiteMatchStates.emplace(Loc, MatchState::Mismatched);
2458-
// If in post-match, the state is not updated to Recovered or StayMatched,
2458+
// In post-match, if the state is not updated to Recovered or StayMatched,
24592459
// update it to Mismatched.
24602460
else if (IsPostMatch && It->second == MatchState::Matched)
24612461
CallsiteMatchStates.emplace(Loc, MatchState::Mismatched);
@@ -2472,17 +2472,19 @@ void SampleProfileMatcher::countMismatchedFuncSamples(const FunctionSamples &FS,
24722472
if (ProbeManager->profileIsHashMismatched(*FuncDesc, FS)) {
24732473
if (IsTopLevel)
24742474
NumStaleProfileFunc++;
2475-
// Once the checksum is mismatched, it's likely all the callites are
2476-
// mismatched and dropped, we conservatively count all the samples as
2477-
// mismatched samples and stop counting the inlinee profile.
2475+
// Given currently all probe ids are after block probe ids, once the
2476+
// checksum is mismatched, it's likely all the callites are mismatched and
2477+
// dropped. We conservatively count all the samples as mismatched and stop
2478+
// counting the inlinees' profiles.
24782479
MismatchedFunctionSamples += FS.getTotalSamples();
24792480
return;
24802481
}
24812482

2482-
// Even the current function checksum is matched, it's possible that the
2483-
// inlinees' checksums are mismatched, we need to go deeper to check the
2484-
// inlinee's function samples. Similarly, if the inlinee's checksum is
2485-
// mismatched, we stop and count all the samples as mismatched samples.
2483+
// Even the current-level function checksum is matched, it's possible that the
2484+
// nested inlinees' checksums are mismatched that affect the inlinee's sample
2485+
// loading, we need to go deeper to check the inlinees' function samples.
2486+
// Similarly, count all the samples as mismatched if the inlinee's checksum is
2487+
// mismatched using this recursive function.
24862488
for (const auto &I : FS.getCallsiteSamples())
24872489
for (const auto &CS : I.second)
24882490
countMismatchedFuncSamples(CS.second, false);
@@ -2512,10 +2514,11 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
25122514
};
25132515

25142516
// The non-inlined callsites are saved in the body samples of function
2515-
// profile.
2517+
// profile, go through it to count the non-inlined callsite samples.
25162518
for (const auto &I : FS.getBodySamples())
25172519
AttributeMismatchedSamples(findMatchState(I.first), I.second.getSamples());
25182520

2521+
// Count the inlined callsite samples.
25192522
for (const auto &I : FS.getCallsiteSamples()) {
25202523
auto State = findMatchState(I.first);
25212524
uint64_t CallsiteSamples = 0;

0 commit comments

Comments
 (0)