-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cc
More file actions
198 lines (172 loc) · 4.56 KB
/
Copy pathGraph.cc
File metadata and controls
198 lines (172 loc) · 4.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* @file Graph.cc
*
* Copyright ©2017 NagraFrance
*/
#include "Graph.h"
using namespace std;
cpad::Graph::Graph(uuid_t grid, int start_checkpoint)
: m_entry(nullptr),
_has_entry(false),
m_cunits_ptr(),
m_checkpoint(start_checkpoint)
{
uuid_copy(m_grid, grid);
}
cpad::Graph::Graph(int start_checkpoint)
: cpad::Graph((unsigned char *)NULL_GRID, start_checkpoint)
{
uuid_generate(m_grid);
}
cpad::Graph::~Graph()
{
}
cpad::Graph::Graph(Graph const& a_graph_to_copy)
: Graph((unsigned char *)a_graph_to_copy.m_grid, a_graph_to_copy.m_checkpoint)
{
m_entry = a_graph_to_copy.m_entry;
_has_entry = a_graph_to_copy._has_entry;
m_cunits_ptr = a_graph_to_copy.m_cunits_ptr;
}
cpad::Graph&
cpad::Graph::operator = (cpad::Graph const& a_graph_to_affect)
{
uuid_copy(m_grid, a_graph_to_affect.m_grid);
m_checkpoint = a_graph_to_affect.m_checkpoint;
m_entry = a_graph_to_affect.m_entry;
_has_entry = a_graph_to_affect._has_entry;
m_cunits_ptr = a_graph_to_affect.m_cunits_ptr;
return (*this);
}
const char *
cpad::Graph::get_name(const char **out)
{
if (out == (const char **)NULL)
throw std::invalid_argument("Invalid NULL pointer argument for returning name");
if (uuid_is_null(m_grid))
throw std::logic_error("Graph has a null graph identifier");
uuid_unparse_upper(m_grid, (char *)*out);
return (*out);
}
void
cpad::Graph::add_cunit(shared_ptr<cpad::CUnit> a_cunit)
{
m_cunits_ptr.push_back(a_cunit);
}
void
cpad::Graph::add_cunit(cpad::CUnit *&a_cunit)
{
add_cunit(shared_ptr<cpad::CUnit>(a_cunit));
}
vector<shared_ptr<cpad::CUnit>>
cpad::Graph::get_cunits(void)
{
return m_cunits_ptr;
}
void
cpad::Graph::set_entry(shared_ptr<cpad::CUnit> an_entry)
{
if (_has_entry)
throw std::logic_error("Graph already has an entry point");
m_entry = an_entry;
_has_entry = true;
}
void
cpad::Graph::set_entry(cpad::CUnit *&an_entry)
{
set_entry(shared_ptr<cpad::CUnit>(an_entry));
}
bool
cpad::Graph::has_entry(void)
{
return _has_entry;
}
shared_ptr<cpad::CUnit>
cpad::Graph::get_entry(void)
{
return m_entry;
}
void
cpad::Graph::dump(std::ostream &os)
{
char uuid[50];
uuid_unparse_upper(m_grid, uuid);
os << "digraph {\n";
os << " node [shape=plaintext];\n";
os << " clusterrank=\"local\";\n";
os << " label=\"Compilation Graph ID: " << uuid << "\";\n";
os << " labeljust=r;\n";
os << " fontname=\"Terminus\";\n";
if (_has_entry)
{
os << " comment=\"Entry point is in compilation unit '" << get_entry()->get_filename() << "'\";\n";
if (get_entry()->has_entry())
{
os << " comment=\"and in function '" << get_entry()->get_entry()->get_name() << "'\";\n";
if (get_entry()->get_entry()->has_entry())
{
os << " comment=\"and in basic_block '" << get_entry()->get_entry()->get_entry()->get_name() << "'\";\n";
}
}
os << " \n";
os << " ENTRY [shape=circle,style=filled,fontcolor=white,color=black,fixedsize=true,fontsize=8,width=0.4,label=\"Entry\"];\n";
os << " \n";
}
for (vector<shared_ptr<CUnit>>::iterator it = m_cunits_ptr.begin();
it != m_cunits_ptr.end();
it++)
{
shared_ptr<CUnit> cunit = *it;
(*cunit).dump(os);
}
if (_has_entry && get_entry()->has_entry() && get_entry()->get_entry()->has_entry())
{
Func entry_func = *(get_entry()->get_entry());
Node entry_node = *(get_entry()->get_entry()->get_entry());
os << " \n";
os << " ENTRY -> " << entry_node.get_cluster_name() << "[style=\"dotted,bold\",color=red,weight=3,constraint=false,decorate=false];\n";
os << " \n";
}
os << "}\n";
}
int
cpad::Graph::get_current_checkpoint()
{
return m_checkpoint;
}
void
cpad::Graph::add_node(const shared_ptr<cpad::Node> &a_shared_node_ptr)
{
add_node(weak_ptr<cpad::Node>(a_shared_node_ptr));
}
void
cpad::Graph::add_node(const weak_ptr<cpad::Node> &a_weak_node_ptr)
{
m_all_nodes.push_back(a_weak_node_ptr);
}
void
cpad::Graph::add_node(cpad::Node * const &a_node_ptr)
{
add_node(shared_ptr<cpad::Node>(a_node_ptr));
}
vector<weak_ptr<cpad::Node>>
cpad::Graph::get_all_nodes(void)
{
return m_all_nodes;
}
void
cpad::Graph::allocate_cfi_apex(void)
{
cerr << "Starting APEX allocation: current checkpoint: " << get_current_checkpoint() << "\n";
cerr << "Computing ancestors ...\n";
for (auto it = m_all_nodes.begin();
it != m_all_nodes.end();
it++)
{
if (auto node_ptr = (*it).lock())
{
node_ptr->compute_ancestors();
node_ptr->dump_ancestors();
}
}
}