[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
Thu Sep 12 16:04:10 PDT 2024


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

>From 50c021b09950cf7d6a8f25b1ac0dec246f2325f5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 3 Sep 2024 11:38:04 -0700
Subject: [PATCH 1/6] update pseudoprobe-decoding-inline.test

Created using spr 1.3.4
---
 .../test/X86/pseudoprobe-decoding-inline.test | 31 ++++++++++++-------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/bolt/test/X86/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test
index 1fdd00c7ef6c4b..629dd84ab8e1dc 100644
--- a/bolt/test/X86/pseudoprobe-decoding-inline.test
+++ b/bolt/test/X86/pseudoprobe-decoding-inline.test
@@ -14,29 +14,38 @@
 # RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML
 # CHECK-YAML: name: bar
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   pseudo_probes: [ { guid: 0xE413754A191DB537, id: 1, type: 0 }, { guid: 0xE413754A191DB537, id: 4, type: 0 } ]
-# CHECK-YAML: guid: 0xE413754A191DB537
-# CHECK-YAML: pseudo_probe_desc_hash: 0x10E852DA94
+# CHECK-YAML:      pseudo_probes:
+# CHECK-YAML-NEXT:   - { id: 1, type: 0
+# CHECK-YAML-NEXT:   - { id: 4, type: 0
+# CHECK-YAML:      inline_tree:
+# CHECK-YAML-NEXT:   - { guid: 0xE413754A191DB537, hash: 0x10E852DA94, id: 0 }
 #
 # CHECK-YAML: name: foo
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   pseudo_probes: [ { guid: 0x5CF8C24CDB18BDAC, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 2, type: 0 } ]
-# CHECK-YAML: guid: 0x5CF8C24CDB18BDAC
-# CHECK-YAML: pseudo_probe_desc_hash: 0x200205A19C5B4
+# CHECK-YAML:      pseudo_probes:
+# CHECK-YAML-NEXT: - { id: 1, type: 0 }
+# CHECK-YAML-NEXT: - { id: 2, type: 0 }
+# CHECK-YAML:      inline_tree:
+# CHECK-YAML-NEXT:   - { guid: 0x5CF8C24CDB18BDAC, hash: 0x200205A19C5B4, id: 0 }
+# CHECK-YAML-NEXT:   - { guid: 0xE413754A191DB537, hash: 0x10E852DA94, id: 1, callsite: 8 }
 #
 # CHECK-YAML: name: main
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   pseudo_probes: [ { guid: 0xDB956436E78DD5FA, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 2, type: 0 } ]
-# CHECK-YAML: guid: 0xDB956436E78DD5FA
-# CHECK-YAML: pseudo_probe_desc_hash: 0x10000FFFFFFFF
+# CHECK-YAML:      pseudo_probes:
+# CHECK-YAML-NEXT: - { id: 1, type: 0 }
+# CHECK-YAML-NEXT: - { id: 1, type: 0, inline_tree_id: 1 }
+# CHECK-YAML-NEXT: - { id: 2, type: 0, inline_tree_id: 1 }
+# CHECK-YAML:      inline_tree:
+# CHECK-YAML-NEXT:   - { guid: 0xDB956436E78DD5FA, hash: 0x10000FFFFFFFF, id: 0 }
+# CHECK-YAML-NEXT:   - { guid: 0x5CF8C24CDB18BDAC, hash: 0x200205A19C5B4, id: 1, callsite: 2 }
+# CHECK-YAML-NEXT:   - { guid: 0xE413754A191DB537, hash: 0x10E852DA94, id: 2, parent: 1, callsite: 8 }
 #
 ## Check that without --profile-write-pseudo-probes option, no pseudo probes are
 ## generated
 # RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
 # RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-NO-OPT
 # CHECK-NO-OPT-NOT: pseudo_probes
-# CHECK-NO-OPT-NOT: guid
-# CHECK-NO-OPT-NOT: pseudo_probe_desc_hash
+# CHECK-NO-OPT-NOT: inline_tree
 
 CHECK: Report of decoding input pseudo probe binaries
 

>From 6ec4cf6bf05551d02cbf17e9edbe8d6931588ff1 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 9 Sep 2024 21:37:28 -0700
Subject: [PATCH 2/6] clang-format

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileWriter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp
index 70e5e09e2920e5..f2609de18ce63c 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -90,7 +90,7 @@ YAMLProfileWriter::convertPseudoProbeDesc(const MCPseudoProbeDecoder &Decoder) {
   InlineTreeDesc InlineTree;
 
   for (const MCDecodedPseudoProbeInlineTree &TopLev :
-      Decoder.getDummyInlineRoot().getChildren())
+       Decoder.getDummyInlineRoot().getChildren())
     InlineTree.TopLevelGUIDToInlineTree[TopLev.Guid] = &TopLev;
 
   for (const auto &FuncDesc : Decoder.getGUID2FuncDescMap())

>From 852eb07f345dd1d9e77a6faead8bf0f73ff64ba7 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 10 Sep 2024 12:26:11 -0700
Subject: [PATCH 3/6] Make pseudo_probe_desc optional

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/ProfileYAMLMapping.h | 9 ++++++++-
 bolt/test/X86/pseudoprobe-decoding-inline.test | 5 +++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index 588e2f59d67e01..9cc33264d70718 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -275,6 +275,12 @@ struct PseudoProbeDesc {
   std::vector<Hex64> GUID;
   std::vector<Hex64> Hash;
   std::vector<uint32_t> GUIDHash; // Index of hash for that GUID in Hash
+
+  bool operator==(const PseudoProbeDesc &Other) const {
+    // Only treat empty Desc as equal
+    return GUID.empty() && Other.GUID.empty() && Hash.empty() &&
+           Other.Hash.empty() && GUIDHash.empty() && Other.GUIDHash.empty();
+  }
 };
 } // end namespace bolt
 
