[llvm] [SampleFDO] Stale profile call-graph matching (PR #95135)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 13:32:27 PDT 2024


================
@@ -127,8 +143,43 @@ void SampleProfileMatcher::findProfileAnchors(const FunctionSamples &FS,
   }
 }
 
-LocToLocMap SampleProfileMatcher::longestCommonSequence(
-    const AnchorList &AnchorList1, const AnchorList &AnchorList2) const {
+Function *
+SampleProfileMatcher::findIfFunctionIsNew(const FunctionId &IRFuncName) {
+  auto R = NewIRFunctions.find(IRFuncName);
+  if (R == NewIRFunctions.end())
+    return nullptr;
+  return R->second;
+}
+
+bool SampleProfileMatcher::isProfileUnused(const FunctionId &ProfileFuncName) {
+  auto F = SymbolMap->find(ProfileFuncName);
+  return F == SymbolMap->end();
+}
+
+bool SampleProfileMatcher::functionMatchesProfile(
+    const FunctionId &IRFuncName, const FunctionId &ProfileFuncName,
+    bool FindMatchedProfileOnly) {
+  if (IRFuncName == ProfileFuncName)
+    return true;
+  if (!SalvageUnusedProfile)
+    return false;
+
+  // If IR function doesn't have profile and the profile is unused, try
+  // matching them.
+  Function *IRFunc = findIfFunctionIsNew(IRFuncName);
----------------
WenleiHe wrote:

The comment and the function name `findIfFunctionIsNew` do not agree. Here we are indeed checking to see if a function has profile, not whether a function is new. 

When we don't have profiled symbol list, `findNewIRFunctions` can get us a list of functions without profile only, because we don't know what's new. I'm wondering if we should rename all these things to emphasize on function without profile instead of new?

Also `functionHasProfile` and `isProfileUnused` seem more symmetrical and easier to understand. 

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


More information about the llvm-commits mailing list