@@ -2355,30 +2355,6 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
2355
2355
for (auto BI = BlockMap.begin (), BE = BlockMap.end (); BI != BE; ++BI)
2356
2356
YamlBF.Blocks [BI->second .getBBIndex ()].Hash = BI->second .getBBHash ();
2357
2357
2358
- auto getSuccessorInfo = [&](uint32_t SuccOffset, unsigned SuccDataIdx) {
2359
- const llvm::bolt::BranchInfo &BI = Branches.Data .at (SuccDataIdx);
2360
- yaml::bolt::SuccessorInfo SI;
2361
- SI.Index = BlockMap.getBBIndex (SuccOffset);
2362
- SI.Count = BI.Branches ;
2363
- SI.Mispreds = BI.Mispreds ;
2364
- return SI;
2365
- };
2366
-
2367
- auto getCallSiteInfo = [&](Location CallToLoc, unsigned CallToIdx,
2368
- uint32_t Offset) {
2369
- const llvm::bolt::BranchInfo &BI = Branches.Data .at (CallToIdx);
2370
- yaml::bolt::CallSiteInfo CSI;
2371
- CSI.DestId = 0 ; // designated for unknown functions
2372
- CSI.EntryDiscriminator = 0 ;
2373
- CSI.Count = BI.Branches ;
2374
- CSI.Mispreds = BI.Mispreds ;
2375
- CSI.Offset = Offset;
2376
- if (BinaryData *BD = BC.getBinaryDataByName (CallToLoc.Name ))
2377
- YAMLProfileWriter::setCSIDestination (BC, CSI, BD->getSymbol (), BAT,
2378
- CallToLoc.Offset );
2379
- return CSI;
2380
- };
2381
-
2382
2358
// Lookup containing basic block offset and index
2383
2359
auto getBlock = [&BlockMap](uint32_t Offset) {
2384
2360
auto BlockIt = BlockMap.upper_bound (Offset);
@@ -2390,25 +2366,26 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
2390
2366
return std::pair (BlockIt->first , BlockIt->second .getBBIndex ());
2391
2367
};
2392
2368
2393
- for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex ) {
2394
- const auto &[_, Index] = getBlock (FromOffset);
2395
- yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks [Index];
2396
- for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
2397
- if (BlockMap.isInputBlock (SuccOffset))
2398
- YamlBB.Successors .emplace_back (
2399
- getSuccessorInfo (SuccOffset, SuccDataIdx));
2400
- }
2401
- for (const auto &[FromOffset, CallTo] : Branches.InterIndex ) {
2402
- const auto &[BlockOffset, BlockIndex] = getBlock (FromOffset);
2403
- yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks [BlockIndex];
2404
- const uint32_t Offset = FromOffset - BlockOffset;
2405
- for (const auto &[CallToLoc, CallToIdx] : CallTo)
2406
- YamlBB.CallSites .emplace_back (
2407
- getCallSiteInfo (CallToLoc, CallToIdx, Offset));
2408
- llvm::sort (YamlBB.CallSites , [](yaml::bolt::CallSiteInfo &A,
2409
- yaml::bolt::CallSiteInfo &B) {
2410
- return A.Offset < B.Offset ;
2411
- });
2369
+ for (const llvm::bolt::BranchInfo &BI : Branches.Data ) {
2370
+ using namespace yaml ::bolt;
2371
+ const auto &[BlockOffset, BlockIndex] = getBlock (BI.From .Offset );
2372
+ BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks [BlockIndex];
2373
+ if (BI.To .IsSymbol && BI.To .Name == BI.From .Name && BI.To .Offset != 0 ) {
2374
+ // Internal branch
2375
+ const unsigned SuccIndex = getBlock (BI.To .Offset ).second ;
2376
+ auto &SI = YamlBB.Successors .emplace_back (SuccessorInfo{SuccIndex});
2377
+ SI.Count = BI.Branches ;
2378
+ SI.Mispreds = BI.Mispreds ;
2379
+ } else {
2380
+ // Call
2381
+ const uint32_t Offset = BI.From .Offset - BlockOffset;
2382
+ auto &CSI = YamlBB.CallSites .emplace_back (CallSiteInfo{Offset});
2383
+ CSI.Count = BI.Branches ;
2384
+ CSI.Mispreds = BI.Mispreds ;
2385
+ if (const BinaryData *BD = BC.getBinaryDataByName (BI.To .Name ))
2386
+ YAMLProfileWriter::setCSIDestination (BC, CSI, BD->getSymbol (), BAT,
2387
+ BI.To .Offset );
2388
+ }
2412
2389
}
2413
2390
// Set entry counts, similar to DataReader::readProfile.
2414
2391
for (const llvm::bolt::BranchInfo &BI : Branches.EntryData ) {
0 commit comments