[PATCH] D139794: [BOLT][NFC] DataAggregator code cleanup

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 18:07:32 PST 2023


Amir updated this revision to Diff 486128.
Amir added a comment.

Use make_second_range


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139794/new/

https://reviews.llvm.org/D139794

Files:
  bolt/lib/Profile/DataAggregator.cpp


Index: bolt/lib/Profile/DataAggregator.cpp
===================================================================
--- bolt/lib/Profile/DataAggregator.cpp
+++ bolt/lib/Profile/DataAggregator.cpp
@@ -644,14 +644,11 @@
   processMemEvents();
 
   // Mark all functions with registered events as having a valid profile.
-  for (auto &BFI : BC.getBinaryFunctions()) {
-    BinaryFunction &BF = BFI.second;
-    if (getBranchData(BF)) {
-      const auto Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
-                                                : BinaryFunction::PF_LBR;
+  const auto Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
+                                            : BinaryFunction::PF_LBR;
+  for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions()))
+    if (getBranchData(BF))
       BF.markProfiled(Flags);
-    }
-  }
 
   // Release intermediate storage.
   clear(BranchLBRs);
@@ -727,17 +724,16 @@
 
   From -= Func.getAddress();
   To -= Func.getAddress();
-  LLVM_DEBUG(dbgs() << "BOLT-DEBUG: bumpBranchCount: " << Func.getPrintName()
-                    << " @ " << Twine::utohexstr(From) << " -> "
-                    << Func.getPrintName() << " @ " << Twine::utohexstr(To)
-                    << '\n');
+  LLVM_DEBUG(dbgs() << formatv(
+                 "BOLT-DEBUG: bumpBranchCount: {0} @ {1:x} -> {0} @ {2:x}\n",
+                 Func.getPrintName(), From, To));
   if (BAT) {
     From = BAT->translate(Func.getAddress(), From, /*IsBranchSrc=*/true);
     To = BAT->translate(Func.getAddress(), To, /*IsBranchSrc=*/false);
-    LLVM_DEBUG(dbgs() << "BOLT-DEBUG: BAT translation on bumpBranchCount: "
-                      << Func.getPrintName() << " @ " << Twine::utohexstr(From)
-                      << " -> " << Func.getPrintName() << " @ "
-                      << Twine::utohexstr(To) << '\n');
+    LLVM_DEBUG(
+        dbgs() << formatv("BOLT-DEBUG: BAT translation on bumpBranchCount: {0} "
+                          "@ {1:x} -> {0} @ {2:x}\n",
+                          Func.getPrintName(), From, To));
   }
 
   AggrData->bumpBranchCount(From, To, Count, Mispreds);
@@ -1712,8 +1708,7 @@
     BinaryFunction *Func = getBinaryFunctionContainingAddress(PC);
     if (!Func) {
       LLVM_DEBUG(if (PC != 0) {
-        dbgs() << "Skipped mem event: 0x" << Twine::utohexstr(PC) << " => 0x"
-               << Twine::utohexstr(Addr) << "\n";
+        dbgs() << formatv("Skipped mem event: {0:x} => {1:x}\n", PC, Addr);
       });
       continue;
     }
@@ -2139,10 +2134,10 @@
          << BinaryMMapInfo.size() << " PID(s)\n";
 
   LLVM_DEBUG({
-    for (std::pair<const uint64_t, MMapInfo> &MMI : BinaryMMapInfo)
-      outs() << "  " << MMI.second.PID << (MMI.second.Forked ? " (forked)" : "")
-             << ": (0x" << Twine::utohexstr(MMI.second.MMapAddress) << ": 0x"
-             << Twine::utohexstr(MMI.second.Size) << ")\n";
+    for (const MMapInfo &MMI : llvm::make_second_range(BinaryMMapInfo))
+      outs() << formatv("  {0}{1}: ({2:x}: {3:x})\n", MMI.PID,
+                        (MMI.Forked ? " (forked)" : ""), MMI.MMapAddress,
+                        MMI.Size);
   });
 
   return std::error_code();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139794.486128.patch
Type: text/x-patch
Size: 3204 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230104/530899ef/attachment.bin>


More information about the llvm-commits mailing list