[PATCH] D154096: Tooltips for control flow dot graphs
Artur Pilipenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 21:06:46 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ffcea5488eb: Tooltips for CFG dot graphs (authored by mark-sed, committed by apilipenko).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154096/new/
https://reviews.llvm.org/D154096
Files:
llvm/include/llvm/Analysis/CFGPrinter.h
Index: llvm/include/llvm/Analysis/CFGPrinter.h
===================================================================
--- llvm/include/llvm/Analysis/CFGPrinter.h
+++ llvm/include/llvm/Analysis/CFGPrinter.h
@@ -247,52 +247,70 @@
return "";
}
+ static std::string getBBName(const BasicBlock *Node) {
+ std::string NodeName = Node->getName().str();
+ if (NodeName.empty()) {
+ raw_string_ostream NodeOS(NodeName);
+ Node->printAsOperand(NodeOS, false);
+ NodeName = NodeOS.str();
+ // Removing %
+ NodeName.erase(NodeName.begin());
+ }
+ return NodeName;
+ }
+
/// Display the raw branch weights from PGO.
std::string getEdgeAttributes(const BasicBlock *Node, const_succ_iterator I,
DOTFuncInfo *CFGInfo) {
+ unsigned OpNo = I.getSuccessorIndex();
+ const Instruction *TI = Node->getTerminator();
+ BasicBlock *SuccBB = TI->getSuccessor(OpNo);
+ auto BranchProb = CFGInfo->getBPI()->getEdgeProbability(Node, SuccBB);
+ double WeightPercent = ((double)BranchProb.getNumerator()) /
+ ((double)BranchProb.getDenominator());
+
+ std::string TTAttr =
+ formatv("tooltip=\"{0} -> {1}\\nProbability {2:P}\" ", getBBName(Node),
+ getBBName(SuccBB), WeightPercent);
if (!CFGInfo->showEdgeWeights())
- return "";
+ return TTAttr;
- const Instruction *TI = Node->getTerminator();
if (TI->getNumSuccessors() == 1)
- return "penwidth=2";
-
- unsigned OpNo = I.getSuccessorIndex();
+ return TTAttr + "penwidth=2";
if (OpNo >= TI->getNumSuccessors())
- return "";
+ return TTAttr;
- BasicBlock *SuccBB = TI->getSuccessor(OpNo);
- auto BranchProb = CFGInfo->getBPI()->getEdgeProbability(Node, SuccBB);
- double WeightPercent = ((double)BranchProb.getNumerator()) /
- ((double)BranchProb.getDenominator());
double Width = 1 + WeightPercent;
if (!CFGInfo->useRawEdgeWeights())
- return formatv("label=\"{0:P}\" penwidth={1}", WeightPercent, Width)
- .str();
+ return TTAttr +
+ formatv("label=\"{0:P}\" penwidth={1}", WeightPercent, Width)
+ .str();
// Prepend a 'W' to indicate that this is a weight rather than the actual
// profile count (due to scaling).
uint64_t Freq = CFGInfo->getFreq(Node);
- std::string Attrs = formatv("label=\"W:{0}\" penwidth={1}",
- (uint64_t)(Freq * WeightPercent), Width);
+ std::string Attrs =
+ TTAttr + formatv("label=\"W:{0}\" penwidth={1}",
+ (uint64_t)(Freq * WeightPercent), Width)
+ .str();
if (Attrs.size())
return Attrs;
MDNode *WeightsNode = getBranchWeightMDNode(*TI);
if (!WeightsNode)
- return "";
+ return TTAttr;
OpNo = I.getSuccessorIndex() + 1;
if (OpNo >= WeightsNode->getNumOperands())
- return "";
+ return TTAttr;
ConstantInt *Weight =
mdconst::dyn_extract<ConstantInt>(WeightsNode->getOperand(OpNo));
if (!Weight)
- return "";
- return ("label=\"W:" + std::to_string(Weight->getZExtValue()) +
+ return TTAttr;
+ return (TTAttr + "label=\"W:" + std::to_string(Weight->getZExtValue()) +
"\" penwidth=" + std::to_string(Width));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154096.550986.patch
Type: text/x-patch
Size: 3380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230817/87f9c464/attachment.bin>
More information about the llvm-commits
mailing list