[PATCH] D156715: [CSSPGO] Fix issues with post-link function checksum check

Lei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 12:34:36 PDT 2023


wlei updated this revision to Diff 546974.
wlei added a comment.

Updating D156715 <https://reviews.llvm.org/D156715>: [CSSPGO] Fix issues with post-link function checksum check


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156715/new/

https://reviews.llvm.org/D156715

Files:
  llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1819,7 +1819,14 @@
   bool Changed = false;
 
   if (FunctionSamples::ProfileIsProbeBased) {
-    if (!ProbeManager->profileIsValid(F, *Samples)) {
+    const auto *FuncDesc = ProbeManager->getDesc(F);
+    if (!FuncDesc) {
+      LLVM_DEBUG(dbgs() << "There is no probe_desc for " << F.getName()
+                        << " or it's an imported function."
+                        << "\n");
+      return false;
+    }
+    if (!ProbeManager->profileIsHashMismatched(*FuncDesc, *Samples)) {
       LLVM_DEBUG(
           dbgs() << "Profile is invalid due to CFG mismatch for Function "
                  << F.getName() << "\n");
@@ -2268,7 +2275,8 @@
     uint64_t Count = FS.getTotalSamples();
     TotalFuncHashSamples += Count;
     TotalProfiledFunc++;
-    if (!ProbeManager->profileIsValid(F, FS)) {
+    const auto *FuncDesc = ProbeManager->getDesc(F);
+    if (FuncDesc && ProbeManager->profileIsHashMismatched(*FuncDesc, FS)) {
       MismatchedFuncHashSamples += Count;
       NumMismatchedFuncHash++;
       IsFuncHashMismatch = true;
Index: llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
+++ llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
@@ -87,12 +87,6 @@
 class PseudoProbeManager {
   DenseMap<uint64_t, PseudoProbeDescriptor> GUIDToProbeDescMap;
 
-  const PseudoProbeDescriptor *getDesc(const Function &F) const {
-    auto I = GUIDToProbeDescMap.find(
-        Function::getGUID(FunctionSamples::getCanonicalFnName(F)));
-    return I == GUIDToProbeDescMap.end() ? nullptr : &I->second;
-  }
-
 public:
   PseudoProbeManager(const Module &M) {
     if (NamedMDNode *FuncInfo =
@@ -108,10 +102,21 @@
     }
   }
 
+  const PseudoProbeDescriptor *getDesc(const Function &F) const {
+    auto I = GUIDToProbeDescMap.find(
+        Function::getGUID(FunctionSamples::getCanonicalFnName(F)));
+    return I == GUIDToProbeDescMap.end() ? nullptr : &I->second;
+  }
+
   bool moduleIsProbed(const Module &M) const {
     return M.getNamedMetadata(PseudoProbeDescMetadataName);
   }
 
+  bool profileIsHashMismatched(const PseudoProbeDescriptor &FuncDesc,
+                               const FunctionSamples &Samples) const {
+    return FuncDesc.getFunctionHash() != Samples.getFunctionHash();
+  }
+
   bool profileIsValid(const Function &F, const FunctionSamples &Samples) const {
     const auto *Desc = getDesc(F);
     if (!Desc) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156715.546974.patch
Type: text/x-patch
Size: 2739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/04fd5ad3/attachment.bin>


More information about the llvm-commits mailing list