[llvm-branch-commits] [llvm] [BOLT] Match blocks with pseudo probes (PR #99891)

Lei Wang via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 25 16:57:04 PDT 2024


================
@@ -266,6 +325,122 @@ class StaleMatcher {
     }
     return BestBlock;
   }
+
+  /// A helper function for logging.
+  static bool LogErrIfExpr(bool Expr, StringRef Message) {
+    if (Expr)
+      errs() << Message;
+    return Expr;
+  }
+
+  /// Matches an inlined profile block with an inlined binary block based on
+  /// pseudo probes.
+  const FlowBlock *matchWithInlinedBlockPseudoProbes(
+      SmallVector<const yaml::bolt::PseudoProbeInfo *>
+          &InlinedBlockPseudoProbes) const {
+    if (opts::Verbosity >= 3)
+      outs() << "BOLT-INFO: attempting to match block with inlined block "
+                "pseudo probes\n";
+
+    size_t NInlinedBlockPseudoProbes = InlinedBlockPseudoProbes.size();
+    if (LogErrIfExpr(NInlinedBlockPseudoProbes == 0,
+                     "BOLT-WARNING: no pseudo probes in profile block\n"))
+      return nullptr;
+    if (LogErrIfExpr(
+            NInlinedBlockPseudoProbes > 1,
+            "BOLT-WARNING: more than 1 pseudo probes in profile block\n"))
+      return nullptr;
+
+    const auto *InlinedPseudoProbe = InlinedBlockPseudoProbes[0];
+    uint64_t Guid = InlinedPseudoProbe->GUID;
+    uint64_t Index = InlinedPseudoProbe->Index;
+
+    auto GuidIt = IndexAndGUIDToInlinedProbes.find(Guid);
+    if (LogErrIfExpr(
+            GuidIt == IndexAndGUIDToInlinedProbes.end(),
+            "BOLT-WARNING: no pseudo probes found within BB at index\n"))
+      return nullptr;
+    auto IndexIt = GuidIt->second.find(Index);
+    if (LogErrIfExpr(
+            IndexIt == GuidIt->second.end(),
+            "BOLT-WARNING: no pseudo probes found within BB at index\n"))
+      return nullptr;
+
+    if (LogErrIfExpr(
+            IndexIt->second.size() > 1,
+            "BOLT-WARNING: more than 1 block pseudo probes in BB at index\n"))
+      return nullptr;
+
+    const MCDecodedPseudoProbe *BinaryPseudoProbe = IndexIt->second[0];
+    auto BinaryPseudoProbeIt = BBPseudoProbeToBlock.find(BinaryPseudoProbe);
+    assert(BinaryPseudoProbeIt != BBPseudoProbeToBlock.end() &&
+           "All binary pseudo probes should belong a binary basic block");
+
+    return BinaryPseudoProbeIt->second;
+  }
+
+  /// Matches a profile block with an binary block based on pseudo probes.
+  const FlowBlock *matchWithNonInlinedBlockPseudoProbes(
+      SmallVector<const yaml::bolt::PseudoProbeInfo *> &BlockPseudoProbes)
+      const {
+    if (opts::Verbosity >= 3)
+      outs() << "BOLT-INFO: attempting to match block with inlined block "
+                "pseudo probes\n";
+
+    size_t NBlockPseudoProbes = BlockPseudoProbes.size();
+    if (LogErrIfExpr(NBlockPseudoProbes == 0,
+                     "BOLT-WARNING: no pseudo probes in profile block\n"))
+      return nullptr;
+    if (LogErrIfExpr(
+            NBlockPseudoProbes > 1,
----------------
wlei-llvm wrote:

Same here

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


More information about the llvm-branch-commits mailing list