-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BOLT] Use aggregated FuncBranchData in writeBATYAML #91289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6e4239c
049c1e3
eecff96
b8425a4
4370534
2b8664c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't this be part of constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can, but I decided to keep it this way for two reasons:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type impedance means that if Count and Mispreds are passed to the constructor there needs to be an explicit cast (as the constructor doesn't accept uints). Whereas if the values are assigned to, there's an implicit cast. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, an explicit cast in the constructor due to type impedance: llvm-project/bolt/lib/Profile/DataAggregator.cpp Lines 1296 to 1298 in 31a203f
|
||||||||
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) { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
B 800154 401050 20 0 | ||
F 800159 800193 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for
llvm::bolt::
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we need a FQ name:
llvm::bolt::BranchInfo
:llvm-project/bolt/include/bolt/Profile/DataReader.h
Line 78 in 5944579
llvm::bolt::DataAggregator::BranchInfo
:llvm-project/bolt/include/bolt/Profile/DataAggregator.h
Line 125 in 5944579
I thought about renaming the latter to
TakenInfo
to match its counterpartFTInfo
:llvm-project/bolt/include/bolt/Profile/DataAggregator.h
Line 120 in 5944579
WDYT?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped in a follow-up diff #92017.