[llvm-branch-commits] [llvm] [BOLT] Add pseudo probe inline tree to YAML profile (PR #107137)

Amir Ayupov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Sep 11 19:10:34 PDT 2024


================
@@ -58,8 +60,164 @@ const BinaryFunction *YAMLProfileWriter::setCSIDestination(
   return nullptr;
 }
 
+std::vector<YAMLProfileWriter::InlineTreeNode>
+YAMLProfileWriter::getInlineTree(const MCPseudoProbeDecoder &Decoder,
+                                 const MCDecodedPseudoProbeInlineTree *Root) {
+  auto getHash = [&](const MCDecodedPseudoProbeInlineTree &Node) {
+    return Decoder.getFuncDescForGUID(Node.Guid)->FuncHash;
+  };
+  assert(Root);
+  std::vector<InlineTreeNode> InlineTree;
+  InlineTreeNode Node{Root, Root->Guid, getHash(*Root), 0, 0};
+  InlineTree.emplace_back(Node);
+  uint32_t ParentId = 0;
+  while (ParentId != InlineTree.size()) {
+    const MCDecodedPseudoProbeInlineTree *Cur = InlineTree[ParentId].InlineTree;
+    for (const MCDecodedPseudoProbeInlineTree &Child : Cur->getChildren()) {
+      InlineTreeNode Node{&Child, Child.Guid, getHash(Child), ParentId,
+                          std::get<1>(Child.getInlineSite())};
+      InlineTree.emplace_back(Node);
+    }
+    ++ParentId;
+  }
+
+  return InlineTree;
+}
+
+std::tuple<yaml::bolt::PseudoProbeDesc, YAMLProfileWriter::InlineTreeDesc>
+YAMLProfileWriter::convertPseudoProbeDesc(const MCPseudoProbeDecoder &Decoder) {
+  yaml::bolt::PseudoProbeDesc Desc;
+  InlineTreeDesc InlineTree;
+
+  for (const MCDecodedPseudoProbeInlineTree &TopLev :
+       Decoder.getDummyInlineRoot().getChildren())
+    InlineTree.TopLevelGUIDToInlineTree[TopLev.Guid] = &TopLev;
+
+  for (const auto &FuncDesc : Decoder.getGUID2FuncDescMap())
+    ++InlineTree.HashIdxMap[FuncDesc.FuncHash];
----------------
aaupov wrote:

HashIdxMap stores unique hashes and we don't know their number beforehand. 

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


More information about the llvm-branch-commits mailing list