[CFGPrinter] Display branch weight on the edges
Summary: This is pretty useful especially in connection with BFI's -view-block-freq-propagation-dags. It helped me to track down the bug that is being fixed in D24118. While -view-block-freq-propagation-dags displays the high-level information with static heuristics included (and block frequencies), the new thing only shows the raw weight as presented by PGO without any of the static estimates. This helps to distinguished what has been measured vs. estimated. For the sample loop in D24118, -view-block-freq-propagation-dags=integer looks like this: https://reviews.llvm.org/F2381352 While with -view-cfg-only you can see the underlying branch weights: https://reviews.llvm.org/F2392296 Reviewers: dexonsmith, bogner, davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D24144 llvm-svn: 280442
This commit is contained in:
parent
b54579fab6
commit
1200a050ff
@ -118,6 +118,36 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// Display the raw branch weights from PGO.
|
||||
std::string getEdgeAttributes(const BasicBlock *Node, succ_const_iterator I,
|
||||
const Function *F) {
|
||||
const TerminatorInst *TI = Node->getTerminator();
|
||||
if (TI->getNumSuccessors() == 1)
|
||||
return "";
|
||||
|
||||
MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
|
||||
if (!WeightsNode)
|
||||
return "";
|
||||
|
||||
MDString *MDName = cast<MDString>(WeightsNode->getOperand(0));
|
||||
if (MDName->getString() != "branch_weights")
|
||||
return "";
|
||||
|
||||
unsigned OpNo = I.getSuccessorIndex() + 1;
|
||||
if (OpNo >= WeightsNode->getNumOperands())
|
||||
return "";
|
||||
ConstantInt *Weight =
|
||||
mdconst::dyn_extract<ConstantInt>(WeightsNode->getOperand(OpNo));
|
||||
if (!Weight)
|
||||
return "";
|
||||
|
||||
// Append a 'W' to indicate that these are weights rather than actual
|
||||
// profile
|
||||
// count (due to scaling).
|
||||
Twine Attrs = "label=\"W:" + Twine(Weight->getZExtValue()) + "\"";
|
||||
return Attrs.str();
|
||||
}
|
||||
};
|
||||
} // End llvm namespace
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user