[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:07 PDT 2024


================
@@ -782,6 +782,26 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
   float Similarity = 0.0;
 
   const auto *FSFlattened = getFlattenedSamplesFor(ProfFunc);
+  // Check if the function is top-level function. For extended profile format,
+  // if a function profile is unused and it's top-level, even if the profile is
+  // matched, it's not found in the profile. This is because sample reader only
+  // read the used profile at the beginning, we need to read the profile
+  // on-demand. Also save it into the FlattenedProfiles for future look-up.
+  if (!FSFlattened) {
+    DenseSet<StringRef> TopLevelFunc;
+    TopLevelFunc.insert(ProfFunc.stringRef());
+    SampleProfileMap TopLevelProfile;
+    Reader.readOnDemand(TopLevelFunc, TopLevelProfile);
----------------
WenleiHe wrote:

How often does this happen on this path (coming from LCS I think)? And how useful it is to load profile here? 

Asking because we probably don't want to load many functions just to do the similarity checks during LCS, as loading profile is kind of expensive? 

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


More information about the llvm-commits mailing list