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

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 16:37:48 PDT 2024


================
@@ -2412,8 +2421,21 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
   // 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.
+    // 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(see "profileIsValid").
+    if (LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink) {
+      F.addFnAttr("profile-checksum-mismatch");
+      [[maybe_unused]] const auto *Desc = ProbeManager->getDesc(F);
+      assert((Desc &&
+              ProbeManager->profileIsHashMismatched(*Desc, *FSFlattened)) &&
+             "The profile-checksum-mismatch attribute is set but there is no "
+             "pseudo-probe descriptor or the checksum is matched");
----------------
WenleiHe wrote:

This assertion is a bit confusing -- it's asserting on something we just checked above from `profileIsValid`?

Originally what I meant was that if both attribute and desc exists, we should make sure they agree. That can only happen in post-link. 

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


More information about the llvm-commits mailing list