[llvm] [Analysis] Fix null ptr dereference when using WriteGraph without branch probability info (PR #104102)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 10:59:22 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Tyler Nowicki (TylerNowicki)
<details>
<summary>Changes</summary>
The call to 'CFGInfo->getBPI()->getEdgeProbability(Node, SuccBB);' fails when BPI is not provided. In this case we can give up and not print any edge attributes.
---
Full diff: https://github.com/llvm/llvm-project/pull/104102.diff
1 Files Affected:
- (modified) llvm/include/llvm/Analysis/CFGPrinter.h (+4-3)
``````````diff
diff --git a/llvm/include/llvm/Analysis/CFGPrinter.h b/llvm/include/llvm/Analysis/CFGPrinter.h
index 7d4d3a574b9e8..cd785331d1f14 100644
--- a/llvm/include/llvm/Analysis/CFGPrinter.h
+++ b/llvm/include/llvm/Analysis/CFGPrinter.h
@@ -265,18 +265,19 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
/// Display the raw branch weights from PGO.
std::string getEdgeAttributes(const BasicBlock *Node, const_succ_iterator I,
DOTFuncInfo *CFGInfo) {
+ // If BPI is not provided do not display any edge attributes
+ if (!CFGInfo->showEdgeWeights())
+ return "";
+
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 TTAttr;
if (TI->getNumSuccessors() == 1)
return TTAttr + "penwidth=2";
``````````
</details>
https://github.com/llvm/llvm-project/pull/104102
More information about the llvm-commits
mailing list