forked from OSchip/llvm-project
[BOLT] Improved Jump-Distance Metric
Summary: Current existing Jump-Distance Metric (Previously named Call-Distance) will ignore some traversals. This modified version adds those missing traversals back. The correlation remains the same: around 97% correlation with CPU and Cache Miss (which implies that even though some traversals are ignored, it doesn't affect correlation that much.) (cherry picked from FBD5369653)
This commit is contained in:
parent
4ecd3856e9
commit
4d34471eeb
|
@ -50,10 +50,10 @@ getPositionMap(const BinaryFunction &Function) {
|
|||
/// Initialize and return a vector of traversals for a given function and its
|
||||
/// entry point
|
||||
std::vector<Traversal> getTraversals(const BinaryFunction &Function,
|
||||
BinaryBasicBlock *BB) {
|
||||
BinaryBasicBlock *EntryBB) {
|
||||
std::vector<Traversal> AllTraversals;
|
||||
std::stack<std::pair<BinaryBasicBlock *, Traversal>> Stack;
|
||||
Stack.push(std::make_pair(BB, Traversal()));
|
||||
Stack.push(std::make_pair(EntryBB, Traversal()));
|
||||
std::unordered_set<BinaryBasicBlock *> BBSet;
|
||||
|
||||
while (!Stack.empty()) {
|
||||
|
@ -70,23 +70,28 @@ std::vector<Traversal> getTraversals(const BinaryFunction &Function,
|
|||
continue;
|
||||
}
|
||||
|
||||
uint64_t SuccTotalCount = 0;
|
||||
bool HaveSuccCount = false;
|
||||
// Calculate total edges count of successors
|
||||
for (auto BI = CurrentBB->branch_info_begin();
|
||||
BI != CurrentBB->branch_info_end(); ++BI) {
|
||||
if (BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE) {
|
||||
SuccTotalCount += BI->Count;
|
||||
if (BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE && BI->Count > 0) {
|
||||
HaveSuccCount = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (SuccTotalCount == 0) {
|
||||
if (!HaveSuccCount) {
|
||||
AllTraversals.push_back(PrevTraversal);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto BI = CurrentBB->branch_info_begin();
|
||||
for (auto *SuccBB : CurrentBB->successors()) {
|
||||
if (BBSet.find(SuccBB) == BBSet.end() && BI->Count != 0 &&
|
||||
BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE) {
|
||||
// If we have never seen SuccBB, or SuccBB indicates the
|
||||
// end of traversal, SuccBB will be added into stack for
|
||||
// further exploring.
|
||||
if ((BBSet.find(SuccBB) == BBSet.end() && BI->Count != 0 &&
|
||||
BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE) ||
|
||||
SuccBB->succ_empty()) {
|
||||
Stack.push(std::make_pair(SuccBB, PrevTraversal));
|
||||
}
|
||||
++BI;
|
||||
|
|
|
@ -820,7 +820,7 @@ void RewriteInstance::run() {
|
|||
}
|
||||
|
||||
if (opts::CalcCacheMetrics) {
|
||||
outs() << "\nBOLT-INFO: After Optimization Call Graph Statistics: Call "
|
||||
outs() << "\nBOLT-INFO: After Optimization CFG Graph Statistics: Jump "
|
||||
"Distance \n\n";
|
||||
CalcCacheMetrics::calcGraphDistance(BinaryFunctions);
|
||||
}
|
||||
|
@ -1874,7 +1874,7 @@ void RewriteInstance::disassembleFunctions() {
|
|||
}
|
||||
|
||||
if (opts::CalcCacheMetrics) {
|
||||
outs() << "\nBOLT-INFO: Before Optimization Call Graph Statistics: Call "
|
||||
outs() << "\nBOLT-INFO: Before Optimization CFG Graph Statistics: Jump "
|
||||
"Distance \n\n";
|
||||
CalcCacheMetrics::calcGraphDistance(BinaryFunctions);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue