Skip to content

Commit 63e17eb

Browse files
committed
Add options to dump block frequency/branch probability info in text.
Summary: Add options -print-bfi/-print-bpi that dump block frequency and branch probability info like -view-block-freq-propagation-dags and -view-machine-block-freq-propagation-dags do but in text. This is useful when the graph is very large and complex (the dot command crashes, lines/edges too close to tell apart, hard to navigate without textual search) or simply when text is preferred. Reviewers: davidxl Reviewed By: davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37165 llvm-svn: 311822
1 parent d27386a commit 63e17eb

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/lib/Analysis/BlockFrequencyInfo.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ cl::opt<bool>
7575
"display to only one function, use filtering option "
7676
"-view-bfi-func-name."));
7777

78+
static cl::opt<bool> PrintBlockFreq(
79+
"print-bfi", cl::init(false), cl::Hidden,
80+
cl::desc("Print the block frequency info."));
81+
82+
cl::opt<std::string> PrintBlockFreqFuncName(
83+
"print-bfi-func-name", cl::Hidden,
84+
cl::desc("The option to specify the name of the function "
85+
"whose block frequency info is printed."));
86+
7887
namespace llvm {
7988

8089
static GVDAGType getGVDT() {
@@ -180,6 +189,11 @@ void BlockFrequencyInfo::calculate(const Function &F,
180189
F.getName().equals(ViewBlockFreqFuncName))) {
181190
view();
182191
}
192+
if (PrintBlockFreq &&
193+
(PrintBlockFreqFuncName.empty() ||
194+
F.getName().equals(PrintBlockFreqFuncName))) {
195+
print(dbgs());
196+
}
183197
}
184198

185199
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {

llvm/lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ using namespace llvm;
4444

4545
#define DEBUG_TYPE "branch-prob"
4646

47+
static cl::opt<bool> PrintBranchProb(
48+
"print-bpi", cl::init(false), cl::Hidden,
49+
cl::desc("Print the branch probability info."));
50+
51+
cl::opt<std::string> PrintBranchProbFuncName(
52+
"print-bpi-func-name", cl::Hidden,
53+
cl::desc("The option to specify the name of the function "
54+
"whose branch probability info is printed."));
55+
4756
INITIALIZE_PASS_BEGIN(BranchProbabilityInfoWrapperPass, "branch-prob",
4857
"Branch Probability Analysis", false, true)
4958
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
@@ -790,6 +799,12 @@ void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI,
790799

791800
PostDominatedByUnreachable.clear();
792801
PostDominatedByColdCall.clear();
802+
803+
if (PrintBranchProb &&
804+
(PrintBranchProbFuncName.empty() ||
805+
F.getName().equals(PrintBranchProbFuncName))) {
806+
print(dbgs());
807+
}
793808
}
794809

795810
void BranchProbabilityInfoWrapperPass::getAnalysisUsage(

llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ extern cl::opt<std::string> ViewBlockFreqFuncName;
6868
// Defined in Analysis/BlockFrequencyInfo.cpp: -view-hot-freq-perc=
6969
extern cl::opt<unsigned> ViewHotFreqPercent;
7070

71+
static cl::opt<bool> PrintMachineBlockFreq(
72+
"print-machine-bfi", cl::init(false), cl::Hidden,
73+
cl::desc("Print the machine block frequency info."));
74+
75+
// Command line option to specify the name of the function for block frequency
76+
// dump. Defined in Analysis/BlockFrequencyInfo.cpp.
77+
extern cl::opt<std::string> PrintBlockFreqFuncName;
78+
7179
static GVDAGType getGVDT() {
7280
if (ViewBlockLayoutWithBFI != GVDT_None)
7381
return ViewBlockLayoutWithBFI;
@@ -185,6 +193,11 @@ void MachineBlockFrequencyInfo::calculate(
185193
F.getName().equals(ViewBlockFreqFuncName))) {
186194
view("MachineBlockFrequencyDAGS." + F.getName());
187195
}
196+
if (PrintMachineBlockFreq &&
197+
(PrintBlockFreqFuncName.empty() ||
198+
F.getName().equals(PrintBlockFreqFuncName))) {
199+
MBFI->print(dbgs());
200+
}
188201
}
189202

190203
bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {

0 commit comments

Comments
 (0)