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

Micah Weston via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 09:47:59 PST 2024


================
@@ -1638,18 +1685,27 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
   LLVM_DEBUG(LVP.dump());
 
   std::unordered_map<uint64_t, BBAddrMap> AddrToBBAddrMap;
+  std::unordered_map<uint64_t, PGOAnalysisMap> AddrToPGOBBAddrMap;
   auto ReadBBAddrMap = [&](std::optional<unsigned> SectionIndex =
                                std::nullopt) {
     AddrToBBAddrMap.clear();
     if (const auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) {
-      auto BBAddrMapsOrErr = Elf->readBBAddrMap(SectionIndex);
+      std::vector<PGOAnalysisMap> PGOAnalyses;
+      auto BBAddrMapsOrErr = Elf->readBBAddrMap(SectionIndex, &PGOAnalyses);
       if (!BBAddrMapsOrErr) {
         reportWarning(toString(BBAddrMapsOrErr.takeError()), Obj.getFileName());
         return;
       }
       for (auto &FunctionBBAddrMap : *BBAddrMapsOrErr)
         AddrToBBAddrMap.emplace(FunctionBBAddrMap.Addr,
                                 std::move(FunctionBBAddrMap));
+      for (size_t I = 0; I < (*BBAddrMapsOrErr).size(); ++I) {
+        AddrToBBAddrMap.emplace((*BBAddrMapsOrErr)[I].Addr,
+                                std::move((*BBAddrMapsOrErr)[I]));
+        if (PGOAnalyses.size() > 0)
+          AddrToPGOBBAddrMap.emplace((*BBAddrMapsOrErr)[I].Addr,
+                                     std::move(PGOAnalyses[I]));
+      }
----------------
red1bluelost wrote:

BBAddrMap and PGOAnalyses both work at the function level. There might be future scenarios where we disable PGOAnalyses on one function but not others. To keep the mapping an empty PGOAnalysis would be in the vector (i.e. FeatEnable = false for all).

For the completely non-PGO case, the readBBAddrMap does not know upfront whether PGO is used or unused. So if you provide the PGOAnalyses vector but PGO is never used, then you just get a vector full of empty PGOAnalysis.

What you could do is check the FeatEnable here and just not add to the map if nothing is enabled. `llvm::zip_equal` can still be used.

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


More information about the llvm-commits mailing list