[llvm] [MemProf] Attach value profile metadata to the IR using CalleeGuids. (PR #141164)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri May 30 22:32:16 PDT 2025


================
@@ -964,6 +970,41 @@ undriftMemProfRecord(const DenseMap<uint64_t, LocToLocMap> &UndriftMaps,
     UndriftCallStack(CS.Frames);
 }
 
+// Helper function to process CalleeGuids and create value profile metadata
+static void addVPMetadata(Module &M, Instruction &I,
+                          ArrayRef<GlobalValue::GUID> CalleeGuids) {
+  if (!ClMemProfAttachCalleeGuids || CalleeGuids.empty())
+    return;
+
+  if (I.getMetadata(LLVMContext::MD_prof)) {
+    uint64_t Unused;
+    auto ExistingVD =
+        getValueProfDataFromInst(I, IPVK_IndirectCallTarget, ~0U, Unused);
+    // We don't know how to merge value profile data yet.
+    if (!ExistingVD.empty()) {
+      return;
+    }
+  }
+
+  SmallVector<InstrProfValueData, 4> VDs;
+  uint64_t TotalCount = 0;
+
+  for (const GlobalValue::GUID CalleeGUID : CalleeGuids) {
+    InstrProfValueData VD;
+    VD.Value = CalleeGUID;
+    // For MemProf, we don't have actual call counts, so we assign
+    // a weight of 1 to each potential target.
----------------
snehasish wrote:

Added TODO.

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


More information about the llvm-commits mailing list