LLVM: lib/Analysis/CFGPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
26
27using namespace llvm;
28
31 cl::desc("The name of a function (or its substring)"
32 " whose CFG is viewed/printed."));
33
35 "cfg-dot-filename-prefix", cl::Hidden,
36 cl::desc("The prefix used for the CFG dot file names."));
37
40
43
45 "cfg-hide-cold-paths", cl::init(0.0),
46 cl::desc("Hide blocks with relative frequency below the given value"));
47
50 cl::desc("Show heat colors in CFG"));
51
54 cl::desc("Use raw weights for labels. "
55 "Use percentages as default."));
56
59 cl::desc("Show edges labeled with weights"));
60
64 std::string Filename =
66 errs() << "Writing '" << Filename << "'...";
67
68 std::error_code EC;
70
75
76 if (!EC)
78 else
79 errs() << " error opening file for writing!";
80 errs() << "\n";
81}
82
93
96 std::optional NodeIdFormatter)
97 : F(F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq),
98 NodeIdFormatter(NodeIdFormatter) {
99 ShowHeat = false;
100 EdgeWeights = !!BPI;
101 RawWeights = !!BFI;
102}
103
105
107 if (!MSTStorage)
108 MSTStorage = std::make_unique(F->getParent());
109 return &*MSTStorage;
110}
111
120
130
140
150
151
152
153
154
155
157
159 viewCFG(false, nullptr, nullptr, OutputFileName);
160}
161
164 const char *OutputFileName) const {
166 return;
168 ViewGraph(&CFGInfo, OutputFileName ? OutputFileName : "cfg" + getName(),
169 ViewCFGOnly);
170}
171
172
173
174
175
176
178
180 viewCFG(true, nullptr, nullptr, OutputFileName);
181}
182
187
188
189
190
191
197 isOnDeoptOrUnreachablePath[Node] =
200 return;
201 }
202 isOnDeoptOrUnreachablePath[Node] =
204 return isOnDeoptOrUnreachablePath[BB];
205 });
206 };
207
208
210}
211
215 if (auto *BFI = CFGInfo->getBFI()) {
218
221 return true;
222 }
224 if (!isOnDeoptOrUnreachablePath.contains(Node))
225 computeDeoptOrUnreachablePaths(Node->getParent());
226 return isOnDeoptOrUnreachablePath[Node];
227 }
228 return false;
229}
230
234 HandleBasicBlock,
235 function_ref<void(std::string &, unsigned &, unsigned)> HandleComment) {
236 if (HandleBasicBlock)
238
239
240 std::optional MSTStorage;
242
243 if (CFGInfo) {
245 } else {
246 MSTStorage.emplace(Node->getModule());
247 MST = &*MSTStorage;
248 }
249
251 Node,
254
255 Node.printAsOperand(OS, false, *MST);
256 OS << ":\n";
257
259 Inst.print(OS, *MST, false);
260 OS << '\n';
261 }
262 }),
263 HandleComment);
264}
static cl::opt< bool > UseRawEdgeWeight("cfg-raw-weights", cl::init(false), cl::Hidden, cl::desc("Use raw weights for labels. " "Use percentages as default."))
static cl::opt< bool > HideUnreachablePaths("cfg-hide-unreachable-paths", cl::init(false))
static void writeCFGToDotFile(Function &F, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, uint64_t MaxFreq, bool CFGOnly=false)
Definition CFGPrinter.cpp:61
static cl::opt< bool > ShowHeatColors("cfg-heat-colors", cl::init(true), cl::Hidden, cl::desc("Show heat colors in CFG"))
static cl::opt< std::string > CFGDotFilenamePrefix("cfg-dot-filename-prefix", cl::Hidden, cl::desc("The prefix used for the CFG dot file names."))
static void viewCFG(Function &F, const BlockFrequencyInfo *BFI, const BranchProbabilityInfo *BPI, uint64_t MaxFreq, bool CFGOnly=false)
Definition CFGPrinter.cpp:83
static cl::opt< double > HideColdPaths("cfg-hide-cold-paths", cl::init(0.0), cl::desc("Hide blocks with relative frequency below the given value"))
static cl::opt< bool > HideDeoptimizePaths("cfg-hide-deoptimize-paths", cl::init(false))
static cl::opt< std::string > CFGFuncName("cfg-func-name", cl::Hidden, cl::desc("The name of a function (or its substring)" " whose CFG is viewed/printed."))
static cl::opt< bool > ShowEdgeWeight("cfg-weights", cl::init(false), cl::Hidden, cl::desc("Show edges labeled with weights"))
static cl::opt< bool > ShowHeatColors("callgraph-heat-colors", cl::init(false), cl::Hidden, cl::desc("Show heat colors in call-graph"))
static cl::opt< bool > ShowEdgeWeight("callgraph-show-weights", cl::init(false), cl::Hidden, cl::desc("Show edges labeled with weights"))
static cl::opt< bool > CFGOnly("dot-mcfg-only", cl::init(false), cl::Hidden, cl::desc("Print only the CFG without blocks body"))
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static StringRef getName(Value *V)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Analysis pass which computes BranchProbabilityInfo.
Analysis providing branch probability information.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition CFGPrinter.cpp:141
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition CFGPrinter.cpp:121
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition CFGPrinter.cpp:131
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition CFGPrinter.cpp:112
void setRawEdgeWeights(bool RawWeights)
void setEdgeWeights(bool EdgeWeights)
DOTFuncInfo(const Function *F)
LLVM_ABI ModuleSlotTracker * getModuleSlotTracker()
Definition CFGPrinter.cpp:106
const BlockFrequencyInfo * getBFI() const
void setHeatColors(bool ShowHeat)
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
Definition CFGPrinter.cpp:156
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
Definition CFGPrinter.cpp:177
Manage lifetime of a slot tracker for printing IR.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
An efficient, type-erasing, non-owning reference to a callable.
A raw_ostream that writes to a file descriptor.
A raw_ostream that writes to an std::string.
initializer< Ty > init(const Ty &Val)
NodeAddr< NodeBase * > Node
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
This is an optimization pass for GlobalISel generic memory operations.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool succ_empty(const Instruction *I)
auto successors(const MachineBasicBlock *BB)
iterator_range< po_iterator< T > > post_order(const T &G)
raw_ostream & WriteGraph(raw_ostream &O, const GraphType &G, bool ShortNames=false, const Twine &Title="")
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
std::string CompleteNodeLabelString(const BasicBlockT *Node, function_ref< void(raw_string_ostream &, const BasicBlockT &)> HandleBasicBlock, function_ref< void(std::string &, unsigned &, unsigned)> HandleComment)
LLVM_ABI uint64_t getMaxFreq(const Function &F, const BlockFrequencyInfo *BFI)
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
static bool isNodeHidden(const void *, const GraphType &)
isNodeHidden - If the function returns true, the given node is not displayed in the graph.