[BOLT] Use aggregated FuncBranchData in writeBATYAML
Switch from FuncBranchData intermediate maps (Intra/InterIndex)
to aggregated Data, same as one used by DataReader:
e62ce1f884/bolt/lib/Profile/DataReader.cpp (L385-L389)
This aligns the order of the output between YAMLProfileWriter and
writeBATYAML.
Test Plan: updated bolt-address-translation-yaml.test
Reviewers: rafaelauler, dcci, ayermolo, maksfb
Reviewed By: ayermolo, maksfb
Pull Request: https://github.com/llvm/llvm-project/pull/91289
This commit is contained in:
@@ -2355,30 +2355,6 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
|
||||
for (auto BI = BlockMap.begin(), BE = BlockMap.end(); BI != BE; ++BI)
|
||||
YamlBF.Blocks[BI->second.getBBIndex()].Hash = BI->second.getBBHash();
|
||||
|
||||
auto getSuccessorInfo = [&](uint32_t SuccOffset, unsigned SuccDataIdx) {
|
||||
const llvm::bolt::BranchInfo &BI = Branches.Data.at(SuccDataIdx);
|
||||
yaml::bolt::SuccessorInfo SI;
|
||||
SI.Index = BlockMap.getBBIndex(SuccOffset);
|
||||
SI.Count = BI.Branches;
|
||||
SI.Mispreds = BI.Mispreds;
|
||||
return SI;
|
||||
};
|
||||
|
||||
auto getCallSiteInfo = [&](Location CallToLoc, unsigned CallToIdx,
|
||||
uint32_t Offset) {
|
||||
const llvm::bolt::BranchInfo &BI = Branches.Data.at(CallToIdx);
|
||||
yaml::bolt::CallSiteInfo CSI;
|
||||
CSI.DestId = 0; // designated for unknown functions
|
||||
CSI.EntryDiscriminator = 0;
|
||||
CSI.Count = BI.Branches;
|
||||
CSI.Mispreds = BI.Mispreds;
|
||||
CSI.Offset = Offset;
|
||||
if (BinaryData *BD = BC.getBinaryDataByName(CallToLoc.Name))
|
||||
YAMLProfileWriter::setCSIDestination(BC, CSI, BD->getSymbol(), BAT,
|
||||
CallToLoc.Offset);
|
||||
return CSI;
|
||||
};
|
||||
|
||||
// Lookup containing basic block offset and index
|
||||
auto getBlock = [&BlockMap](uint32_t Offset) {
|
||||
auto BlockIt = BlockMap.upper_bound(Offset);
|
||||
@@ -2390,25 +2366,26 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
|
||||
return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
|
||||
};
|
||||
|
||||
for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
|
||||
const auto &[_, Index] = getBlock(FromOffset);
|
||||
yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
|
||||
for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
|
||||
if (BlockMap.isInputBlock(SuccOffset))
|
||||
YamlBB.Successors.emplace_back(
|
||||
getSuccessorInfo(SuccOffset, SuccDataIdx));
|
||||
}
|
||||
for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
|
||||
const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
|
||||
yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
|
||||
const uint32_t Offset = FromOffset - BlockOffset;
|
||||
for (const auto &[CallToLoc, CallToIdx] : CallTo)
|
||||
YamlBB.CallSites.emplace_back(
|
||||
getCallSiteInfo(CallToLoc, CallToIdx, Offset));
|
||||
llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
|
||||
yaml::bolt::CallSiteInfo &B) {
|
||||
return A.Offset < B.Offset;
|
||||
});
|
||||
for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
|
||||
using namespace yaml::bolt;
|
||||
const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
|
||||
BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
|
||||
if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) {
|
||||
// Internal branch
|
||||
const unsigned SuccIndex = getBlock(BI.To.Offset).second;
|
||||
auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
|
||||
SI.Count = BI.Branches;
|
||||
SI.Mispreds = BI.Mispreds;
|
||||
} else {
|
||||
// Call
|
||||
const uint32_t Offset = BI.From.Offset - BlockOffset;
|
||||
auto &CSI = YamlBB.CallSites.emplace_back(CallSiteInfo{Offset});
|
||||
CSI.Count = BI.Branches;
|
||||
CSI.Mispreds = BI.Mispreds;
|
||||
if (const BinaryData *BD = BC.getBinaryDataByName(BI.To.Name))
|
||||
YAMLProfileWriter::setCSIDestination(BC, CSI, BD->getSymbol(), BAT,
|
||||
BI.To.Offset);
|
||||
}
|
||||
}
|
||||
// Set entry counts, similar to DataReader::readProfile.
|
||||
for (const llvm::bolt::BranchInfo &BI : Branches.EntryData) {
|
||||
|
||||
Reference in New Issue
Block a user