[llvm] [MemProf][PGO] Prevent dropping of profile metadata during optimization (PR #121359)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 09:32:47 PST 2025


================
@@ -347,3 +347,24 @@ template <> uint64_t CallStack<MDNode, MDNode::op_iterator>::back() const {
   return mdconst::dyn_extract<ConstantInt>(N->operands().back())
       ->getZExtValue();
 }
+
+MDNode *MDNode::getMergedMemProfMetadata(MDNode *A, MDNode *B) {
+  if (!(A && B)) {
+    return A ? A : B;
+  }
+
+  // TODO: Support more sophisticated merging, such as selecting the one with
+  // more bytes allocated, or implement support for carrying multiple allocation
+  // leaf contexts. For now, keep the first one.
+  return A;
----------------
snehasish wrote:

This logic is a little hard to read. Can this be replaced with --
```
if(A) return A;
return B;
```

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


More information about the llvm-commits mailing list