Go to the documentation of this file.
18 #ifndef LLVM_ANALYSIS_CFGPRINTER_H
19 #define LLVM_ANALYSIS_CFGPRINTER_H
33 template <
class GraphType>
struct GraphTraits;
69 :
F(
F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq) {
84 return BFI->getBlockFreq(
BB).getFrequency();
135 if (!
Node->getName().empty())
136 return Node->getName().str();
146 OutStr.erase(OutStr.begin() +
I, OutStr.begin() + Idx);
156 HandleComment = eraseComment) {
157 enum { MaxColumns = 80 };
159 raw_string_ostream OS(Str);
161 if (
Node->getName().empty()) {
166 HandleBasicBlock(OS, *
Node);
167 std::string OutStr = OS.
str();
168 if (OutStr[0] ==
'\n')
169 OutStr.erase(OutStr.begin());
173 unsigned LastSpace = 0;
174 for (
unsigned i = 0;
i != OutStr.length(); ++
i) {
175 if (OutStr[
i] ==
'\n') {
177 OutStr.insert(OutStr.begin() +
i + 1,
'l');
180 }
else if (OutStr[
i] ==
';') {
181 unsigned Idx = OutStr.find(
'\n',
i + 1);
182 HandleComment(OutStr,
i, Idx);
183 }
else if (ColNum == MaxColumns) {
187 OutStr.insert(LastSpace,
"\\l...");
188 ColNum =
i - LastSpace;
193 if (OutStr[
i] ==
' ')
202 return getSimpleNodeLabel(
Node, CFGInfo);
204 return getCompleteNodeLabel(
Node, CFGInfo);
210 if (
const BranchInst *BI = dyn_cast<BranchInst>(
Node->getTerminator()))
211 if (BI->isConditional())
216 unsigned SuccNo =
I.getSuccessorIndex();
224 OS << Case.getCaseValue()->getValue();
240 unsigned OpNo =
I.getSuccessorIndex();
247 double WeightPercent = ((
double)BranchProb.getNumerator()) /
248 ((
double)BranchProb.getDenominator());
249 double Width = 1 + WeightPercent;
252 return formatv(
"label=\"{0:P}\" penwidth={1}", WeightPercent,
Width)
259 std::string
Attrs =
formatv(
"label=\"W:{0}\" penwidth={1}",
269 if (MDName->
getString() !=
"branch_weights")
272 OpNo =
I.getSuccessorIndex() + 1;
276 mdconst::dyn_extract<ConstantInt>(WeightsNode->
getOperand(OpNo));
290 std::string EdgeColor = (Freq <= (CFGInfo->
getMaxFreq() / 2))
294 std::string
Attrs =
"color=\"" + EdgeColor +
"ff\", style=filled," +
295 " fillcolor=\"" + Color +
"70\"";
299 void computeDeoptOrUnreachablePaths(
const Function *
F);
A set of analyses that are preserved following a run of a transformation pass.
FunctionPass * createCFGOnlyPrinterLegacyPassPass()
This is an optimization pass for GlobalISel generic memory operations.
DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI, const BranchProbabilityInfo *BPI, uint64_t MaxFreq)
A CRTP mix-in to automatically provide informational APIs needed for passes.
void setHeatColors(bool ShowHeat)
A raw_ostream that writes to an std::string.
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in and only one load from a constant double
const BasicBlock & getEntryBlock() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
const BlockFrequencyInfo * getBFI() const
void setEdgeWeights(bool EdgeWeights)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
std::string getHeatColor(uint64_t freq, uint64_t maxFreq)
LLVM Basic Block Representation.
static std::string getGraphName(DOTFuncInfo *CFGInfo)
unsigned getNumOperands() const
Return number of MDNode operands.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
This is the shared class of boolean and integer constants.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
static nodes_iterator nodes_begin(DOTFuncInfo *CFGInfo)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Analysis providing branch probability information.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI, unsigned SuccessorIndex)
Initializes case iterator for given SwitchInst and for given successor index.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
static NodeRef getEntryNode(DOTFuncInfo *CFGInfo)
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
An efficient, type-erasing, non-owning reference to a callable.
const MDOperand & getOperand(unsigned I) const
uint64_t getMaxFreq() const
FunctionPass * createCFGPrinterLegacyPassPass()
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
StandardInstrumentations SI(Debug, VerifyEach)
static nodes_iterator nodes_end(DOTFuncInfo *CFGInfo)
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
std::string getNodeLabel(const BasicBlock *Node, DOTFuncInfo *CFGInfo)
static size_t size(DOTFuncInfo *CFGInfo)
StringRef getName() const
Return a constant reference to the value's name.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
std::string getEdgeAttributes(const BasicBlock *Node, const_succ_iterator I, DOTFuncInfo *CFGInfo)
Display the raw branch weights from PGO.
static std::string getCompleteNodeLabel(const BasicBlock *Node, DOTFuncInfo *, llvm::function_ref< void(raw_string_ostream &, const BasicBlock &)> HandleBasicBlock=[](raw_string_ostream &OS, const BasicBlock &Node) -> void { OS<< Node;}, llvm::function_ref< void(std::string &, unsigned &, unsigned)> HandleComment=eraseComment)
static std::string getEdgeSourceLabel(const BasicBlock *Node, const_succ_iterator I)
uint64_t getFreq(const BasicBlock *BB) const
std::string getNodeAttributes(const BasicBlock *Node, DOTFuncInfo *CFGInfo)
static bool isSimple(Instruction *I)
void printAsOperand(OutputBuffer &OB, Prec P=Prec::Default, bool StrictlyWorse=false) const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
std::string to_string(const T &Value)
const BranchProbabilityInfo * getBPI() const
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
A container for analyses that lazily runs them and caches their results.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
const Function * getFunction() const
StringRef getString() const
Conditional or Unconditional Branch instruction.
void setRawEdgeWeights(bool RawWeights)
std::string & str()
Returns the string's reference.
DOTGraphTraits(bool isSimple=false)
llvm::DenseMap< const BasicBlock *, bool > isOnDeoptOrUnreachablePath
static std::string getSimpleNodeLabel(const BasicBlock *Node, DOTFuncInfo *)
static void eraseComment(std::string &OutStr, unsigned &I, unsigned Idx)
DOTFuncInfo(const Function *F)