@@ -1263,10 +1263,57 @@ static SymbolInfoTy createDummySymbolInfo(const ObjectFile &Obj,
1263
1263
return SymbolInfoTy (Addr, Name, Type);
1264
1264
}
1265
1265
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) {
1270
1317
if (AddrToBBAddrMap.empty ())
1271
1318
return ;
1272
1319
Labels.clear ();
@@ -1275,11 +1322,21 @@ collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAd
1275
1322
auto Iter = AddrToBBAddrMap.find (StartAddress);
1276
1323
if (Iter == AddrToBBAddrMap.end ())
1277
1324
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];
1279
1329
uint64_t BBAddress = BBEntry.Offset + Iter->second .getFunctionAddress ();
1280
1330
if (BBAddress >= EndAddress)
1281
1331
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});
1283
1340
}
1284
1341
}
1285
1342
@@ -1637,18 +1694,24 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
1637
1694
LLVM_DEBUG (LVP.dump ());
1638
1695
1639
1696
std::unordered_map<uint64_t , BBAddrMap> AddrToBBAddrMap;
1697
+ std::unordered_map<uint64_t , PGOAnalysisMap> AddrToPGOAnalysisMap;
1640
1698
auto ReadBBAddrMap = [&](std::optional<unsigned > SectionIndex =
1641
1699
std::nullopt) {
1642
1700
AddrToBBAddrMap.clear ();
1643
1701
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);
1645
1704
if (!BBAddrMapsOrErr) {
1646
1705
reportWarning (toString (BBAddrMapsOrErr.takeError ()), Obj.getFileName ());
1647
1706
return ;
1648
1707
}
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
+ }
1652
1715
}
1653
1716
};
1654
1717
@@ -1977,14 +2040,15 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
1977
2040
FOS.SetUnbuffered ();
1978
2041
1979
2042
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;
1981
2044
if (SymbolizeOperands) {
1982
2045
collectLocalBranchTargets (Bytes, DT->InstrAnalysis .get (),
1983
2046
DT->DisAsm .get (), DT->InstPrinter .get (),
1984
2047
PrimaryTarget.SubtargetInfo .get (),
1985
2048
SectionAddr, Index, End, AllLabels);
1986
- collectBBAddrMapLabels (AddrToBBAddrMap, SectionAddr, Index, End,
1987
- BBAddrMapLabels);
2049
+ collectBBAddrMapLabels (AddrToBBAddrMap, AddrToPGOAnalysisMap,
2050
+ SectionAddr, Index, End, BBAddrMapLabels,
2051
+ FileName);
1988
2052
}
1989
2053
1990
2054
if (DT->InstrAnalysis )
@@ -2082,8 +2146,9 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2082
2146
// Print local label if there's any.
2083
2147
auto Iter1 = BBAddrMapLabels.find (SectionAddr + Index);
2084
2148
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 " ;
2087
2152
} else {
2088
2153
auto Iter2 = AllLabels.find (SectionAddr + Index);
2089
2154
if (Iter2 != AllLabels.end ())
@@ -2260,7 +2325,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2260
2325
} else if (!Disp) {
2261
2326
*TargetOS << TargetName;
2262
2327
} else if (BBAddrMapLabelAvailable) {
2263
- *TargetOS << BBAddrMapLabels[Target].front ();
2328
+ *TargetOS << BBAddrMapLabels[Target].front (). BlockLabel ;
2264
2329
} else if (LabelAvailable) {
2265
2330
*TargetOS << AllLabels[Target];
2266
2331
} else {
@@ -2276,7 +2341,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2276
2341
}
2277
2342
2278
2343
} else if (BBAddrMapLabelAvailable) {
2279
- *TargetOS << " <" << BBAddrMapLabels[Target].front () << " >" ;
2344
+ *TargetOS << " <" << BBAddrMapLabels[Target].front ().BlockLabel
2345
+ << " >" ;
2280
2346
} else if (LabelAvailable) {
2281
2347
*TargetOS << " <" << AllLabels[Target] << " >" ;
2282
2348
}
0 commit comments