@@ -2310,6 +2310,52 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
2310
2310
BP.Functions .emplace_back (
2311
2311
YAMLProfileWriter::convert (Function, /* UseDFS=*/ false ));
2312
2312
}
2313
+
2314
+ for (const auto &KV : NamesToBranches) {
2315
+ const StringRef FuncName = KV.first ;
2316
+ const FuncBranchData &Branches = KV.second ;
2317
+ yaml::bolt::BinaryFunctionProfile YamlBF;
2318
+ BinaryData *BD = BC.getBinaryDataByName (FuncName);
2319
+ assert (BD);
2320
+ uint64_t FuncAddress = BD->getAddress ();
2321
+ if (!BAT->isBATFunction (FuncAddress))
2322
+ continue ;
2323
+ // Filter out cold fragments
2324
+ if (!BD->getSectionName ().equals (BC.getMainCodeSectionName ()))
2325
+ continue ;
2326
+ BinaryFunction *BF = BC.getBinaryFunctionAtAddress (FuncAddress);
2327
+ assert (BF);
2328
+ YamlBF.Name = FuncName.str ();
2329
+ YamlBF.Id = BF->getFunctionNumber ();
2330
+ YamlBF.Hash = BAT->getBFHash (FuncAddress);
2331
+ YamlBF.ExecCount = BF->getKnownExecutionCount ();
2332
+ YamlBF.NumBasicBlocks = BAT->getNumBasicBlocks (FuncAddress);
2333
+ const BoltAddressTranslation::BBHashMapTy &BlockMap =
2334
+ BAT->getBBHashMap (FuncAddress);
2335
+
2336
+ auto addSuccProfile = [&](yaml::bolt::BinaryBasicBlockProfile &YamlBB,
2337
+ uint64_t SuccOffset, unsigned SuccDataIdx) {
2338
+ const llvm::bolt::BranchInfo &BI = Branches.Data .at (SuccDataIdx);
2339
+ yaml::bolt::SuccessorInfo SI;
2340
+ SI.Index = BlockMap.getBBIndex (SuccOffset);
2341
+ SI.Count = BI.Branches ;
2342
+ SI.Mispreds = BI.Mispreds ;
2343
+ YamlBB.Successors .emplace_back (SI);
2344
+ };
2345
+
2346
+ for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex ) {
2347
+ yaml::bolt::BinaryBasicBlockProfile YamlBB;
2348
+ if (!BlockMap.isInputBlock (FromOffset))
2349
+ continue ;
2350
+ YamlBB.Index = BlockMap.getBBIndex (FromOffset);
2351
+ YamlBB.Hash = BlockMap.getBBHash (FromOffset);
2352
+ for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
2353
+ addSuccProfile (YamlBB, SuccOffset, SuccDataIdx);
2354
+ if (YamlBB.ExecCount || !YamlBB.Successors .empty ())
2355
+ YamlBF.Blocks .emplace_back (YamlBB);
2356
+ }
2357
+ BP.Functions .emplace_back (YamlBF);
2358
+ }
2313
2359
}
2314
2360
2315
2361
// Write the profile.
0 commit comments