[llvm] [MemProf] Add CalleeGUIDs from profile to existing VP metadata (PR #171495)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 15 10:07:52 PST 2025


================
@@ -373,38 +373,57 @@ static void addVPMetadata(Module &M, Instruction &I,
   if (!ClMemProfAttachCalleeGuids || CalleeGuids.empty())
     return;
 
+  // Prepare the vector of value data, initializing from any existing
+  // value-profile metadata present on the instruction so that we merge the
+  // new CalleeGuids into the existing entries.
+  SmallVector<InstrProfValueData, 8> VDs;
+  uint64_t TotalCount = 0;
+
   if (I.getMetadata(LLVMContext::MD_prof)) {
-    uint64_t Unused;
-    // TODO: When merging is implemented, increase this to a typical ICP value
-    // (e.g., 3-6) For now, we only need to check if existing data exists, so 1
-    // is sufficient
-    auto ExistingVD = getValueProfDataFromInst(I, IPVK_IndirectCallTarget,
-                                               /*MaxNumValueData=*/1, Unused);
-    // We don't know how to merge value profile data yet.
-    if (!ExistingVD.empty()) {
-      return;
+    // Read all existing entries so we can merge them. Use a large
+    // MaxNumValueData to retrieve all existing entries.
+    VDs = getValueProfDataFromInst(I, IPVK_IndirectCallTarget,
+                                   /*MaxNumValueData=*/UINT32_MAX, TotalCount);
+  }
+
+  // Save the original size for use later in detecting whether any were added.
+  auto OriginalSize = VDs.size();
----------------
teresajohnson wrote:

done. but in general, why not use auto (with const added as would be appropriate here)? It is a good convenience so I don't need to look up the exact type returned.

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


More information about the llvm-commits mailing list