[llvm] [SampleFDO] Match functions with the same base function name (PR #126688)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 18:25:29 PST 2025


================
@@ -727,6 +728,33 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
   // two sequences are.
   float Similarity = 0.0;
 
+  // Match the functions if they have the same base name(after demangling) and
+  // skip the similarity check.
+  ItaniumPartialDemangler Demangler;
+  // Helper lambda to demangle and get the base name. If the demangling failed,
+  // return an empty string.
+  auto GetBaseName = [&](StringRef FName) {
+    auto FunctionName = FName.str();
+    if (Demangler.partialDemangle(FunctionName.c_str()))
+      return std::string();
+    constexpr size_t MaxBaseNameSize = 4096;
+    char BaseNameBuf[MaxBaseNameSize] = {};
+    size_t BaseNameSize = MaxBaseNameSize;
+    char *BaseNamePtr =
+        Demangler.getFunctionBaseName(BaseNameBuf, &BaseNameSize);
+    return (BaseNamePtr && BaseNameSize)
+               ? std::string(BaseNamePtr, BaseNameSize)
+               : std::string();
----------------
WenleiHe wrote:

Haven't looked closely, but is `BaseNamePtr` reusing some the buffer from `BaseNameBuf`? We cannot return anything pointing to local buffer. 

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


More information about the llvm-commits mailing list