0
|
1 /*
|
|
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 #ifndef PRODUCT
|
|
26
|
|
27 class Compile;
|
|
28 class PhaseIFG;
|
|
29 class PhaseChaitin;
|
|
30 class Matcher;
|
|
31 class Node;
|
|
32 class InlineTree;
|
|
33 class ciMethod;
|
|
34
|
|
35 class IdealGraphPrinter
|
|
36 {
|
|
37 private:
|
|
38
|
|
39 enum State
|
|
40 {
|
|
41 Invalid,
|
|
42 Valid,
|
|
43 New
|
|
44 };
|
|
45
|
|
46 private:
|
|
47
|
|
48 static const char *INDENT;
|
|
49 static const char *TOP_ELEMENT;
|
|
50 static const char *GROUP_ELEMENT;
|
|
51 static const char *GRAPH_ELEMENT;
|
|
52 static const char *PROPERTIES_ELEMENT;
|
|
53 static const char *EDGES_ELEMENT;
|
|
54 static const char *PROPERTY_ELEMENT;
|
|
55 static const char *EDGE_ELEMENT;
|
|
56 static const char *NODE_ELEMENT;
|
|
57 static const char *NODES_ELEMENT;
|
|
58 static const char *CONTROL_FLOW_ELEMENT;
|
|
59 static const char *REMOVE_EDGE_ELEMENT;
|
|
60 static const char *REMOVE_NODE_ELEMENT;
|
|
61 static const char *METHOD_NAME_PROPERTY;
|
|
62 static const char *BLOCK_NAME_PROPERTY;
|
|
63 static const char *BLOCK_DOMINATOR_PROPERTY;
|
|
64 static const char *BLOCK_ELEMENT;
|
|
65 static const char *SUCCESSORS_ELEMENT;
|
|
66 static const char *SUCCESSOR_ELEMENT;
|
|
67 static const char *METHOD_IS_PUBLIC_PROPERTY;
|
|
68 static const char *METHOD_IS_STATIC_PROPERTY;
|
|
69 static const char *TRUE_VALUE;
|
|
70 static const char *NODE_NAME_PROPERTY;
|
|
71 static const char *EDGE_NAME_PROPERTY;
|
|
72 static const char *NODE_ID_PROPERTY;
|
|
73 static const char *FROM_PROPERTY;
|
|
74 static const char *TO_PROPERTY;
|
|
75 static const char *PROPERTY_NAME_PROPERTY;
|
|
76 static const char *GRAPH_NAME_PROPERTY;
|
|
77 static const char *INDEX_PROPERTY;
|
|
78 static const char *METHOD_ELEMENT;
|
|
79 static const char *INLINE_ELEMENT;
|
|
80 static const char *BYTECODES_ELEMENT;
|
|
81 static const char *METHOD_BCI_PROPERTY;
|
|
82 static const char *METHOD_SHORT_NAME_PROPERTY;
|
|
83 static const char *ASSEMBLY_ELEMENT;
|
|
84
|
|
85 class Property {
|
|
86
|
|
87 private:
|
|
88
|
|
89 const char *_name;
|
|
90 const char *_value;
|
|
91
|
|
92 public:
|
|
93
|
|
94 Property();
|
|
95 Property(const Property* p);
|
|
96 ~Property();
|
|
97 Property(const char *name, const char *value);
|
|
98 Property(const char *name, int value);
|
|
99 bool equals(Property* p);
|
|
100 void print(IdealGraphPrinter *printer);
|
|
101 void print_as_attribute(IdealGraphPrinter *printer);
|
|
102 bool is_null();
|
|
103 void clean();
|
|
104 const char *name();
|
|
105
|
|
106 static const char* dup(const char *str) {
|
|
107 char * copy = new char[strlen(str)+1];
|
|
108 strcpy(copy, str);
|
|
109 return copy;
|
|
110 }
|
|
111
|
|
112 };
|
|
113
|
|
114 class Properties {
|
|
115
|
|
116 private:
|
|
117
|
|
118 GrowableArray<Property *> *list;
|
|
119
|
|
120 public:
|
|
121
|
|
122 Properties();
|
|
123 ~Properties();
|
|
124 void add(Property *p);
|
|
125 void remove(const char *name);
|
|
126 bool equals(Properties* p);
|
|
127 void print(IdealGraphPrinter *printer);
|
|
128 void print_as_attributes(IdealGraphPrinter *printer);
|
|
129 void clean();
|
|
130
|
|
131 };
|
|
132
|
|
133
|
|
134 class Description {
|
|
135
|
|
136 private:
|
|
137
|
|
138 State _state;
|
|
139
|
|
140 public:
|
|
141
|
|
142 Description();
|
|
143
|
|
144 State state();
|
|
145 void set_state(State s);
|
|
146 void print(IdealGraphPrinter *printer);
|
|
147 virtual void print_changed(IdealGraphPrinter *printer) = 0;
|
|
148 virtual void print_removed(IdealGraphPrinter *printer) = 0;
|
|
149
|
|
150 };
|
|
151
|
|
152 class NodeDescription : public Description{
|
|
153
|
|
154 public:
|
|
155
|
|
156 static int count;
|
|
157
|
|
158 private:
|
|
159
|
|
160 GrowableArray<NodeDescription *> _succs;
|
|
161 int _block_index;
|
|
162 uintptr_t _id;
|
|
163 Properties _properties;
|
|
164 Node* _node;
|
|
165
|
|
166 public:
|
|
167
|
|
168 NodeDescription(Node* node);
|
|
169 ~NodeDescription();
|
|
170 Node* node();
|
|
171
|
|
172 // void set_node(Node* node);
|
|
173 GrowableArray<NodeDescription *>* succs();
|
|
174 void init_succs();
|
|
175 void clear_succs();
|
|
176 void add_succ(NodeDescription *desc);
|
|
177 int block_index();
|
|
178 void set_block_index(int i);
|
|
179 Properties* properties();
|
|
180 virtual void print_changed(IdealGraphPrinter *printer);
|
|
181 virtual void print_removed(IdealGraphPrinter *printer);
|
|
182 bool equals(NodeDescription *desc);
|
|
183 uint id();
|
|
184
|
|
185 };
|
|
186
|
|
187 class Block {
|
|
188
|
|
189 private:
|
|
190
|
|
191 NodeDescription *_start;
|
|
192 NodeDescription *_proj;
|
|
193 GrowableArray<int> _succs;
|
|
194 GrowableArray<NodeDescription *> _nodes;
|
|
195 GrowableArray<int> _dominates;
|
|
196 GrowableArray<int> _children;
|
|
197 int _semi;
|
|
198 int _parent;
|
|
199 GrowableArray<int> _pred;
|
|
200 GrowableArray<int> _bucket;
|
|
201 int _index;
|
|
202 int _dominator;
|
|
203 int _ancestor;
|
|
204 int _label;
|
|
205
|
|
206 public:
|
|
207
|
|
208 Block();
|
|
209 Block(int index);
|
|
210
|
|
211 void add_node(NodeDescription *n);
|
|
212 GrowableArray<NodeDescription *>* nodes();
|
|
213 GrowableArray<int>* children();
|
|
214 void add_child(int i);
|
|
215 void add_succ(int index);
|
|
216 GrowableArray<int>* succs();
|
|
217 GrowableArray<int>* dominates();
|
|
218 void add_dominates(int i);
|
|
219 NodeDescription *start();
|
|
220 NodeDescription *proj();
|
|
221 void set_start(NodeDescription *n);
|
|
222 void set_proj(NodeDescription *n);
|
|
223
|
|
224 int label();
|
|
225 void set_label(int i);
|
|
226 int ancestor();
|
|
227 void set_ancestor(int i);
|
|
228 int index();
|
|
229 int dominator();
|
|
230 void set_dominator(int i);
|
|
231 int parent();
|
|
232 void set_parent(int i);
|
|
233 int semi();
|
|
234 GrowableArray<int>* bucket();
|
|
235 void add_to_bucket(int i);
|
|
236 void clear_bucket();
|
|
237 GrowableArray<int>* pred();
|
|
238 void set_semi(int i);
|
|
239 void add_pred(int i);
|
|
240
|
|
241 };
|
|
242
|
|
243 class EdgeDescription : public Description {
|
|
244
|
|
245 private:
|
|
246
|
|
247 int _from;
|
|
248 int _to;
|
|
249 int _index;
|
|
250 public:
|
|
251
|
|
252 EdgeDescription(int from, int to, int index);
|
|
253 ~EdgeDescription();
|
|
254
|
|
255 virtual void print_changed(IdealGraphPrinter *printer);
|
|
256 virtual void print_removed(IdealGraphPrinter *printer);
|
|
257 bool equals(EdgeDescription *desc);
|
|
258 int from();
|
|
259 int to();
|
|
260 };
|
|
261
|
|
262
|
|
263 static int _file_count;
|
|
264 networkStream *_stream;
|
|
265 outputStream *_output;
|
|
266 ciMethod *_current_method;
|
|
267 GrowableArray<NodeDescription *> _nodes;
|
|
268 GrowableArray<EdgeDescription *> _edges;
|
|
269 int _depth;
|
|
270 Arena *_arena;
|
|
271 char buffer[128];
|
|
272 bool _should_send_method;
|
|
273 PhaseChaitin* _chaitin;
|
|
274 bool _clear_nodes;
|
|
275 Matcher* _matcher;
|
|
276 bool _traverse_outs;
|
|
277
|
|
278 void start_element_helper(const char *name, Properties *properties, bool endElement, bool print_indent = false, bool print_return = true);
|
|
279 NodeDescription *create_node_description(Node* node);
|
|
280
|
|
281 static void pre_node(Node* node, void *env);
|
|
282 static void post_node(Node* node, void *env);
|
|
283
|
|
284 void schedule_latest(int **common_dominator, GrowableArray<Block>* blocks);
|
|
285 void build_common_dominator(int **common_dominator, int index, GrowableArray<Block>* blocks);
|
|
286 void compress(int index, GrowableArray<Block>* blocks);
|
|
287 int eval(int index, GrowableArray<Block>* blocks);
|
|
288 void link(int index1, int index2, GrowableArray<Block>* blocks);
|
|
289 void build_dominators(GrowableArray<Block>* blocks);
|
|
290 void build_blocks(Node *node);
|
|
291 void walk(Node *n);
|
|
292 void start_element(const char *name, Properties *properties = NULL, bool print_indent = false, bool print_return = true);
|
|
293 void simple_element(const char *name, Properties *properties = NULL, bool print_indent = false);
|
|
294 void end_element(const char *name, bool print_indent = false, bool print_return = true);
|
|
295 void print_edge(int from, int to, int index);
|
|
296 void print_indent();
|
|
297 void print_method(ciMethod *method, int bci, InlineTree *tree);
|
|
298 void print_inline_tree(InlineTree *tree);
|
|
299 void clear_nodes();
|
|
300
|
|
301 IdealGraphPrinter();
|
|
302 ~IdealGraphPrinter();
|
|
303
|
|
304 public:
|
|
305
|
|
306 static void clean_up();
|
|
307 static IdealGraphPrinter *printer();
|
|
308
|
|
309 bool traverse_outs();
|
|
310 void set_traverse_outs(bool b);
|
|
311 void print_ifg(PhaseIFG* ifg);
|
|
312 outputStream *output();
|
|
313 void print_inlining(Compile* compile);
|
|
314 void begin_method(Compile* compile);
|
|
315 void end_method();
|
|
316 void print_method(Compile* compile, const char *name, int level=1, bool clear_nodes = false);
|
|
317 void print(Compile* compile, const char *name, Node *root, int level=1, bool clear_nodes = false);
|
|
318 void print_xml(const char *name);
|
|
319
|
|
320
|
|
321 };
|
|
322
|
|
323 #endif
|