@@ -1264,10 +1264,53 @@ static SymbolInfoTy createDummySymbolInfo(const ObjectFile &Obj,
1264
1264
return SymbolInfoTy (Addr, Name, Type);
1265
1265
}
1266
1266
1267
- static void
1268
- collectBBAddrMapLabels (const std::unordered_map<uint64_t , BBAddrMap> &AddrToBBAddrMap,
1269
- uint64_t SectionAddr, uint64_t Start, uint64_t End,
1270
- std::unordered_map<uint64_t , std::vector<std::string>> &Labels) {
1267
+ struct BBAddrMapLabel {
1268
+ std::string BlockLabel;
1269
+ std::string PGOAnalysis;
1270
+ };
1271
+
1272
+ static void constructPGOLabelString (std::string &PGOString,
1273
+ const PGOAnalysisMap &PGOMap,
1274
+ size_t BBEntryIndex) {
1275
+ raw_string_ostream PGOSS (PGOString);
1276
+
1277
+ PGOSS << " (" ;
1278
+ if (PGOMap.FeatEnable .FuncEntryCount && BBEntryIndex == 0 ) {
1279
+ PGOSS << " Entry count: " << Twine (PGOMap.FuncEntryCount );
1280
+ if (PGOMap.FeatEnable .BBFreq || PGOMap.FeatEnable .BrProb ) {
1281
+ PGOSS << " , " ;
1282
+ }
1283
+ }
1284
+
1285
+ if (PGOMap.FeatEnable .BBFreq || PGOMap.FeatEnable .BrProb ) {
1286
+ const PGOAnalysisMap::PGOBBEntry &PGOBBEntry =
1287
+ PGOMap.BBEntries [BBEntryIndex];
1288
+
1289
+ if (PGOMap.FeatEnable .BBFreq ) {
1290
+ PGOSS << " Frequency: " << Twine (PGOBBEntry.BlockFreq .getFrequency ());
1291
+ if (PGOMap.FeatEnable .BrProb && PGOBBEntry.Successors .size () > 0 ) {
1292
+ PGOSS << " , " ;
1293
+ }
1294
+ }
1295
+ if (PGOMap.FeatEnable .BrProb && PGOBBEntry.Successors .size () > 0 ) {
1296
+ PGOSS << " Successors: " ;
1297
+ interleaveComma (
1298
+ PGOBBEntry.Successors , PGOSS,
1299
+ [&PGOSS](const PGOAnalysisMap::PGOBBEntry::SuccessorEntry &SE) {
1300
+ PGOSS << " BB" << SE.ID << " :" ;
1301
+ PGOSS.write_hex (SE.Prob .getNumerator ());
1302
+ });
1303
+ }
1304
+ }
1305
+ PGOSS << " )" ;
1306
+ }
1307
+
1308
+ static void collectBBAddrMapLabels (
1309
+ const std::unordered_map<uint64_t , BBAddrMap> &AddrToBBAddrMap,
1310
+ const std::unordered_map<uint64_t , PGOAnalysisMap> &AddrToPGOAnalysisMap,
1311
+ uint64_t SectionAddr, uint64_t Start, uint64_t End,
1312
+ std::unordered_map<uint64_t , std::vector<BBAddrMapLabel>> &Labels,
1313
+ const StringRef FileName) {
1271
1314
if (AddrToBBAddrMap.empty ())
1272
1315
return ;
1273
1316
Labels.clear ();
@@ -1276,11 +1319,27 @@ collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAd
1276
1319
auto Iter = AddrToBBAddrMap.find (StartAddress);
1277
1320
if (Iter == AddrToBBAddrMap.end ())
1278
1321
return ;
1279
- for (const BBAddrMap::BBEntry &BBEntry : Iter->second .getBBEntries ()) {
1322
+ auto PGOIter = AddrToPGOAnalysisMap.find (StartAddress);
1323
+ if (!AddrToPGOAnalysisMap.empty () && PGOIter == AddrToPGOAnalysisMap.end ())
1324
+ reportWarning (" Expected BBAddrMap and PGOAnalysisMap to have information "
1325
+ " on the same basic blocks" ,
1326
+ FileName);
1327
+
1328
+ for (size_t I = 0 ; I < Iter->second .getBBEntries ().size (); ++I) {
1329
+ const BBAddrMap::BBEntry &BBEntry = Iter->second .getBBEntries ()[I];
1280
1330
uint64_t BBAddress = BBEntry.Offset + Iter->second .getFunctionAddress ();
1281
1331
if (BBAddress >= EndAddress)
1282
1332
continue ;
1283
- Labels[BBAddress].push_back ((" BB" + Twine (BBEntry.ID )).str ());
1333
+
1334
+ std::string LabelString = (" BB" + Twine (BBEntry.ID )).str ();
1335
+ std::string PGOString;
1336
+
1337
+ if (!AddrToPGOAnalysisMap.empty () &&
1338
+ PGOIter != AddrToPGOAnalysisMap.end () &&
1339
+ PGOIter->second .FeatEnable .anyEnabled ())
1340
+ constructPGOLabelString (PGOString, PGOIter->second , I);
1341
+
1342
+ Labels[BBAddress].push_back ({LabelString, PGOString});
1284
1343
}
1285
1344
}
1286
1345
@@ -1638,18 +1697,25 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
1638
1697
LLVM_DEBUG (LVP.dump ());
1639
1698
1640
1699
std::unordered_map<uint64_t , BBAddrMap> AddrToBBAddrMap;
1700
+ std::unordered_map<uint64_t , PGOAnalysisMap> AddrToPGOAnalysisMap;
1641
1701
auto ReadBBAddrMap = [&](std::optional<unsigned > SectionIndex =
1642
1702
std::nullopt) {
1643
1703
AddrToBBAddrMap.clear ();
1644
1704
if (const auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) {
1645
- auto BBAddrMapsOrErr = Elf->readBBAddrMap (SectionIndex);
1705
+ std::vector<PGOAnalysisMap> PGOAnalyses;
1706
+ auto BBAddrMapsOrErr = Elf->readBBAddrMap (SectionIndex, &PGOAnalyses);
1646
1707
if (!BBAddrMapsOrErr) {
1647
1708
reportWarning (toString (BBAddrMapsOrErr.takeError ()), Obj.getFileName ());
1648
1709
return ;
1649
1710
}
1650
- for (auto &FunctionBBAddrMap : *BBAddrMapsOrErr)
1651
- AddrToBBAddrMap.emplace (FunctionBBAddrMap.Addr ,
1652
- std::move (FunctionBBAddrMap));
1711
+ for (size_t I = 0 ; I < (*BBAddrMapsOrErr).size (); ++I) {
1712
+ uint64_t BBAddrMapAddr = (*BBAddrMapsOrErr)[I].Addr ;
1713
+ AddrToBBAddrMap.emplace (BBAddrMapAddr,
1714
+ std::move ((*BBAddrMapsOrErr)[I]));
1715
+ if (PGOAnalyses.size () > 0 )
1716
+ AddrToPGOAnalysisMap.emplace (BBAddrMapAddr,
1717
+ std::move (PGOAnalyses[I]));
1718
+ }
1653
1719
}
1654
1720
};
1655
1721
@@ -1978,14 +2044,15 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
1978
2044
FOS.SetUnbuffered ();
1979
2045
1980
2046
std::unordered_map<uint64_t , std::string> AllLabels;
1981
- std::unordered_map<uint64_t , std::vector<std::string >> BBAddrMapLabels;
2047
+ std::unordered_map<uint64_t , std::vector<BBAddrMapLabel >> BBAddrMapLabels;
1982
2048
if (SymbolizeOperands) {
1983
2049
collectLocalBranchTargets (Bytes, DT->InstrAnalysis .get (),
1984
2050
DT->DisAsm .get (), DT->InstPrinter .get (),
1985
2051
PrimaryTarget.SubtargetInfo .get (),
1986
2052
SectionAddr, Index, End, AllLabels);
1987
- collectBBAddrMapLabels (AddrToBBAddrMap, SectionAddr, Index, End,
1988
- BBAddrMapLabels);
2053
+ collectBBAddrMapLabels (AddrToBBAddrMap, AddrToPGOAnalysisMap,
2054
+ SectionAddr, Index, End, BBAddrMapLabels,
2055
+ FileName);
1989
2056
}
1990
2057
1991
2058
if (DT->InstrAnalysis )
@@ -2083,8 +2150,9 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2083
2150
// Print local label if there's any.
2084
2151
auto Iter1 = BBAddrMapLabels.find (SectionAddr + Index);
2085
2152
if (Iter1 != BBAddrMapLabels.end ()) {
2086
- for (StringRef Label : Iter1->second )
2087
- FOS << " <" << Label << " >:\n " ;
2153
+ for (const auto &BBLabel : Iter1->second )
2154
+ FOS << " <" << BBLabel.BlockLabel << " >" << BBLabel.PGOAnalysis
2155
+ << " :\n " ;
2088
2156
} else {
2089
2157
auto Iter2 = AllLabels.find (SectionAddr + Index);
2090
2158
if (Iter2 != AllLabels.end ())
@@ -2261,7 +2329,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2261
2329
} else if (!Disp) {
2262
2330
*TargetOS << TargetName;
2263
2331
} else if (BBAddrMapLabelAvailable) {
2264
- *TargetOS << BBAddrMapLabels[Target].front ();
2332
+ *TargetOS << BBAddrMapLabels[Target].front (). BlockLabel ;
2265
2333
} else if (LabelAvailable) {
2266
2334
*TargetOS << AllLabels[Target];
2267
2335
} else {
@@ -2277,7 +2345,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2277
2345
}
2278
2346
2279
2347
} else if (BBAddrMapLabelAvailable) {
2280
- *TargetOS << " <" << BBAddrMapLabels[Target].front () << " >" ;
2348
+ *TargetOS << " <" << BBAddrMapLabels[Target].front ().BlockLabel
2349
+ << " >" ;
2281
2350
} else if (LabelAvailable) {
2282
2351
*TargetOS << " <" << AllLabels[Target] << " >" ;
2283
2352
}
0 commit comments