================
@@ -592,72 +633,276 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
   return MatchedWithCallGraph;
 }
 
-size_t YAMLProfileReader::InlineTreeNodeMapTy::matchInlineTrees(
-    const MCPseudoProbeDecoder &Decoder,
-    const std::vector<yaml::bolt::InlineTreeNode> &DecodedInlineTree,
-    const MCDecodedPseudoProbeInlineTree *Root) {
-  // Match inline tree nodes by GUID, checksum, parent, and call site.
-  for (const auto &[InlineTreeNodeId, InlineTreeNode] :
-       llvm::enumerate(DecodedInlineTree)) {
-    uint64_t GUID = InlineTreeNode.GUID;
-    uint64_t Hash = InlineTreeNode.Hash;
-    uint32_t ParentId = InlineTreeNode.ParentIndexDelta;
-    uint32_t CallSiteProbe = InlineTreeNode.CallSiteProbe;
-    const MCDecodedPseudoProbeInlineTree *Cur = nullptr;
-    if (!InlineTreeNodeId) {
-      Cur = Root;
-    } else if (const MCDecodedPseudoProbeInlineTree *Parent =
-                   getInlineTreeNode(ParentId)) {
-      for (const MCDecodedPseudoProbeInlineTree &Child :
-           Parent->getChildren()) {
-        if (Child.Guid == GUID) {
-          if (std::get<1>(Child.getInlineSite()) == CallSiteProbe)
-            Cur = &Child;
-          break;
-        }
+const MCDecodedPseudoProbeInlineTree *
+YAMLProfileReader::lookupTopLevelNode(const BinaryFunction &BF) {
+  const BinaryContext &BC = BF.getBinaryContext();
+  const MCPseudoProbeDecoder *Decoder = BC.getPseudoProbeDecoder();
+  assert(Decoder &&
+         "If pseudo probes are in use, pseudo probe decoder should exist");
+  uint64_t Addr = BF.getAddress();
+  uint64_t Size = BF.getSize();
+  auto Probes = Decoder->getAddress2ProbesMap().find(Addr, Addr + Size);
+  if (Probes.empty())
+    return nullptr;
+  const MCDecodedPseudoProbe &Probe = *Probes.begin();
+  const MCDecodedPseudoProbeInlineTree *Root = Probe.getInlineTreeNode();
+  while (Root->hasInlineSite())
+    Root = (const MCDecodedPseudoProbeInlineTree *)Root->Parent;
+  return Root;
+}
+
+size_t YAMLProfileReader::matchInlineTreesImpl(
+    BinaryFunction &BF, yaml::bolt::BinaryFunctionProfile &YamlBF,
+    const MCDecodedPseudoProbeInlineTree &Root, uint32_t RootIdx,
+    ArrayRef<yaml::bolt::InlineTreeNode> ProfileInlineTree,
+    MutableArrayRef<const MCDecodedPseudoProbeInlineTree *> Map, float Scale) {
+  using namespace yaml::bolt;
+  BinaryContext &BC = BF.getBinaryContext();
+  const MCPseudoProbeDecoder &Decoder = *BC.getPseudoProbeDecoder();
+  const InlineTreeNode &FuncNode = ProfileInlineTree[RootIdx];
+
+  using ChildMapTy =
+      std::unordered_map<InlineSite, const MCDecodedPseudoProbeInlineTree *,
+                         InlineSiteHash>;
+  using CallSiteInfoTy =
+      std::unordered_map<InlineSite, const CallSiteInfo *, InlineSiteHash>;
+  // Mapping from a parent node id to a map InlineSite -> Child node.
+  DenseMap<uint32_t, ChildMapTy> ParentToChildren;
+  // Collect calls in the profile: map from a parent node id to a map
+  // InlineSite -> CallSiteInfo ptr.
+  DenseMap<uint32_t, CallSiteInfoTy> ParentToCSI;
+  for (const BinaryBasicBlockProfile &YamlBB : YamlBF.Blocks) {
+    // Collect callees for inlined profile matching, indexed by InlineSite.
+    for (const CallSiteInfo &CSI : YamlBB.CallSites) {
+      ProbeMatchingStats.TotalCallCount += CSI.Count;
+      ++ProbeMatchingStats.TotalCallSites;
+      if (CSI.Probe == 0) {
+        LLVM_DEBUG(dbgs() << "no probe for " << CSI.DestId << " " << CSI.Count
----------------
maksfb wrote:

```suggestion
        LLVM_DEBUG(dbgs() << "BOLT-DEBUG: no probe for " << CSI.DestId << " " 
<< CSI.Count
```

https://github.com/llvm/llvm-project/pull/100446
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to