[llvm] [CSSPGO] Fix the issue of missing callee profile matches (PR #85715)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 16:08:15 PDT 2024


================
@@ -2410,17 +2412,26 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
 
   // Run profile matching for checksum mismatched profile, currently only
   // support for pseudo-probe.
-  if (SalvageStaleProfile && FunctionSamples::ProfileIsProbeBased &&
-      !ProbeManager->profileIsValid(F, *FSFlattened)) {
-    // The matching result will be saved to IRToProfileLocationMap, create a new
-    // map for each function.
-    auto &IRToProfileLocationMap = getIRToProfileLocationMap(F);
-    runStaleProfileMatching(F, IRAnchors, ProfileAnchors,
-                            IRToProfileLocationMap);
-    // Find and update callsite match states after matching.
-    if (ReportProfileStaleness || PersistProfileStaleness)
-      recordCallsiteMatchStates(F, IRAnchors, ProfileAnchors,
-                                &IRToProfileLocationMap);
+  if (SalvageStaleProfile && FunctionSamples::ProfileIsProbeBased) {
+    const auto *Desc = ProbeManager->getDesc(F);
+    // For imported functions, the checksum metadata(pseudo_probe_desc) are
+    // dropped, so we leverage function attribute(profile-checksum-mismatch) to
+    // transfer the info: add the attribute during pre-link phase and check it
+    // during post-link phase.
+    if ((Desc && ProbeManager->profileIsHashMismatched(*Desc, *FSFlattened)) ||
+        F.hasFnAttribute("profile-checksum-mismatch")) {
----------------
WenleiHe wrote:

Should the attribute check also be hidden behind `profileIsValid`? 

We call `profileIsValid` from `emitAnnotations` too for statistics. 

https://github.com/llvm/llvm-project/pull/85715


More information about the llvm-commits mailing list