[lld] [lld] Report temporal BP profile resolution (PR #212127)

Karim Alweheshy via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 01:28:42 PDT 2026


https://github.com/karim-alweheshy updated https://github.com/llvm/llvm-project/pull/212127

>From f59f6e526a769106835b475b1ce052291651c510 Mon Sep 17 00:00:00 2001
From: Karim Alweheshy <karim.alweheshy at gmail.com>
Date: Sun, 26 Jul 2026 17:23:49 +0200
Subject: [PATCH] lld: report temporal BP profile resolution

---
 .../lld/Common/BPSectionOrdererBase.inc       | 19 +++++++++++++++++++
 lld/test/MachO/bp-section-orderer.s           | 11 ++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lld/include/lld/Common/BPSectionOrdererBase.inc b/lld/include/lld/Common/BPSectionOrdererBase.inc
index 05a5c2446f68c..b2e87d6c240fc 100644
--- a/lld/include/lld/Common/BPSectionOrdererBase.inc
+++ b/lld/include/lld/Common/BPSectionOrdererBase.inc
@@ -24,6 +24,7 @@
 #include "lld/Common/Utils.h"
 #include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallSet.h"
@@ -173,6 +174,9 @@ auto BPOrderer<D>::computeOrder(
   MapVector<unsigned, UtilityNodes> startupSectionIdxUNs;
   // Used to define the initial order for startup functions.
   DenseMap<unsigned, size_t> sectionIdxToTimestamp;
+  uint64_t numProfiledFunctionRefs = 0, numResolvedProfiledFunctionRefs = 0;
+  DenseSet<CachedHashStringRef> uniqueProfiledFunctions;
+  DenseSet<CachedHashStringRef> uniqueResolvedProfiledFunctions;
   std::unique_ptr<InstrProfReader> reader;
   if (!profilePath.empty()) {
     auto fs = vfs::getRealFileSystem();
@@ -198,11 +202,20 @@ auto BPOrderer<D>::computeOrder(
         auto [_, parsedFuncName] = getParsedIRPGOName(
             reader->getSymtab().getFuncOrVarName(trace[timestamp]));
         parsedFuncName = lld::utils::getRootSymbol(parsedFuncName);
+        if (verbose) {
+          ++numProfiledFunctionRefs;
+          uniqueProfiledFunctions.insert(CachedHashStringRef(parsedFuncName));
+        }
 
         auto sectionIdxsIt =
             rootSymbolToSectionIdxs.find(CachedHashStringRef(parsedFuncName));
         if (sectionIdxsIt == rootSymbolToSectionIdxs.end())
           continue;
+        if (verbose) {
+          ++numResolvedProfiledFunctionRefs;
+          uniqueResolvedProfiledFunctions.insert(
+              CachedHashStringRef(parsedFuncName));
+        }
         auto &sectionIdxs = sectionIdxsIt->second;
         // If the same symbol is found in multiple sections, they might be
         // identical, so we arbitrarily use the size from the first section.
@@ -404,6 +417,12 @@ auto BPOrderer<D>::computeOrder(
            << totalOrderedSize << " bytes) using balanced partitioning:\n";
     dbgs() << "  Functions for startup: " << numStartupSections << " ("
            << startupSize << " bytes)\n";
+    if (!profilePath.empty())
+      dbgs() << "  Temporal profile function references: "
+             << numResolvedProfiledFunctionRefs << " / "
+             << numProfiledFunctionRefs << " resolved ("
+             << uniqueResolvedProfiledFunctions.size() << " / "
+             << uniqueProfiledFunctions.size() << " unique)\n";
     dbgs() << "  Sections for compression: " << numCompressionSections << " ("
            << compressionSize << " bytes)\n";
     dbgs() << "  Compression groups: " << groupsForCompression.size() << "\n";
diff --git a/lld/test/MachO/bp-section-orderer.s b/lld/test/MachO/bp-section-orderer.s
index d7de90d6cd7b3..b8c2ac6865b5b 100644
--- a/lld/test/MachO/bp-section-orderer.s
+++ b/lld/test/MachO/bp-section-orderer.s
@@ -10,6 +10,7 @@
 # RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile %t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP
 # RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile=%t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer --icf=all --bp-compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP-ICF
 # STARTUP: Ordered 5 sections ([[#]] bytes) using balanced partitioning
+# STARTUP: Temporal profile function references: 6 / 7 resolved (5 / 6 unique)
 # STARTUP-ICF: Ordered 4 sections ([[#]] bytes) using balanced partitioning
 
 # Check that orderfiles take precedence over BP
@@ -126,7 +127,7 @@ bss0:
 1
 # Weight
 1
-A, B, C.__uniq.555555555555555555555555555555555555555.llvm.6666666666666666666, merged1, merged2
+A, B, A, C.__uniq.555555555555555555555555555555555555555.llvm.6666666666666666666, merged1, merged2, Missing
 
 A
 # Func Hash:
@@ -176,6 +177,14 @@ merged2
 # Counter Values:
 1
 
+Missing
+# Func Hash:
+7777
+# Num Counters:
+1
+# Counter Values:
+1
+
 #--- a.orderfile
 A
 F



More information about the llvm-commits mailing list