-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphvizDOTDrawer.cpp
More file actions
84 lines (78 loc) · 2.92 KB
/
GraphvizDOTDrawer.cpp
File metadata and controls
84 lines (78 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "GraphvizDOTDrawer.h"
#include <cassert>
void GraphvizDOTDrawer::declareExpr(const Expr *e, const char *category) {
std::string label;
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(e)) {
label = std::to_string(CE->getZExtValue());
} else {
label = e->getKindStr();
}
os << (size_t)e << "[ label=\"" << label << "\", "
<< "Kind=" << e->getKind() << ","
<< "Width=" << e->getWidth() << ","
<< "Category=" << category << ","
<< "KInst=\"" << e->getKInstUniqueID() << "\""
<< ","
<< "DbgInfo=\"" << e->getKInstDbgInfo() << "\""
<< ","
<< "IsPointer=" << e->getKInstIsPtrType() << ","
<< "Freq=" << e->getKInstLoadedFreq();
if (const ReadExpr *RE = dyn_cast<ReadExpr>(e)) {
os << ", Root=\"" << getArrWithSize(RE->updates.root) << "\"";
}
os << "];\n";
}
void GraphvizDOTDrawer::declareLastLevelRead(const ReadExpr *RE,
const char *category) {
std::string label;
const ConstantExpr *CE = dyn_cast<ConstantExpr>(RE->index);
label =
RE->updates.root->name + "[" + std::to_string(CE->getZExtValue()) + "]";
os << (size_t)RE << "[ label=\"" << label << "\", "
<< "Kind=" << RE->getKind() << ","
<< "Width=" << RE->getWidth() << ","
<< "Category=" << category << ","
<< "KInst=\"" << RE->getKInstUniqueID() << "\""
<< ","
<< "DbgInfo=\"" << RE->getKInstDbgInfo() << "\""
<< ","
<< "IsPointer=" << RE->getKInstIsPtrType() << ","
<< "Root=\"" << getArrWithSize(RE->updates.root) << "\","
<< "Freq=" << RE->getKInstLoadedFreq() << "];\n";
}
void GraphvizDOTDrawer::declareUpdateNode(const UpdateNode *un,
const Array *root,
const char *category) {
os << (size_t)un << "[ label=\"UN\", Kind=UN , "
<< "Category=" << category << ","
<< "Width=8,"
<< "Root=\"" << getArrWithSize(root) << "\","
<< "KInst=\"" << un->getKInstUniqueID() << "\""
<< ","
<< "DbgInfo=\"" << un->getKInstDbgInfo() << "\""
<< ","
<< "Flags=\"" << std::to_string(un->flags) << "\""
<< ","
<< "IsPointer=" << false << ","
<< "Freq=" << un->getKInstLoadedFreq() << "];\n";
}
void GraphvizDOTDrawer::declareArray(const Array *arr) {
os << (size_t)arr << "[ label=\"" << arr->name << "\", "
<< "Kind=Array,"
<< "Size=" << arr->getSize() << ","
<< "Category=Array"
<< "];\n";
}
void GraphvizDOTDrawer::drawEdge(const void *from, const void *to,
double weight) {
os << (size_t)from << " -> " << (size_t)to
<< "[weight=" << std::to_string(weight) << "]"
<< ";\n";
}
void GraphvizDOTDrawer::printHeader() { os << "digraph{\n"; }
void GraphvizDOTDrawer::printFooter() {
os << "dummyA[label=\"dummyA\", IDep=\"-1\"];\n"
<< "dummyB[label=\"dummyB\", IDep=\"-1\"];\n"
<< "dummyA -> dummyB [weight=5.0];\n"
<< "}\n";
}