@@ -306,7 +312,8 @@ template <> struct MappingTraits<bolt::BinaryProfile> {
   static void mapping(IO &YamlIO, bolt::BinaryProfile &BP) {
     YamlIO.mapRequired("header", BP.Header);
     YamlIO.mapRequired("functions", BP.Functions);
-    YamlIO.mapOptional("pseudo_probe_desc", BP.PseudoProbeDesc);
+    YamlIO.mapOptional("pseudo_probe_desc", BP.PseudoProbeDesc,
+                       bolt::PseudoProbeDesc());
   }
 };
 
diff --git a/bolt/test/X86/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test
index 0a99795d32935a..87e6fa59b07077 100644
--- a/bolt/test/X86/pseudoprobe-decoding-inline.test
+++ b/bolt/test/X86/pseudoprobe-decoding-inline.test
@@ -36,8 +36,9 @@
 ## generated
 # RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
 # RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-NO-OPT
-# CHECK-NO-OPT-NOT: pseudo_probes
-# CHECK-NO-OPT-NOT: inline_tree
+# CHECK-NO-OPT-NOT: probes:
+# CHECK-NO-OPT-NOT: inline_tree:
+# CHECK-NO-OPT-NOT: pseudo_probe_desc:
 
 CHECK: Report of decoding input pseudo probe binaries
 

>From 65c2b99aaaecd272d48e6af6955c439d7d045b70 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 11 Sep 2024 19:56:11 -0700
Subject: [PATCH 4/6] Address comments

