@@ -1263,10 +1263,57 @@ static SymbolInfoTy createDummySymbolInfo(const ObjectFile &Obj,
12631263 return SymbolInfoTy (Addr, Name, Type);
12641264}
12651265
1266- static void
1267- collectBBAddrMapLabels (const std::unordered_map<uint64_t , BBAddrMap> &AddrToBBAddrMap,
1268- uint64_t SectionAddr, uint64_t Start, uint64_t End,
1269- std::unordered_map<uint64_t , std::vector<std::string>> &Labels) {
1266+ struct BBAddrMapLabel {
1267+ std::string BlockLabel;
1268+ std::string PGOAnalysis;
1269+ };
1270+
1271+ static std::string constructPGOLabelString (const PGOAnalysisMap &PGOMap,
1272+ size_t BBEntryIndex) {
1273+ std::string PGOString;
1274+ raw_string_ostream PGOSS (PGOString);
1275+
1276+ PGOSS << " (" ;
1277+ if (PGOMap.FeatEnable .FuncEntryCount && BBEntryIndex == 0 ) {
1278+ PGOSS << " Entry count: " << Twine (PGOMap.FuncEntryCount );
1279+ if (PGOMap.FeatEnable .BBFreq || PGOMap.FeatEnable .BrProb ) {
1280+ PGOSS << " , " ;
1281+ }
1282+ }
1283+
1284+ if (PGOMap.FeatEnable .BBFreq || PGOMap.FeatEnable .BrProb ) {
1285+ assert (BBEntryIndex < PGOMap.BBEntries .size () &&
1286+ " Expected PGOAnalysisMap and BBAddrMap to have the same entires" );
1287+ const PGOAnalysisMap::PGOBBEntry &PGOBBEntry =
1288+ PGOMap.BBEntries [BBEntryIndex];
1289+
1290+ if (PGOMap.FeatEnable .BBFreq ) {
1291+ PGOSS << " Frequency: " << Twine (PGOBBEntry.BlockFreq .getFrequency ());
1292+ if (PGOMap.FeatEnable .BrProb && PGOBBEntry.Successors .size () > 0 ) {
1293+ PGOSS << " , " ;
1294+ }
1295+ }
1296+ if (PGOMap.FeatEnable .BrProb && PGOBBEntry.Successors .size () > 0 ) {
1297+ PGOSS << " Successors: " ;
1298+ interleaveComma (
1299+ PGOBBEntry.Successors , PGOSS,
1300+ [&PGOSS](const PGOAnalysisMap::PGOBBEntry::SuccessorEntry &SE) {
1301+ PGOSS << " BB" << SE.ID << " :" ;
1302+ PGOSS.write_hex (SE.Prob .getNumerator ());
1303+ });
1304+ }
1305+ }
1306+ PGOSS << " )" ;
1307+
1308+ return PGOString;
1309+ }
1310+
1311+ static void collectBBAddrMapLabels (
1312+ const std::unordered_map<uint64_t , BBAddrMap> &AddrToBBAddrMap,
1313+ const std::unordered_map<uint64_t , PGOAnalysisMap> &AddrToPGOAnalysisMap,
1314+ uint64_t SectionAddr, uint64_t Start, uint64_t End,
1315+ std::unordered_map<uint64_t , std::vector<BBAddrMapLabel>> &Labels,
1316+ const StringRef FileName) {
12701317 if (AddrToBBAddrMap.empty ())
12711318 return ;
12721319 Labels.clear ();
@@ -1275,11 +1322,21 @@ collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAd
12751322 auto Iter = AddrToBBAddrMap.find (StartAddress);
12761323 if (Iter == AddrToBBAddrMap.end ())
12771324 return ;
1278- for (const BBAddrMap::BBEntry &BBEntry : Iter->second .getBBEntries ()) {
1325+ auto PGOIter = AddrToPGOAnalysisMap.find (StartAddress);
1326+
1327+ for (size_t I = 0 ; I < Iter->second .getBBEntries ().size (); ++I) {
1328+ const BBAddrMap::BBEntry &BBEntry = Iter->second .getBBEntries ()[I];
12791329 uint64_t BBAddress = BBEntry.Offset + Iter->second .getFunctionAddress ();
12801330 if (BBAddress >= EndAddress)
12811331 continue ;
1282- Labels[BBAddress].push_back ((" BB" + Twine (BBEntry.ID )).str ());
1332+
1333+ std::string LabelString = (" BB" + Twine (BBEntry.ID )).str ();
1334+ std::string PGOString;
1335+
1336+ if (PGOIter != AddrToPGOAnalysisMap.end ())
1337+ PGOString = constructPGOLabelString (PGOIter->second , I);
1338+
1339+ Labels[BBAddress].push_back ({LabelString, PGOString});
12831340 }
12841341}
12851342
@@ -1637,18 +1694,24 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
16371694 LLVM_DEBUG (LVP.dump ());
16381695
16391696 std::unordered_map<uint64_t , BBAddrMap> AddrToBBAddrMap;
1697+ std::unordered_map<uint64_t , PGOAnalysisMap> AddrToPGOAnalysisMap;
16401698 auto ReadBBAddrMap = [&](std::optional<unsigned > SectionIndex =
16411699 std::nullopt ) {
16421700 AddrToBBAddrMap.clear ();
16431701 if (const auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) {
1644- auto BBAddrMapsOrErr = Elf->readBBAddrMap (SectionIndex);
1702+ std::vector<PGOAnalysisMap> PGOAnalyses;
1703+ auto BBAddrMapsOrErr = Elf->readBBAddrMap (SectionIndex, &PGOAnalyses);
16451704 if (!BBAddrMapsOrErr) {
16461705 reportWarning (toString (BBAddrMapsOrErr.takeError ()), Obj.getFileName ());
16471706 return ;
16481707 }
1649- for (auto &FunctionBBAddrMap : *BBAddrMapsOrErr)
1650- AddrToBBAddrMap.emplace (FunctionBBAddrMap.Addr ,
1651- std::move (FunctionBBAddrMap));
1708+ for (const auto &[FunctionBBAddrMap, FunctionPGOAnalysis] :
1709+ zip_equal (*std::move (BBAddrMapsOrErr), std::move (PGOAnalyses))) {
1710+ uint64_t Addr = FunctionBBAddrMap.Addr ;
1711+ AddrToBBAddrMap.emplace (Addr, std::move (FunctionBBAddrMap));
1712+ if (FunctionPGOAnalysis.FeatEnable .anyEnabled ())
1713+ AddrToPGOAnalysisMap.emplace (Addr, std::move (FunctionPGOAnalysis));
1714+ }
16521715 }
16531716 };
16541717
@@ -1977,14 +2040,15 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
19772040 FOS.SetUnbuffered ();
19782041
19792042 std::unordered_map<uint64_t , std::string> AllLabels;
1980- std::unordered_map<uint64_t , std::vector<std::string >> BBAddrMapLabels;
2043+ std::unordered_map<uint64_t , std::vector<BBAddrMapLabel >> BBAddrMapLabels;
19812044 if (SymbolizeOperands) {
19822045 collectLocalBranchTargets (Bytes, DT->InstrAnalysis .get (),
19832046 DT->DisAsm .get (), DT->InstPrinter .get (),
19842047 PrimaryTarget.SubtargetInfo .get (),
19852048 SectionAddr, Index, End, AllLabels);
1986- collectBBAddrMapLabels (AddrToBBAddrMap, SectionAddr, Index, End,
1987- BBAddrMapLabels);
2049+ collectBBAddrMapLabels (AddrToBBAddrMap, AddrToPGOAnalysisMap,
2050+ SectionAddr, Index, End, BBAddrMapLabels,
2051+ FileName);
19882052 }
19892053
19902054 if (DT->InstrAnalysis )
@@ -2082,8 +2146,9 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
20822146 // Print local label if there's any.
20832147 auto Iter1 = BBAddrMapLabels.find (SectionAddr + Index);
20842148 if (Iter1 != BBAddrMapLabels.end ()) {
2085- for (StringRef Label : Iter1->second )
2086- FOS << " <" << Label << " >:\n " ;
2149+ for (const auto &BBLabel : Iter1->second )
2150+ FOS << " <" << BBLabel.BlockLabel << " >" << BBLabel.PGOAnalysis
2151+ << " :\n " ;
20872152 } else {
20882153 auto Iter2 = AllLabels.find (SectionAddr + Index);
20892154 if (Iter2 != AllLabels.end ())
@@ -2260,7 +2325,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22602325 } else if (!Disp) {
22612326 *TargetOS << TargetName;
22622327 } else if (BBAddrMapLabelAvailable) {
2263- *TargetOS << BBAddrMapLabels[Target].front ();
2328+ *TargetOS << BBAddrMapLabels[Target].front (). BlockLabel ;
22642329 } else if (LabelAvailable) {
22652330 *TargetOS << AllLabels[Target];
22662331 } else {
@@ -2276,7 +2341,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22762341 }
22772342
22782343 } else if (BBAddrMapLabelAvailable) {
2279- *TargetOS << " <" << BBAddrMapLabels[Target].front () << " >" ;
2344+ *TargetOS << " <" << BBAddrMapLabels[Target].front ().BlockLabel
2345+ << " >" ;
22802346 } else if (LabelAvailable) {
22812347 *TargetOS << " <" << AllLabels[Target] << " >" ;
22822348 }
0 commit comments