[llvm] [MergeFunctions] Preserve import GUIDs when folding functions (PR #207003)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 14:49:05 PDT 2026


================
@@ -880,19 +881,35 @@ static bool isODR(const Function *F) {
   return F->hasWeakODRLinkage() || F->hasLinkOnceODRLinkage();
 }
 
-static void mergeEntryCountsInto(Function *F, std::optional<uint64_t> FC,
-                                 std::optional<uint64_t> GC) {
-  if (!FC && !GC)
+static DenseSet<GlobalValue::GUID> unionImportGUIDs(const Function *F,
+                                                    const Function *G) {
+  DenseSet<GlobalValue::GUID> AllImports = F->getImportGUIDs();
+  DenseSet<GlobalValue::GUID> GImports = G->getImportGUIDs();
+  AllImports.insert(GImports.begin(), GImports.end());
+  return AllImports;
+}
+
+static void
+mergeEntryCountsAndImportsInto(Function *F, std::optional<uint64_t> FC,
+                               std::optional<uint64_t> GC,
+                               const DenseSet<GlobalValue::GUID> &Imports) {
+  if (!FC && !GC && Imports.empty())
     return;
-  uint64_t Sum = SaturatingAdd(FC ? *FC : uint64_t{0}, GC ? *GC : uint64_t{0});
-  F->setEntryCount(Sum);
+
+  uint64_t Sum;
+  if (!FC && !GC)
+    Sum = static_cast<uint64_t>(-1);
----------------
teresajohnson wrote:

Is -1 the right fallback value? Won't that make it look super hot or is there special handling to treat -1 as unknown?


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


More information about the llvm-commits mailing list