31 cl::desc(
"The name of a function (or its substring)"
32 " whose CFG is viewed/printed."));
36 cl::desc(
"The prefix used for the CFG dot file names."));
45 "cfg-hide-cold-paths",
cl::init(0.0),
46 cl::desc(
"Hide blocks with relative frequency below the given value"));
50 cl::desc(
"Show heat colors in CFG"));
54 cl::desc(
"Use raw weights for labels. "
55 "Use percentages as default."));
59 cl::desc(
"Show edges labeled with weights"));
64 std::string Filename =
66 errs() <<
"Writing '" << Filename <<
"'...";
79 errs() <<
" error opening file for writing!";
96 :
F(
F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq) {
106 MSTStorage = std::make_unique<ModuleSlotTracker>(F->
getParent());
157 viewCFG(
false,
nullptr,
nullptr, OutputFileName);
162 const char *OutputFileName)
const {
178 viewCFG(
true,
nullptr,
nullptr, OutputFileName);
192 auto evaluateBB = [&](
const BasicBlock *Node) {
195 isOnDeoptOrUnreachablePath[Node] =
200 isOnDeoptOrUnreachablePath[
Node] =
202 return isOnDeoptOrUnreachablePath[BB];
213 if (
auto *BFI = CFGInfo->
getBFI()) {
222 if (!isOnDeoptOrUnreachablePath.contains(
Node))
223 computeDeoptOrUnreachablePaths(
Node->getParent());
224 return isOnDeoptOrUnreachablePath[
Node];
233 function_ref<
void(std::string &,
unsigned &,
unsigned)> HandleComment) {
234 if (HandleBasicBlock)
238 std::optional<ModuleSlotTracker> MSTStorage;
244 MSTStorage.emplace(
Node->getModule());
257 Inst.print(
OS, *MST,
false);
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)
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)
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 > 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 bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
void printAsOperand(OutputBuffer &OB, Prec P=Prec::Default, bool StrictlyWorse=false) const
A container for analyses that lazily runs them and caches their results.
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)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
void setRawEdgeWeights(bool RawWeights)
void setEdgeWeights(bool EdgeWeights)
DOTFuncInfo(const Function *F)
LLVM_ABI ModuleSlotTracker * getModuleSlotTracker()
const BlockFrequencyInfo * getBFI() const
void setHeatColors(bool ShowHeat)
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
Module * getParent()
Get the module that this global value is contained inside of...
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)
@ 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="")
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.
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.