18#ifndef LLVM_ANALYSIS_CFGPRINTER_H
19#define LLVM_ANALYSIS_CFGPRINTER_H
66 std::unique_ptr<ModuleSlotTracker> MSTStorage;
71 using NodeIdFormatterTy =
72 std::function<std::optional<std::string>(
const BasicBlock *)>;
73 std::optional<NodeIdFormatterTy> NodeIdFormatter;
82 std::optional<NodeIdFormatterTy> NodeIdFormatter = std::nullopt);
95 return BFI->getBlockFreq(BB).getFrequency();
111 return NodeIdFormatter;
137template <
typename BasicBlockT>
139 if (!
Node->getName().empty())
140 return Node->getName().str();
149template <
typename BasicBlockT>
151 const BasicBlockT *
Node,
157 enum { MaxColumns = 80 };
160 HandleBasicBlock(OS, *
Node);
162 if (OutStr[0] ==
'%') {
163 OutStr.erase(OutStr.begin());
166 OutStr.insert(OutStr.find_first_of(
'\n') + 1,
"\\|");
169 unsigned LastSpace = 0;
170 for (
unsigned i = 0; i != OutStr.length(); ++i) {
171 if (OutStr[i] ==
'\n') {
173 OutStr.insert(OutStr.begin() + i + 1,
'l');
176 }
else if (OutStr[i] ==
';') {
177 unsigned Idx = OutStr.find(
'\n', i + 1);
178 HandleComment(OutStr, i, Idx);
179 }
else if (ColNum == MaxColumns) {
183 OutStr.insert(LastSpace,
"\\l...");
184 ColNum = i - LastSpace;
189 if (OutStr[i] ==
' ')
204 OutStr.erase(OutStr.begin() +
I, OutStr.begin() + Idx);
219 HandleBasicBlock = {},
220 function_ref<void(std::string &,
unsigned &,
unsigned)> HandleComment =
247 OS << Case.getCaseValue()->getValue();
254 std::string NodeName =
Node->getName().str();
255 if (NodeName.empty()) {
259 NodeName.erase(NodeName.begin());
275 double WeightPercent = ((double)BranchProb.getNumerator()) /
276 ((double)BranchProb.getDenominator());
282 return TTAttr +
"penwidth=2";
287 double Width = 1 + WeightPercent;
291 formatv(
"label=\"{0:P}\" penwidth={1}", WeightPercent, Width)
299 TTAttr +
formatv(
"label=\"W:{0}\" penwidth={1}",
300 (
uint64_t)(Freq * WeightPercent), Width)
316 return (TTAttr +
"label=\"W:" + std::to_string(Weight->
getZExtValue()) +
317 "\" penwidth=" + std::to_string(Width));
321 std::stringstream Attrs;
324 if (
auto NodeId = (*NodeIdFmt)(
Node))
325 Attrs <<
"id=\"" << *NodeId <<
"\"";
330 std::string EdgeColor = (Freq <= (CFGInfo->
getMaxFreq() / 2))
333 if (!Attrs.str().empty())
335 Attrs <<
"color=\"" << EdgeColor <<
"ff\", style=filled, "
336 <<
"fillcolor=\"" << Color <<
"70\", " <<
"fontname=\"Courier\"";
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
This file contains the declarations for profiling metadata utility functions.
static bool isSimple(Instruction *I)
static std::string getBBName(const MachineBasicBlock *MBB)
void printAsOperand(OutputBuffer &OB, Prec P=Prec::Default, bool StrictlyWorse=false) const
LLVM Basic Block Representation.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
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)
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void setRawEdgeWeights(bool RawWeights)
uint64_t getMaxFreq() const
void setEdgeWeights(bool EdgeWeights)
DOTFuncInfo(const Function *F)
uint64_t getFreq(const BasicBlock *BB) const
std::optional< NodeIdFormatterTy > getNodeIdFormatter()
const BranchProbabilityInfo * getBPI() const
LLVM_ABI ModuleSlotTracker * getModuleSlotTracker()
const Function * getFunction() const
const BlockFrequencyInfo * getBFI() const
void setHeatColors(bool ShowHeat)
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
Manage lifetime of a slot tracker for printing IR.
A set of analyses that are preserved following a run of a transformation pass.
std::string str() const
Get the contents as an std::string.
static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI, unsigned SuccessorIndex)
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 an std::string.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
std::string SimpleNodeLabelString(const BasicBlockT *Node)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
LLVM_ABI std::string getHeatColor(uint64_t Freq, uint64_t MaxFreq)
Instruction::const_succ_iterator const_succ_iterator
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)
std::string getEdgeAttributes(const BasicBlock *Node, const_succ_iterator I, DOTFuncInfo *CFGInfo)
Display the raw branch weights from PGO.
static LLVM_ABI std::string getCompleteNodeLabel(const BasicBlock *Node, DOTFuncInfo *, function_ref< void(raw_string_ostream &, const BasicBlock &)> HandleBasicBlock={}, function_ref< void(std::string &, unsigned &, unsigned)> HandleComment=eraseComment)
LLVM_ABI bool isNodeHidden(const BasicBlock *Node, const DOTFuncInfo *CFGInfo)
static std::string getSimpleNodeLabel(const BasicBlock *Node, DOTFuncInfo *)
static std::string getGraphName(DOTFuncInfo *CFGInfo)
DenseMap< const BasicBlock *, bool > isOnDeoptOrUnreachablePath
LLVM_ABI void computeDeoptOrUnreachablePaths(const Function *F)
DOTGraphTraits(bool isSimple=false)
std::string getNodeAttributes(const BasicBlock *Node, DOTFuncInfo *CFGInfo)
static std::string getEdgeSourceLabel(const BasicBlock *Node, const_succ_iterator I)
static void eraseComment(std::string &OutStr, unsigned &I, unsigned Idx)
std::string getNodeLabel(const BasicBlock *Node, DOTFuncInfo *CFGInfo)
static std::string getBBName(const BasicBlock *Node)
DefaultDOTGraphTraits(bool simple=false)
static nodes_iterator nodes_begin(DOTFuncInfo *CFGInfo)
static size_t size(DOTFuncInfo *CFGInfo)
pointer_iterator< Function::const_iterator > nodes_iterator
static NodeRef getEntryNode(DOTFuncInfo *CFGInfo)
static nodes_iterator nodes_end(DOTFuncInfo *CFGInfo)
typename DOTFuncInfo *::UnknownGraphTypeError NodeRef
A CRTP mix-in for passes that should not be skipped.