Created using spr 1.3.4
---
 .../include/bolt/Profile/ProfileYAMLMapping.h | 35 ++++++++--------
 bolt/include/bolt/Profile/YAMLProfileWriter.h | 12 +++---
 bolt/lib/Profile/YAMLProfileWriter.cpp        | 41 +++++++++----------
 .../test/X86/pseudoprobe-decoding-inline.test | 12 +++---
 4 files changed, 49 insertions(+), 51 deletions(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index 9cc33264d70718..ee39051cbc136d 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -98,7 +98,7 @@ struct PseudoProbeInfo {
   uint32_t InlineTreeIndex = 0;
   uint64_t BlockMask = 0; // bitset with probe indices
   // Assume BlockMask == 1 if no other probes are set
-  std::vector<uint64_t> BlockProbes;
+  std::vector<uint64_t> BlockProbes; // block probes with indices above 64
   std::vector<uint64_t> CallProbes;
   std::vector<uint64_t> IndCallProbes;
   std::vector<uint32_t> InlineTreeNodes;
@@ -113,10 +113,10 @@ struct PseudoProbeInfo {
 
 template <> struct MappingTraits<bolt::PseudoProbeInfo> {
   static void mapping(IO &YamlIO, bolt::PseudoProbeInfo &PI) {
-    YamlIO.mapOptional("blk", PI.BlockMask, 0);
-    YamlIO.mapOptional("blks", PI.BlockProbes, std::vector<uint64_t>());
-    YamlIO.mapOptional("calls", PI.CallProbes, std::vector<uint64_t>());
-    YamlIO.mapOptional("indcalls", PI.IndCallProbes, std::vector<uint64_t>());
+    YamlIO.mapOptional("blx", PI.BlockMask, 0);
+    YamlIO.mapOptional("blk", PI.BlockProbes, std::vector<uint64_t>());
+    YamlIO.mapOptional("call", PI.CallProbes, std::vector<uint64_t>());
+    YamlIO.mapOptional("icall", PI.IndCallProbes, std::vector<uint64_t>());
     YamlIO.mapOptional("id", PI.InlineTreeIndex, 0);
     YamlIO.mapOptional("ids", PI.InlineTreeNodes, std::vector<uint32_t>());
   }
@@ -170,18 +170,18 @@ template <> struct MappingTraits<bolt::BinaryBasicBlockProfile> {
 };
 
 namespace bolt {
-struct InlineTreeInfo {
+struct InlineTreeNode {
   uint32_t ParentIndexDelta;
   uint32_t CallSiteProbe;
-  // Index in PseudoProbeDesc.GUID + 1, 0 for same as previous
+  // Index in PseudoProbeDesc.GUID, UINT32_MAX for same as previous (omitted)
   uint32_t GUIDIndex;
-  bool operator==(const InlineTreeInfo &) const { return false; }
+  bool operator==(const InlineTreeNode &) const { return false; }
 };
 } // end namespace bolt
 
-template <> struct MappingTraits<bolt::InlineTreeInfo> {
-  static void mapping(IO &YamlIO, bolt::InlineTreeInfo &ITI) {
-    YamlIO.mapOptional("g", ITI.GUIDIndex, 0);
+template <> struct MappingTraits<bolt::InlineTreeNode> {
+  static void mapping(IO &YamlIO, bolt::InlineTreeNode &ITI) {
+    YamlIO.mapOptional("g", ITI.GUIDIndex, UINT32_MAX);
     YamlIO.mapOptional("p", ITI.ParentIndexDelta, 0);
     YamlIO.mapOptional("cs", ITI.CallSiteProbe, 0);
   }
@@ -192,7 +192,7 @@ template <> struct MappingTraits<bolt::InlineTreeInfo> {
 } // end namespace llvm
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::bolt::BinaryBasicBlockProfile)
-LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::InlineTreeInfo)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::InlineTreeNode)
 
 namespace llvm {
 namespace yaml {
@@ -205,7 +205,7 @@ struct BinaryFunctionProfile {
   llvm::yaml::Hex64 Hash{0};
   uint64_t ExecCount{0};
   std::vector<BinaryBasicBlockProfile> Blocks;
-  std::vector<InlineTreeInfo> InlineTree;
+  std::vector<InlineTreeNode> InlineTree;
   bool Used{false};
 };
 } // end namespace bolt
@@ -220,7 +220,7 @@ template <> struct MappingTraits<bolt::BinaryFunctionProfile> {
     YamlIO.mapOptional("blocks", BFP.Blocks,
                        std::vector<bolt::BinaryBasicBlockProfile>());
     YamlIO.mapOptional("inline_tree", BFP.InlineTree,
-                       std::vector<bolt::InlineTreeInfo>());
+                       std::vector<bolt::InlineTreeNode>());
   }
 };
 
@@ -274,12 +274,13 @@ namespace bolt {
 struct PseudoProbeDesc {
   std::vector<Hex64> GUID;
   std::vector<Hex64> Hash;
-  std::vector<uint32_t> GUIDHash; // Index of hash for that GUID in Hash
+  std::vector<uint32_t> GUIDHashIdx; // Index of hash for that GUID in Hash
 
   bool operator==(const PseudoProbeDesc &Other) const {
     // Only treat empty Desc as equal
     return GUID.empty() && Other.GUID.empty() && Hash.empty() &&
-           Other.Hash.empty() && GUIDHash.empty() && Other.GUIDHash.empty();
+           Other.Hash.empty() && GUIDHashIdx.empty() &&
+           Other.GUIDHashIdx.empty();
   }
 };
 } // end namespace bolt
@@ -287,7 +288,7 @@ struct PseudoProbeDesc {
 template <> struct MappingTraits<bolt::PseudoProbeDesc> {
   static void mapping(IO &YamlIO, bolt::PseudoProbeDesc &PD) {
     YamlIO.mapRequired("gs", PD.GUID);
-    YamlIO.mapRequired("gh", PD.GUIDHash);
+    YamlIO.mapRequired("gh", PD.GUIDHashIdx);
     YamlIO.mapRequired("hs", PD.Hash);
   }
 };
diff --git a/bolt/include/bolt/Profile/YAMLProfileWriter.h b/bolt/include/bolt/Profile/YAMLProfileWriter.h
index d691fe6b5a4ce9..aec6e474847605 100644
--- a/bolt/include/bolt/Profile/YAMLProfileWriter.h
+++ b/bolt/include/bolt/Profile/YAMLProfileWriter.h
@@ -43,18 +43,18 @@ class YAMLProfileWriter {
     GUIDNumMap HashIdxMap;
   };
 
-  static std::tuple<std::vector<yaml::bolt::InlineTreeInfo>, InlineTreeMapTy>
+  static std::tuple<std::vector<yaml::bolt::InlineTreeNode>, InlineTreeMapTy>
   convertBFInlineTree(const MCPseudoProbeDecoder &Decoder,
                       const InlineTreeDesc &InlineTree, uint64_t GUID);
 
+  static std::tuple<yaml::bolt::PseudoProbeDesc, InlineTreeDesc>
+  convertPseudoProbeDesc(const MCPseudoProbeDecoder &PseudoProbeDecoder);
+
   static yaml::bolt::BinaryFunctionProfile
   convert(const BinaryFunction &BF, bool UseDFS,
           const InlineTreeDesc &InlineTree,
           const BoltAddressTranslation *BAT = nullptr);
 
-  static std::tuple<yaml::bolt::PseudoProbeDesc, InlineTreeDesc>
-  convertPseudoProbeDesc(const MCPseudoProbeDecoder &PseudoProbeDecoder);
-
   /// Set CallSiteInfo destination fields from \p Symbol and return a target
   /// BinaryFunction for that symbol.
   static const BinaryFunction *
@@ -71,8 +71,8 @@ class YAMLProfileWriter {
     uint32_t InlineSite;
   };
   static std::vector<InlineTreeNode>
-  getInlineTree(const MCPseudoProbeDecoder &Decoder,
-                const MCDecodedPseudoProbeInlineTree *Root);
+  collectInlineTree(const MCPseudoProbeDecoder &Decoder,
+                    const MCDecodedPseudoProbeInlineTree &Root);
 
   // 0 - block probe, 1 - indirect call, 2 - direct call
   using ProbeList = std::array<SmallVector<uint64_t, 0>, 3>;
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp
index f2609de18ce63c..072a23631d04a5 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -18,7 +18,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/raw_ostream.h"
-#include <queue>
 
 #undef  DEBUG_TYPE
 #define DEBUG_TYPE "bolt-prof"
@@ -61,23 +60,21 @@ const BinaryFunction *YAMLProfileWriter::setCSIDestination(
 }
 
 std::vector<YAMLProfileWriter::InlineTreeNode>
-YAMLProfileWriter::getInlineTree(const MCPseudoProbeDecoder &Decoder,
-                                 const MCDecodedPseudoProbeInlineTree *Root) {
+YAMLProfileWriter::collectInlineTree(
+    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);
+  std::vector<InlineTreeNode> InlineTree(
+      {InlineTreeNode{&Root, Root.Guid, getHash(Root), 0, 0}});
   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);
-    }
+    for (const MCDecodedPseudoProbeInlineTree &Child : Cur->getChildren())
+      InlineTree.emplace_back(
+          InlineTreeNode{&Child, Child.Guid, getHash(Child), ParentId,
+                         std::get<1>(Child.getInlineSite())});
     ++ParentId;
   }
 
@@ -125,7 +122,7 @@ YAMLProfileWriter::convertPseudoProbeDesc(const MCPseudoProbeDecoder &Decoder) {
     Desc.GUID.emplace_back(GUID);
     InlineTree.GUIDIdxMap[GUID] = Index++;
     uint64_t Hash = Decoder.getFuncDescForGUID(GUID)->FuncHash;
-    Desc.GUIDHash.emplace_back(InlineTree.HashIdxMap[Hash]);
+    Desc.GUIDHashIdx.emplace_back(InlineTree.HashIdxMap[Hash]);
   }
 
   return {Desc, InlineTree};
@@ -184,31 +181,31 @@ YAMLProfileWriter::convertNodeProbes(NodeIdToProbes &NodeProbes) {
   return YamlProbes;
 }
 
-std::tuple<std::vector<yaml::bolt::InlineTreeInfo>,
+std::tuple<std::vector<yaml::bolt::InlineTreeNode>,
            YAMLProfileWriter::InlineTreeMapTy>
 YAMLProfileWriter::convertBFInlineTree(const MCPseudoProbeDecoder &Decoder,
                                        const InlineTreeDesc &InlineTree,
                                        uint64_t GUID) {
   DenseMap<const MCDecodedPseudoProbeInlineTree *, uint32_t> InlineTreeNodeId;
-  std::vector<yaml::bolt::InlineTreeInfo> YamlInlineTree;
+  std::vector<yaml::bolt::InlineTreeNode> YamlInlineTree;
   auto It = InlineTree.TopLevelGUIDToInlineTree.find(GUID);
   if (It == InlineTree.TopLevelGUIDToInlineTree.end())
     return {YamlInlineTree, InlineTreeNodeId};
   const MCDecodedPseudoProbeInlineTree *Root = It->second;
-  assert(Root);
+  assert(Root && "Malformed TopLevelGUIDToInlineTree");
   uint32_t Index = 0;
   uint32_t PrevParent = 0;
-  uint32_t PrevGUIDIdx = 0;
-  for (const auto &Node : getInlineTree(Decoder, Root)) {
+  uint32_t PrevGUIDIdx = UINT32_MAX;
+  for (const auto &Node : collectInlineTree(Decoder, *Root)) {
     InlineTreeNodeId[Node.InlineTree] = Index++;
     auto GUIDIdxIt = InlineTree.GUIDIdxMap.find(Node.GUID);
-    assert(GUIDIdxIt != InlineTree.GUIDIdxMap.end());
-    uint32_t GUIDIdx = GUIDIdxIt->second + 1;
+    assert(GUIDIdxIt != InlineTree.GUIDIdxMap.end() && "Malformed GUIDIdxMap");
+    uint32_t GUIDIdx = GUIDIdxIt->second;
     if (GUIDIdx == PrevGUIDIdx)
-      GUIDIdx = 0;
+      GUIDIdx = UINT32_MAX;
     else
       PrevGUIDIdx = GUIDIdx;
-    YamlInlineTree.emplace_back(yaml::bolt::InlineTreeInfo{
+    YamlInlineTree.emplace_back(yaml::bolt::InlineTreeNode{
         Node.ParentId - PrevParent, Node.InlineSite, GUIDIdx});
     PrevParent = Node.ParentId;
   }
diff --git a/bolt/test/X86/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test
index 87e6fa59b07077..c8bdce927ce124 100644
--- a/bolt/test/X86/pseudoprobe-decoding-inline.test
+++ b/bolt/test/X86/pseudoprobe-decoding-inline.test
@@ -14,18 +14,18 @@
 # RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML
 # CHECK-YAML: name: bar
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   probes: [ { blk: 9 } ]
-# CHECK-YAML: inline_tree: [ { g: 1 } ]
+# CHECK-YAML:   probes: [ { blx: 9 } ]
+# CHECK-YAML: inline_tree: [ { g: 0 } ]
 #
 # CHECK-YAML: name: foo
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   probes: [ { blk: 3 } ]
-# CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 8 } ]
+# CHECK-YAML:   probes: [ { blx: 3 } ]
+# CHECK-YAML: inline_tree: [ { g: 1 }, { g: 0, cs: 8 } ]
 #
 # CHECK-YAML: name: main
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   probes: [ { blk: 3, id: 1 }, {  } ]
-# CHECK-YAML: inline_tree: [ { g: 3 }, { g: 2, cs: 2 }, { g: 1, p: 1, cs: 8 } ]
+# CHECK-YAML:   probes: [ { blx: 3, id: 1 }, {  } ]
+# CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 2 }, { g: 0, p: 1, cs: 8 } ]
 #
 # CHECK-YAML: pseudo_probe_desc:
 # CHECK-YAML-NEXT: gs: [ 0xE413754A191DB537, 0x5CF8C24CDB18BDAC, 0xDB956436E78DD5FA ]

>From 7c90ed65e98968f2646a187132bc72962c4f1315 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 11 Sep 2024 20:41:17 -0700
Subject: [PATCH 5/6] Drop Block1 optimization

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/ProfileYAMLMapping.h | 3 +--
 bolt/lib/Profile/YAMLProfileWriter.cpp         | 6 +-----
 bolt/test/X86/pseudoprobe-decoding-inline.test | 4 ++--
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index ee39051cbc136d..cae00e37bf27ed 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -96,8 +96,7 @@ template <> struct MappingTraits<bolt::SuccessorInfo> {
 namespace bolt {
 struct PseudoProbeInfo {
   uint32_t InlineTreeIndex = 0;
-  uint64_t BlockMask = 0; // bitset with probe indices
-  // Assume BlockMask == 1 if no other probes are set
+  uint64_t BlockMask = 0; // bitset with probe indices from 1 to 64
   std::vector<uint64_t> BlockProbes; // block probes with indices above 64
   std::vector<uint64_t> CallProbes;
   std::vector<uint64_t> IndCallProbes;
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp
index 072a23631d04a5..44600c3c5d5ef7 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -173,10 +173,6 @@ YAMLProfileWriter::convertNodeProbes(NodeIdToProbes &NodeProbes) {
     else
       YamlBPI.InlineTreeNodes = Nodes;
     handleMask(BPI.BlockProbes, YamlBPI.BlockProbes, YamlBPI.BlockMask);
-    // Assume BlockMask == 1 if no other probes are set
-    if (YamlBPI.BlockMask == 1 && YamlBPI.CallProbes.empty() &&
-        YamlBPI.IndCallProbes.empty())
-      YamlBPI.BlockMask = 0;
   }
   return YamlProbes;
 }
@@ -195,7 +191,7 @@ YAMLProfileWriter::convertBFInlineTree(const MCPseudoProbeDecoder &Decoder,
   assert(Root && "Malformed TopLevelGUIDToInlineTree");
   uint32_t Index = 0;
   uint32_t PrevParent = 0;
-  uint32_t PrevGUIDIdx = UINT32_MAX;
+  uint32_t PrevGUIDIdx = 0;
   for (const auto &Node : collectInlineTree(Decoder, *Root)) {
     InlineTreeNodeId[Node.InlineTree] = Index++;
     auto GUIDIdxIt = InlineTree.GUIDIdxMap.find(Node.GUID);
diff --git a/bolt/test/X86/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test
index c8bdce927ce124..ec1172573c186a 100644
--- a/bolt/test/X86/pseudoprobe-decoding-inline.test
+++ b/bolt/test/X86/pseudoprobe-decoding-inline.test
@@ -15,7 +15,7 @@
 # CHECK-YAML: name: bar
 # CHECK-YAML: - bid: 0
 # CHECK-YAML:   probes: [ { blx: 9 } ]
-# CHECK-YAML: inline_tree: [ { g: 0 } ]
+# CHECK-YAML: inline_tree: [ { } ]
 #
 # CHECK-YAML: name: foo
 # CHECK-YAML: - bid: 0
@@ -24,7 +24,7 @@
 #
 # CHECK-YAML: name: main
 # CHECK-YAML: - bid: 0
-# CHECK-YAML:   probes: [ { blx: 3, id: 1 }, {  } ]
+# CHECK-YAML:   probes: [ { blx: 3, id: 1 }, { blx: 1 } ]
 # CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 2 }, { g: 0, p: 1, cs: 8 } ]
 #
 # CHECK-YAML: pseudo_probe_desc:

>From 7331abae2b65894d2f1e60dea1f385ce8dc85bce Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 11 Sep 2024 20:47:06 -0700
Subject: [PATCH 6/6] clang-format

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/ProfileYAMLMapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index cae00e37bf27ed..91955afb186e90 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -96,7 +96,7 @@ template <> struct MappingTraits<bolt::SuccessorInfo> {
 namespace bolt {
 struct PseudoProbeInfo {
   uint32_t InlineTreeIndex = 0;
-  uint64_t BlockMask = 0; // bitset with probe indices from 1 to 64
+  uint64_t BlockMask = 0;            // bitset with probe indices from 1 to 64
   std::vector<uint64_t> BlockProbes; // block probes with indices above 64
   std::vector<uint64_t> CallProbes;
   std::vector<uint64_t> IndCallProbes;



More information about the llvm-branch-commits mailing list