llvm.org GIT mirror llvm / 828b398
Add support to dump dot graph block layout after MBP Differential Revision: https://reviews.llvm.org/D29141 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293408 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
6 changed file(s) with 71 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
12901290 }
12911291
12921292 std::string getNodeLabel(NodeRef Node, const BlockFrequencyInfoT *Graph,
1293 GVDAGType GType) {
1293 GVDAGType GType, int layout_order = -1) {
12941294 std::string Result;
12951295 raw_string_ostream OS(Result);
12961296
1297 OS << Node->getName().str() << " : ";
1297 if (layout_order != -1)
1298 OS << Node->getName() << "[" << layout_order << "] : ";
1299 else
1300 OS << Node->getName() << " : ";
12981301 switch (GType) {
12991302 case GVDT_Fraction:
13001303 Graph->printBlockFreq(OS, Node);
5555
5656 const MachineFunction *getFunction() const;
5757 const MachineBranchProbabilityInfo *getMBPI() const;
58 void view() const;
58 void view(bool isSimple = true) const;
5959
6060 // Print the block frequency Freq to OS using the current functions entry
6161 // frequency to convert freq into a relative decimal form.
496496 const BlockFrequency Freq) const {
497497 return MBFI.printBlockFreq(OS, Freq);
498498 }
499
500 void BranchFolder::MBFIWrapper::view(bool isSimple) { MBFI.view(isSimple); }
499501
500502 /// CountTerminators - Count the number of terminators in the given
501503 /// block and set I to the position of the first non-terminator, if there
121121 const MachineBasicBlock *MBB) const;
122122 raw_ostream &printBlockFreq(raw_ostream &OS,
123123 const BlockFrequency Freq) const;
124 void view(bool isSimple = true);
124125
125126 private:
126127 const MachineBlockFrequencyInfo &MBFI;
4242 "integer fractional block frequency representation."),
4343 clEnumValN(GVDT_Count, "count", "display a graph using the real "
4444 "profile count if available.")));
45 // Similar option above, but used to control BFI display only after MBP pass
46 cl::opt ViewBlockLayoutWithBFI(
47 "view-block-layout-with-bfi", cl::Hidden,
48 cl::desc(
49 "Pop up a window to show a dag displaying MBP layout and associated "
50 "block frequencies of the CFG."),
51 cl::values(clEnumValN(GVDT_None, "none", "do not display graphs."),
52 clEnumValN(GVDT_Fraction, "fraction",
53 "display a graph using the "
54 "fractional block frequency representation."),
55 clEnumValN(GVDT_Integer, "integer",
56 "display a graph using the raw "
57 "integer fractional block frequency representation."),
58 clEnumValN(GVDT_Count, "count",
59 "display a graph using the real "
60 "profile count if available.")));
4561
4662 extern cl::opt ViewBlockFreqFuncName;
4763 extern cl::opt ViewHotFreqPercent;
64
65 static GVDAGType getGVDT() {
66 if (ViewBlockLayoutWithBFI != GVDT_None)
67 return ViewBlockLayoutWithBFI;
68
69 return ViewMachineBlockFreqPropagationDAG;
70 }
4871
4972 namespace llvm {
5073
79102 struct DOTGraphTraits
80103 : public MBFIDOTGraphTraitsBase {
81104 explicit DOTGraphTraits(bool isSimple = false)
82 : MBFIDOTGraphTraitsBase(isSimple) {}
105 : MBFIDOTGraphTraitsBase(isSimple), CurFunc(nullptr), LayoutOrderMap() {}
106
107 const MachineFunction *CurFunc;
108 DenseMap LayoutOrderMap;
83109
84110 std::string getNodeLabel(const MachineBasicBlock *Node,
85111 const MachineBlockFrequencyInfo *Graph) {
86 return MBFIDOTGraphTraitsBase::getNodeLabel(
87 Node, Graph, ViewMachineBlockFreqPropagationDAG);
112
113 int layout_order = -1;
114 // Attach additional ordering information if 'isSimple' is false.
115 if (!isSimple()) {
116 const MachineFunction *F = Node->getParent();
117 if (!CurFunc || F != CurFunc) {
118 if (CurFunc)
119 LayoutOrderMap.clear();
120
121 CurFunc = F;
122 int O = 0;
123 for (auto MBI = F->begin(); MBI != F->end(); ++MBI, ++O) {
124 LayoutOrderMap[&*MBI] = O;
125 }
126 }
127 layout_order = LayoutOrderMap[Node];
128 }
129 return MBFIDOTGraphTraitsBase::getNodeLabel(Node, Graph, getGVDT(),
130 layout_order);
88131 }
89132
90133 std::string getNodeAttributes(const MachineBasicBlock *Node,
147190
148191 /// Pop up a ghostview window with the current block frequency propagation
149192 /// rendered using dot.
150 void MachineBlockFrequencyInfo::view() const {
193 void MachineBlockFrequencyInfo::view(bool isSimple) const {
151194 // This code is only for debugging.
152195 #ifndef NDEBUG
153196 ViewGraph(const_cast(this),
154 "MachineBlockFrequencyDAGs");
197 "MachineBlockFrequencyDAGs", isSimple);
155198 #else
156199 errs() << "MachineBlockFrequencyInfo::view is only available in debug builds "
157200 "on systems with Graphviz or gv!\n";
3131 #include "llvm/ADT/SmallPtrSet.h"
3232 #include "llvm/ADT/SmallVector.h"
3333 #include "llvm/ADT/Statistic.h"
34 #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
3435 #include "llvm/CodeGen/MachineBasicBlock.h"
3536 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
3637 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
144145
145146 extern cl::opt StaticLikelyProb;
146147 extern cl::opt ProfileLikelyProb;
148
149 #ifndef NDEBUG
150 extern cl::opt ViewBlockLayoutWithBFI;
151 extern cl::opt ViewBlockFreqFuncName;
152 #endif
147153
148154 namespace {
149155 class BlockChain;
20662072 MBI->setAlignment(AlignAllNonFallThruBlocks);
20672073 }
20682074 }
2075 #ifndef NDEBUG
2076 if (ViewBlockLayoutWithBFI != GVDT_None &&
2077 (ViewBlockFreqFuncName.empty() ||
2078 F->getFunction()->getName().equals(ViewBlockFreqFuncName))) {
2079 MBFI->view(false);
2080 }
2081 #endif
2082
20692083
20702084 // We always return true as we have no way to track whether the final order
20712085 // differs from the original order.