[llvm-branch-commits] [llvm] [BOLT] Impute missing trace fall-through (PR #145258)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 10 21:08:57 PDT 2025


================
@@ -529,6 +534,49 @@ void DataAggregator::parsePerfData(BinaryContext &BC) {
   deleteTempFiles();
 }
 
+void DataAggregator::imputeFallThroughs() {
+  if (Traces.empty())
+    return;
+
+  std::pair PrevBranch(Trace::EXTERNAL, Trace::EXTERNAL);
+  uint64_t AggregateCount = 0;
+  uint64_t AggregateFallthroughSize = 0;
+  uint64_t InferredTraces = 0;
+
+  // Helper map with whether the instruction is a call/ret/unconditional branch
+  std::unordered_map<uint64_t, bool> IsUncondJumpMap;
+  auto checkUncondJump = [&](const uint64_t Addr) {
+    auto isUncondJump = [&](const MCInst &MI) -> bool {
+      return BC->MIB->IsUnconditionalJump(MI);
+    };
+    return testAndSet<bool>(Addr, isUncondJump, IsUncondJumpMap).value_or(true);
+  };
+
+  for (auto &[Trace, Info] : Traces) {
+    if (Trace.From == Trace::EXTERNAL)
+      continue;
+    std::pair CurrentBranch(Trace.Branch, Trace.From);
+    if (Trace.To == Trace::BR_ONLY) {
+      uint64_t InferredBytes = PrevBranch == CurrentBranch
----------------
ShatianWang wrote:

nit: could you add a comment here to explain what this code does (if average is not available... then...) and why it would work (traces are sorted and BR_ONLY trace comes last in the group). 

Although the information is in the PR summary, putting it down as a comment here would help future readers to understand the code faster. 

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


More information about the llvm-branch-commits mailing list