@@ -446,13 +446,19 @@ class SampleProfileMatcher {
446
446
447
447
// Match state for an anchor/callsite.
448
448
enum class MatchState {
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 ,
455
- Unknown = 32 ,
449
+ Unknown = 0 ,
450
+ // Initial match in pre-match.
451
+ InitialMatch = 1 ,
452
+ // Initial mismatch in pre-match.
453
+ InitialMismatch = 2 ,
454
+ // InitialMatch stays matched in post-match.
455
+ UnchangedMatch = 3 ,
456
+ // InitialMismatch stays mismatched in post-match.
457
+ UnchangedMismatch = 4 ,
458
+ // InitialMismatch is recovered in post-match.
459
+ RecoveredMismatch = 5 ,
460
+ // InitialMatch is removed and becomes mismatched in post-match.
461
+ RemovedMatch = 6 ,
456
462
};
457
463
458
464
// For each function, store every callsite and its matching state into this
@@ -508,6 +514,12 @@ class SampleProfileMatcher {
508
514
&ProfileAnchors,
509
515
const LocToLocMap *IRToProfileLocationMap);
510
516
517
+ bool isMismatchState (const enum MatchState &State) {
518
+ return State == MatchState::InitialMismatch ||
519
+ State == MatchState::UnchangedMismatch ||
520
+ State == MatchState::RemovedMatch;
521
+ };
522
+
511
523
// Count the samples of checksum mismatched function for the top-level
512
524
// function and all inlinees.
513
525
void countMismatchedFuncSamples (const FunctionSamples &FS, bool IsTopLevel);
@@ -2434,12 +2446,15 @@ void SampleProfileMatcher::recordCallsiteMatchStates(
2434
2446
IsCallsiteMatched = true ;
2435
2447
2436
2448
if (IsCallsiteMatched) {
2437
- auto R =
2438
- CallsiteMatchStates.emplace (ProfileLoc, MatchState::InitialMatch);
2439
- // When there is an existing state, we know it's in post-match phrase.
2440
- // Update the matching state accordingly.
2441
- if (!R.second && R.first ->second == MatchState::InitialMismatch)
2442
- R.first ->second = MatchState::RecoveredMismatch;
2449
+ auto It = CallsiteMatchStates.find (ProfileLoc);
2450
+ if (It == CallsiteMatchStates.end ())
2451
+ CallsiteMatchStates.emplace (ProfileLoc, MatchState::InitialMatch);
2452
+ else if (IsPostMatch) {
2453
+ if (It->second == MatchState::InitialMatch)
2454
+ It->second = MatchState::UnchangedMatch;
2455
+ else if (It->second == MatchState::InitialMismatch)
2456
+ It->second = MatchState::RecoveredMismatch;
2457
+ }
2443
2458
}
2444
2459
}
2445
2460
@@ -2452,9 +2467,14 @@ void SampleProfileMatcher::recordCallsiteMatchStates(
2452
2467
auto It = CallsiteMatchStates.find (Loc);
2453
2468
if (It == CallsiteMatchStates.end ())
2454
2469
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);
2470
+ else if (IsPostMatch) {
2471
+ // Update the state if it's not matched(UnchangedMatch or
2472
+ // RecoveredMismatch).
2473
+ if (It->second == MatchState::InitialMismatch)
2474
+ It->second = MatchState::UnchangedMismatch;
2475
+ else if (It->second == MatchState::InitialMatch)
2476
+ It->second = MatchState::RemovedMatch;
2477
+ }
2458
2478
}
2459
2479
}
2460
2480
@@ -2501,14 +2521,9 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
2501
2521
return It->second ;
2502
2522
};
2503
2523
2504
- auto IsMismatchState = [&](const enum MatchState &State) {
2505
- return State == MatchState::InitialMismatch ||
2506
- State == MatchState::RemovedMatch;
2507
- };
2508
-
2509
2524
auto AttributeMismatchedSamples = [&](const enum MatchState &State,
2510
2525
uint64_t Samples) {
2511
- if (IsMismatchState (State))
2526
+ if (isMismatchState (State))
2512
2527
MismatchedCallsiteSamples += Samples;
2513
2528
else if (State == MatchState::RecoveredMismatch)
2514
2529
RecoveredCallsiteSamples += Samples;
@@ -2527,7 +2542,7 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
2527
2542
CallsiteSamples += CS.second .getTotalSamples ();
2528
2543
AttributeMismatchedSamples (State, CallsiteSamples);
2529
2544
2530
- if (IsMismatchState (State))
2545
+ if (isMismatchState (State))
2531
2546
continue ;
2532
2547
2533
2548
// When the current level of inlined call site matches the profiled call
@@ -2546,8 +2561,7 @@ void SampleProfileMatcher::countMismatchCallsites(const FunctionSamples &FS) {
2546
2561
const auto &MatchStates = It->second ;
2547
2562
for (const auto &I : MatchStates) {
2548
2563
TotalProfiledCallsites++;
2549
- if (I.second == MatchState::InitialMismatch ||
2550
- I.second == MatchState::RemovedMatch)
2564
+ if (isMismatchState (I.second ))
2551
2565
NumMismatchedCallsites++;
2552
2566
else if (I.second == MatchState::RecoveredMismatch)
2553
2567
NumRecoveredCallsites++;
0 commit comments