[llvm] [SampleFDO] Read call-graph matching recovered top-level function profile (PR #101053)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 10:59:05 PDT 2024


================
@@ -863,6 +883,39 @@ bool SampleProfileMatcher::functionMatchesProfile(Function &IRFunc,
   return Matched;
 }
 
+void SampleProfileMatcher::UpdateSampleLoaderWithRecoveredProfiles() {
+  DenseSet<StringRef> RecoveredFuncs;
+  // Update FuncNameToProfNameMap and SymbolMap.
+  for (auto &I : FuncToProfileNameMap) {
+    assert(I.first && "New function is null");
+    FunctionId FuncName(I.first->getName());
+    RecoveredFuncs.insert(I.second.stringRef());
+    FuncNameToProfNameMap->emplace(FuncName, I.second);
+
+    // We need to remove the old entry to avoid duplicating the function
+    // processing.
+    SymbolMap->erase(FuncName);
+    SymbolMap->emplace(I.second, I.first);
+  }
+
+  // Read the top-level profiles for the recovered function profiles. This is
+  // because in extended binary format it only loads the top-level profile for
+  // the functions in the new build but not the recovered functions which is
+  // from the old build.
+  SampleProfileMap TopLevelRecoveredProfiles;
+  Reader.readOnDemand(RecoveredFuncs, TopLevelRecoveredProfiles);
+  auto &Profiles = Reader.getProfiles();
+  for (auto &I : TopLevelRecoveredProfiles) {
+    LLVM_DEBUG(dbgs() << "Top-level function " << I.second.getFunction()
+                      << " is recovered and re-read by the sample reader.\n");
----------------
WenleiHe wrote:

nit: recovered -> salvaged, top-level function -> profile for top-level function

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


More information about the llvm-commits mailing list