[llvm] [MemProf] Suppress duplicate clones in the LTO backend (PR #161551)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 14:06:15 PDT 2025


================
@@ -5186,19 +5191,129 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
   return Changed;
 }
 
+// Compute a SHA1 hash of the callsite and alloc version information of clone I
+// in the summary, to use in detection of duplicate clones.
+std::string ComputeHash(StringMap<Function *> &HashToFunc, FunctionSummary *FS,
+                        unsigned I) {
+  SHA1 Hasher;
+  // Update hash with any callsites that call non-default (non-zero) callee
+  // versions.
+  for (auto &SN : FS->callsites()) {
+    // In theory all callsites and allocs in this function should have the same
+    // number of clone entries, but handle any discrepancies gracefully below
+    // for NDEBUG builds.
+    assert(
+        SN.Clones.size() > I &&
+        "Callsite summary has fewer entries than other summaries in function");
+    if (SN.Clones.size() <= I || !SN.Clones[I])
+      continue;
+    uint8_t Data[4];
----------------
kazutakahirata wrote:

May I suggest this?
```suggestion
    uint8_t Data[sizeof(SN.Clones[I])];
```


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


More information about the llvm-commits mailing list