[PATCH] D77978: [ViewCFG] Allow printing edge weights in debuggers
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 12 12:16:41 PDT 2020
hoyFB created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
hoyFB updated this revision to Diff 256871.
hoyFB added a comment.
hoyFB updated this revision to Diff 256873.
hoyFB added reviewers: wenlei, davidxl, knaumov.
Updating D77978 <https://reviews.llvm.org/D77978>: [ViewCFG] Allow printing edge weights in debuggers
hoyFB added a comment.
Updating D77978 <https://reviews.llvm.org/D77978>: [ViewCFG] Allow printing edge weights in debuggers
Extending the Function::viewCFG prototypes to allow for printing block probability info in form of .dot files during debugging.
Also avoiding an AV when no BFI/BPI available.
Test Plan:
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77978
Files:
llvm/include/llvm/Analysis/CFGPrinter.h
llvm/include/llvm/IR/Function.h
llvm/lib/Analysis/CFGPrinter.cpp
Index: llvm/lib/Analysis/CFGPrinter.cpp
===================================================================
--- llvm/lib/Analysis/CFGPrinter.cpp
+++ llvm/lib/Analysis/CFGPrinter.cpp
@@ -240,11 +240,14 @@
/// program, displaying the CFG of the current function. This depends on there
/// being a 'dot' and 'gv' program in your path.
///
-void Function::viewCFG() const {
+void Function::viewCFG() const { viewCFG(false, nullptr, nullptr); }
+
+void Function::viewCFG(bool viewCFGOnly, BlockFrequencyInfo *BFI,
+ BranchProbabilityInfo *BPI) const {
if (!CFGFuncName.empty() && !getName().contains(CFGFuncName))
return;
- DOTFuncInfo CFGInfo(this);
- ViewGraph(&CFGInfo, "cfg" + getName());
+ DOTFuncInfo CFGInfo(this, BFI, BPI, BFI ? getMaxFreq(*this, BFI) : 0);
+ ViewGraph(&CFGInfo, "cfg" + getName(), viewCFGOnly);
}
/// viewCFGOnly - This function is meant for use from the debugger. It works
@@ -252,11 +255,11 @@
/// into the nodes, just the label. If you are only interested in the CFG
/// this can make the graph smaller.
///
-void Function::viewCFGOnly() const {
- if (!CFGFuncName.empty() && !getName().contains(CFGFuncName))
- return;
- DOTFuncInfo CFGInfo(this);
- ViewGraph(&CFGInfo, "cfg" + getName(), true);
+void Function::viewCFGOnly() const { viewCFGOnly(nullptr, nullptr); }
+
+void Function::viewCFGOnly(BlockFrequencyInfo *BFI,
+ BranchProbabilityInfo *BPI) const {
+ viewCFG(true, BFI, BPI);
}
FunctionPass *llvm::createCFGPrinterLegacyPassPass() {
Index: llvm/include/llvm/IR/Function.h
===================================================================
--- llvm/include/llvm/IR/Function.h
+++ llvm/include/llvm/IR/Function.h
@@ -55,6 +55,8 @@
class raw_ostream;
class Type;
class User;
+class BranchProbabilityInfo;
+class BlockFrequencyInfo;
class Function : public GlobalObject, public ilist_node<Function> {
public:
@@ -792,6 +794,10 @@
///
void viewCFG() const;
+ /// Extended form to print edge weights.
+ void viewCFG(bool viewCFGOnly, BlockFrequencyInfo *BFI,
+ BranchProbabilityInfo *BPI) const;
+
/// viewCFGOnly - This function is meant for use from the debugger. It works
/// just like viewCFG, but it does not include the contents of basic blocks
/// into the nodes, just the label. If you are only interested in the CFG
@@ -799,6 +805,9 @@
///
void viewCFGOnly() const;
+ /// Extended form to print edge weights.
+ void viewCFGOnly(BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI) const;
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == Value::FunctionVal;
Index: llvm/include/llvm/Analysis/CFGPrinter.h
===================================================================
--- llvm/include/llvm/Analysis/CFGPrinter.h
+++ llvm/include/llvm/Analysis/CFGPrinter.h
@@ -67,8 +67,8 @@
BranchProbabilityInfo *BPI, uint64_t MaxFreq)
: F(F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq) {
ShowHeat = false;
- EdgeWeights = true;
- RawWeights = true;
+ EdgeWeights = !!BPI; // Print EdgeWeights when BPI is available.
+ RawWeights = !!BFI; // Print RawWeights when BFI is available.
}
const BlockFrequencyInfo *getBFI() { return BFI; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77978.256873.patch
Type: text/x-patch
Size: 3339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200412/b0ae437d/attachment.bin>
More information about the llvm-commits
mailing list