[llvm] [llvm-objdump] Add support for symbolizing PGOBBAddrMap Info (PR #76386)

Micah Weston via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 13:36:26 PST 2024


================
@@ -1264,23 +1264,70 @@ static SymbolInfoTy createDummySymbolInfo(const ObjectFile &Obj,
     return SymbolInfoTy(Addr, Name, Type);
 }
 
-static void
-collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAddrMap,
-                       uint64_t SectionAddr, uint64_t Start, uint64_t End,
-                       std::unordered_map<uint64_t, std::vector<std::string>> &Labels) {
+static void collectBBAddrMapLabels(
+    const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAddrMap,
+    const std::unordered_map<uint64_t, PGOAnalysisMap> &AddrToPGOBBAddrMap,
+    uint64_t SectionAddr, uint64_t Start, uint64_t End,
+    std::unordered_map<
+        uint64_t, std::vector<std::pair<std::string, std::string>>> &Labels) {
   if (AddrToBBAddrMap.empty())
     return;
   Labels.clear();
   uint64_t StartAddress = SectionAddr + Start;
   uint64_t EndAddress = SectionAddr + End;
   auto Iter = AddrToBBAddrMap.find(StartAddress);
+  auto PGOIter = AddrToPGOBBAddrMap.find(StartAddress);
   if (Iter == AddrToBBAddrMap.end())
     return;
-  for (const BBAddrMap::BBEntry &BBEntry : Iter->second.getBBEntries()) {
+  for (size_t I = 0; I < Iter->second.getBBEntries().size(); ++I) {
+    const BBAddrMap::BBEntry &BBEntry = Iter->second.getBBEntries()[I];
     uint64_t BBAddress = BBEntry.Offset + Iter->second.getFunctionAddress();
     if (BBAddress >= EndAddress)
       continue;
-    Labels[BBAddress].push_back(("BB" + Twine(BBEntry.ID)).str());
+
+    std::string LabelString = "BB" + Twine(BBEntry.ID).str();
+    std::string PGOString = "";
+
+    if (!AddrToPGOBBAddrMap.empty()) {
+      assert(PGOIter != AddrToPGOBBAddrMap.end() &&
+             "PGOAnalysisMap and BBAddrMap should have information on the same "
+             "basic blocks");
+      const PGOAnalysisMap::PGOBBEntry &PGOBBEntry =
+          PGOIter->second.BBEntries[I];
+
+      PGOString += " (";
+
+      if (PGOIter->second.FeatEnable.FuncEntryCount && I == 0) {
+        PGOString +=
+            "Entry count: " + Twine(PGOIter->second.FuncEntryCount).str();
+        if (PGOIter->second.FeatEnable.BBFreq ||
+            PGOIter->second.FeatEnable.BrProb) {
+          PGOString += ", ";
+        }
+      }
+      if (PGOIter->second.FeatEnable.BBFreq) {
+        PGOString +=
+            "Frequency: " + Twine(PGOBBEntry.BlockFreq.getFrequency()).str();
+        if (PGOIter->second.FeatEnable.BrProb &&
+            PGOBBEntry.Successors.size() > 0) {
+          PGOString += ", ";
+        }
+      }
+      if (PGOIter->second.FeatEnable.BrProb &&
+          PGOBBEntry.Successors.size() > 0) {
+        PGOString += "Successors: ";
+        for (size_t J = 0; J < PGOBBEntry.Successors.size(); ++J) {
----------------
red1bluelost wrote:

Try replacing this for-loop with `llvm::interleaveComma`

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


More information about the llvm-commits mailing list