annotate src/share/vm/opto/idealGraphPrinter.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children 2a1a77d3458f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_idealGraphPrinter.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Constants
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Keep consistent with Java constants
a61af66fc99e Initial load
duke
parents:
diff changeset
32 const char *IdealGraphPrinter::INDENT = " ";
a61af66fc99e Initial load
duke
parents:
diff changeset
33 const char *IdealGraphPrinter::TOP_ELEMENT = "graphDocument";
a61af66fc99e Initial load
duke
parents:
diff changeset
34 const char *IdealGraphPrinter::GROUP_ELEMENT = "group";
a61af66fc99e Initial load
duke
parents:
diff changeset
35 const char *IdealGraphPrinter::GRAPH_ELEMENT = "graph";
a61af66fc99e Initial load
duke
parents:
diff changeset
36 const char *IdealGraphPrinter::PROPERTIES_ELEMENT = "properties";
a61af66fc99e Initial load
duke
parents:
diff changeset
37 const char *IdealGraphPrinter::EDGES_ELEMENT = "edges";
a61af66fc99e Initial load
duke
parents:
diff changeset
38 const char *IdealGraphPrinter::PROPERTY_ELEMENT = "p";
a61af66fc99e Initial load
duke
parents:
diff changeset
39 const char *IdealGraphPrinter::EDGE_ELEMENT = "edge";
a61af66fc99e Initial load
duke
parents:
diff changeset
40 const char *IdealGraphPrinter::NODE_ELEMENT = "node";
a61af66fc99e Initial load
duke
parents:
diff changeset
41 const char *IdealGraphPrinter::NODES_ELEMENT = "nodes";
a61af66fc99e Initial load
duke
parents:
diff changeset
42 const char *IdealGraphPrinter::REMOVE_EDGE_ELEMENT = "removeEdge";
a61af66fc99e Initial load
duke
parents:
diff changeset
43 const char *IdealGraphPrinter::REMOVE_NODE_ELEMENT = "removeNode";
a61af66fc99e Initial load
duke
parents:
diff changeset
44 const char *IdealGraphPrinter::METHOD_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
45 const char *IdealGraphPrinter::METHOD_IS_PUBLIC_PROPERTY = "public";
a61af66fc99e Initial load
duke
parents:
diff changeset
46 const char *IdealGraphPrinter::METHOD_IS_STATIC_PROPERTY = "static";
a61af66fc99e Initial load
duke
parents:
diff changeset
47 const char *IdealGraphPrinter::TRUE_VALUE = "true";
a61af66fc99e Initial load
duke
parents:
diff changeset
48 const char *IdealGraphPrinter::NODE_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
49 const char *IdealGraphPrinter::EDGE_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
50 const char *IdealGraphPrinter::NODE_ID_PROPERTY = "id";
a61af66fc99e Initial load
duke
parents:
diff changeset
51 const char *IdealGraphPrinter::FROM_PROPERTY = "from";
a61af66fc99e Initial load
duke
parents:
diff changeset
52 const char *IdealGraphPrinter::TO_PROPERTY = "to";
a61af66fc99e Initial load
duke
parents:
diff changeset
53 const char *IdealGraphPrinter::PROPERTY_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
54 const char *IdealGraphPrinter::GRAPH_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
55 const char *IdealGraphPrinter::INDEX_PROPERTY = "index";
a61af66fc99e Initial load
duke
parents:
diff changeset
56 const char *IdealGraphPrinter::METHOD_ELEMENT = "method";
a61af66fc99e Initial load
duke
parents:
diff changeset
57 const char *IdealGraphPrinter::INLINE_ELEMENT = "inline";
a61af66fc99e Initial load
duke
parents:
diff changeset
58 const char *IdealGraphPrinter::BYTECODES_ELEMENT = "bytecodes";
a61af66fc99e Initial load
duke
parents:
diff changeset
59 const char *IdealGraphPrinter::METHOD_BCI_PROPERTY = "bci";
a61af66fc99e Initial load
duke
parents:
diff changeset
60 const char *IdealGraphPrinter::METHOD_SHORT_NAME_PROPERTY = "shortName";
a61af66fc99e Initial load
duke
parents:
diff changeset
61 const char *IdealGraphPrinter::CONTROL_FLOW_ELEMENT = "controlFlow";
a61af66fc99e Initial load
duke
parents:
diff changeset
62 const char *IdealGraphPrinter::BLOCK_NAME_PROPERTY = "name";
a61af66fc99e Initial load
duke
parents:
diff changeset
63 const char *IdealGraphPrinter::BLOCK_DOMINATOR_PROPERTY = "dom";
a61af66fc99e Initial load
duke
parents:
diff changeset
64 const char *IdealGraphPrinter::BLOCK_ELEMENT = "block";
a61af66fc99e Initial load
duke
parents:
diff changeset
65 const char *IdealGraphPrinter::SUCCESSORS_ELEMENT = "successors";
a61af66fc99e Initial load
duke
parents:
diff changeset
66 const char *IdealGraphPrinter::SUCCESSOR_ELEMENT = "successor";
a61af66fc99e Initial load
duke
parents:
diff changeset
67 const char *IdealGraphPrinter::ASSEMBLY_ELEMENT = "assembly";
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int IdealGraphPrinter::_file_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 IdealGraphPrinter *IdealGraphPrinter::printer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (PrintIdealGraphLevel == 0) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 JavaThread *thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (!thread->is_Compiler_thread()) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 CompilerThread *compiler_thread = (CompilerThread *)thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 if (compiler_thread->ideal_graph_printer() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 IdealGraphPrinter *printer = new IdealGraphPrinter();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 compiler_thread->set_ideal_graph_printer(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return compiler_thread->ideal_graph_printer();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void IdealGraphPrinter::clean_up() {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 JavaThread *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 for (p = Threads::first(); p; p = p->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (p->is_Compiler_thread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 CompilerThread *c = (CompilerThread *)p;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 IdealGraphPrinter *printer = c->ideal_graph_printer();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 delete printer;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 c->set_ideal_graph_printer(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Constructor, either file or network output
a61af66fc99e Initial load
duke
parents:
diff changeset
101 IdealGraphPrinter::IdealGraphPrinter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 _traverse_outs = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _should_send_method = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _output = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 buffer[0] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 _depth = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _current_method = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 assert(!_current_method, "current method must be initialized to NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 _arena = new Arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 _stream = new (ResourceObj::C_HEAP) networkStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (PrintIdealGraphFile != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ThreadCritical tc;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // User wants all output to go to files
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (_file_count != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 stringStream st;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 const char* dot = strrchr(PrintIdealGraphFile, '.');
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (dot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 st.write(PrintIdealGraphFile, dot - PrintIdealGraphFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 st.print("%d%s", _file_count, dot);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 st.print("%s%d", PrintIdealGraphFile, _file_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _output = new (ResourceObj::C_HEAP) fileStream(st.as_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
128 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _output = new (ResourceObj::C_HEAP) fileStream(PrintIdealGraphFile);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _file_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Try to connect to visualizer
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (_stream->connect(PrintIdealGraphAddress, PrintIdealGraphPort)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 char c = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 _stream->read(&c, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (c != 'y') {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 tty->print_cr("Client available, but does not want to receive data!");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 _stream->close();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 delete _stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _stream = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _output = _stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // It would be nice if we could shut down cleanly but it should
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // be an error if we can't connect to the visualizer.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 fatal2("Couldn't connect to visualizer at %s:%d", PrintIdealGraphAddress, PrintIdealGraphPort);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 start_element(TOP_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Destructor, close file or network stream
a61af66fc99e Initial load
duke
parents:
diff changeset
156 IdealGraphPrinter::~IdealGraphPrinter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 end_element(TOP_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (_stream) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 delete _stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (_stream == _output) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 _output = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _stream = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (_output) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 delete _output;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _output = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 void IdealGraphPrinter::print_ifg(PhaseIFG* ifg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Code to print an interference graph to tty, currently not used
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (!_current_method) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Remove neighbor colors
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 for (uint i = 0; i < ifg._maxlrg; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 IndexSet *s = ifg.neighbors(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 IndexSetIterator elements(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 uint neighbor;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 while ((neighbor = elements.next()) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 tty->print_cr("Edge between %d and %d\n", i, neighbor);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 for (uint i = 0; i < ifg._maxlrg; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 LRG &l = ifg.lrgs(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (l._def) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 OptoReg::Name name = l.reg();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 tty->print("OptoReg::dump: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 OptoReg::dump(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 tty->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 tty->print_cr("name=%d\n", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (OptoReg::is_stack(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 tty->print_cr("Stack number %d\n", OptoReg::reg2stack(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 } else if (!OptoReg::is_valid(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 tty->print_cr("BAD!!!");
a61af66fc99e Initial load
duke
parents:
diff changeset
207 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (OptoReg::is_reg(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 tty->print_cr(OptoReg::regname(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 int x = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 int x = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (l._def == NodeSentinel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 tty->print("multiple mapping from %d: ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 for (int j=0; j<l._defs->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 tty->print("%d ", l._defs->at(j)->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 tty->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
224 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 tty->print_cr("mapping between %d and %d\n", i, l._def->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }*/
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 void IdealGraphPrinter::print_method(ciMethod *method, int bci, InlineTree *tree) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 stringStream str;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 method->print_name(&str);
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 stringStream shortStr;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 method->print_short_name(&shortStr);
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 properties.add(new Property(METHOD_NAME_PROPERTY, str.as_string()));
a61af66fc99e Initial load
duke
parents:
diff changeset
242 properties.add(new Property(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string()));
a61af66fc99e Initial load
duke
parents:
diff changeset
243 properties.add(new Property(METHOD_BCI_PROPERTY, bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
244 start_element(METHOD_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 start_element(BYTECODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 output()->print_cr("<![CDATA[");
a61af66fc99e Initial load
duke
parents:
diff changeset
248 method->print_codes_on(output());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 output()->print_cr("]]>");
a61af66fc99e Initial load
duke
parents:
diff changeset
250 end_element(BYTECODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 start_element(INLINE_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (tree != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 GrowableArray<InlineTree *> subtrees = tree->subtrees();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 for (int i = 0; i < subtrees.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 print_inline_tree(subtrees.at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 end_element(INLINE_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 end_element(METHOD_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 output()->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void IdealGraphPrinter::print_inline_tree(InlineTree *tree) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (tree == NULL) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 ciMethod *method = tree->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 print_method(tree->method(), tree->caller_bci(), tree);
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 void IdealGraphPrinter::clear_nodes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // _nodes.at(i)->clear_node();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 void IdealGraphPrinter::print_inlining(Compile* compile) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // Print inline tree
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (_should_send_method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 InlineTree *inlineTree = compile->ilt();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (inlineTree != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 print_inline_tree(inlineTree);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // print this method only
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Has to be called whenever a method is compiled
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void IdealGraphPrinter::begin_method(Compile* compile) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 ciMethod *method = compile->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 assert(_output, "output stream must exist!");
a61af66fc99e Initial load
duke
parents:
diff changeset
298 assert(method, "null methods are not allowed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
299 assert(!_current_method, "current method must be null!");
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 _arena->destruct_contents();
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 start_element(GROUP_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Print properties
a61af66fc99e Initial load
duke
parents:
diff changeset
306 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Add method name
a61af66fc99e Initial load
duke
parents:
diff changeset
309 stringStream strStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 method->print_name(&strStream);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 properties.add(new Property(METHOD_NAME_PROPERTY, strStream.as_string()));
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (method->flags().is_public()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 properties.add(new Property(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE));
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (method->flags().is_static()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 properties.add(new Property(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE));
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 properties.print(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (_stream) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 char answer = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 _stream->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 int result = _stream->read(&answer, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 _should_send_method = (answer == 'y');
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 this->_nodes = GrowableArray<NodeDescription *>(_arena, 2, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 this->_edges = GrowableArray< EdgeDescription * >(_arena, 2, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 this->_current_method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 _output->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Has to be called whenever a method has finished compilation
a61af66fc99e Initial load
duke
parents:
diff changeset
342 void IdealGraphPrinter::end_method() {
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // if (finish && !in_method) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 nmethod* method = (nmethod*)this->_current_method->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 start_element(ASSEMBLY_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Disassembler::decode(method, _output);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 end_element(ASSEMBLY_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 end_element(GROUP_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 _current_method = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 _output->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 delete desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 _nodes.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 this->_nodes.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 for (int i = 0; i < _edges.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // for (int j=0; j<_edges.at(i)->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 EdgeDescription *conn = _edges.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 conn->print(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 if (conn) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 delete conn;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 _edges.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374 //}
a61af66fc99e Initial load
duke
parents:
diff changeset
375 //_edges.at(i)->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
376 //delete _edges.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 //_edges.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 this->_edges.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // in_method = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // Outputs an XML start element
a61af66fc99e Initial load
duke
parents:
diff changeset
385 void IdealGraphPrinter::start_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */, bool print_return /* = true */) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 start_element_helper(s, properties, false, print_indent, print_return);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 _depth++;
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // Outputs an XML start element without body
a61af66fc99e Initial load
duke
parents:
diff changeset
393 void IdealGraphPrinter::simple_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 start_element_helper(s, properties, true, print_indent, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // Outputs an XML start element. If outputEnd is true, the element has no body.
a61af66fc99e Initial load
duke
parents:
diff changeset
398 void IdealGraphPrinter::start_element_helper(const char *s, Properties *properties, bool outputEnd, bool print_indent /* = false */, bool print_return /* = true */) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 assert(_output, "output stream must exist!");
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402 if (print_indent) this->print_indent();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 _output->print("<");
a61af66fc99e Initial load
duke
parents:
diff changeset
404 _output->print(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (properties) properties->print_as_attributes(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 if (outputEnd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 _output->print("/");
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 _output->print(">");
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (print_return) _output->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // Print indent
a61af66fc99e Initial load
duke
parents:
diff changeset
417 void IdealGraphPrinter::print_indent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 for (int i = 0; i < _depth; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 _output->print(INDENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Outputs an XML end element
a61af66fc99e Initial load
duke
parents:
diff changeset
424 void IdealGraphPrinter::end_element(const char *s, bool print_indent /* = true */, bool print_return /* = true */) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 assert(_output, "output stream must exist!");
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 _depth--;
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 if (print_indent) this->print_indent();
a61af66fc99e Initial load
duke
parents:
diff changeset
431 _output->print("</");
a61af66fc99e Initial load
duke
parents:
diff changeset
432 _output->print(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 _output->print(">");
a61af66fc99e Initial load
duke
parents:
diff changeset
434 if (print_return) _output->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 bool IdealGraphPrinter::traverse_outs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 return _traverse_outs;
a61af66fc99e Initial load
duke
parents:
diff changeset
440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 void IdealGraphPrinter::set_traverse_outs(bool b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 _traverse_outs = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 void IdealGraphPrinter::walk(Node *start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
450 GrowableArray<Node *> nodeStack(Thread::current()->resource_area(), 0, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 nodeStack.push(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 visited.test_set(start->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 while(nodeStack.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 Node *n = nodeStack.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 IdealGraphPrinter::pre_node(n, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (_traverse_outs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 for (DUIterator i = n->outs(); n->has_out(i); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 Node* p = n->out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 if (!visited.test_set(p->_idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 nodeStack.push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 for ( uint i = 0; i < n->len(); i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 if ( n->in(i) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (!visited.test_set(n->in(i)->_idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 nodeStack.push(n->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 void IdealGraphPrinter::compress(int index, GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 Block *block = blocks->adr_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 int ancestor = block->ancestor();
a61af66fc99e Initial load
duke
parents:
diff changeset
481 assert(ancestor != -1, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 Block *ancestor_block = blocks->adr_at(ancestor);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (ancestor_block->ancestor() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 compress(ancestor, blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 int label = block->label();
a61af66fc99e Initial load
duke
parents:
diff changeset
488 Block *label_block = blocks->adr_at(label);
a61af66fc99e Initial load
duke
parents:
diff changeset
489
a61af66fc99e Initial load
duke
parents:
diff changeset
490 int ancestor_label = ancestor_block->label();
a61af66fc99e Initial load
duke
parents:
diff changeset
491 Block *ancestor_label_block = blocks->adr_at(label);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (ancestor_label_block->semi() < label_block->semi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 block->set_label(ancestor_label);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 block->set_ancestor(ancestor_block->ancestor());
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 int IdealGraphPrinter::eval(int index, GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 Block *block = blocks->adr_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (block->ancestor() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 return index;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 compress(index, blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
506 return block->label();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510 void IdealGraphPrinter::link(int index1, int index2, GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 Block *block2 = blocks->adr_at(index2);
a61af66fc99e Initial load
duke
parents:
diff changeset
512 block2->set_ancestor(index1);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 void IdealGraphPrinter::build_dominators(GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 if (blocks->length() == 0) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 GrowableArray<int> stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
520 stack.append(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 GrowableArray<Block *> array;
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 assert(blocks->length() > 0, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
525 blocks->adr_at(0)->set_dominator(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
526
a61af66fc99e Initial load
duke
parents:
diff changeset
527 int n = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
528 while(!stack.is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 int index = stack.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
530 Block *block = blocks->adr_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
531 block->set_semi(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 array.append(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
533 n = n + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 for (int i = 0; i < block->succs()->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 int succ_index = block->succs()->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 Block *succ = blocks->adr_at(succ_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
537 if (succ->semi() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
538 succ->set_parent(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
539 stack.push(succ_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541 succ->add_pred(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 for (int i=n-1; i>0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 Block *block = array.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 int block_index = block->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
548 for (int j=0; j<block->pred()->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 int pred_index = block->pred()->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
550 int cur_index = eval(pred_index, blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 Block *cur_block = blocks->adr_at(cur_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 if (cur_block->semi() < block->semi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 block->set_semi(cur_block->semi());
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 int semi_index = block->semi();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 Block *semi_block = array.at(semi_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
560 semi_block->add_to_bucket(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 link(block->parent(), block_index, blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 Block *parent_block = blocks->adr_at(block->parent());
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 for (int j=0; j<parent_block->bucket()->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 int cur_index = parent_block->bucket()->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 int new_index = eval(cur_index, blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 Block *cur_block = blocks->adr_at(cur_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 Block *new_block = blocks->adr_at(new_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 int dom = block->parent();
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572 if (new_block->semi() < cur_block->semi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 dom = new_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 cur_block->set_dominator(dom);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 parent_block->clear_bucket();
a61af66fc99e Initial load
duke
parents:
diff changeset
580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 for (int i=1; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584 Block *block = array.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 int block_index = block->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587 int semi_index = block->semi();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 Block *semi_block = array.at(semi_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 if (block->dominator() != semi_block->index()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
591 int new_dom = blocks->adr_at(block->dominator())->dominator();
a61af66fc99e Initial load
duke
parents:
diff changeset
592 block->set_dominator(new_dom);
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595
a61af66fc99e Initial load
duke
parents:
diff changeset
596 for (int i = 0; i < blocks->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (blocks->adr_at(i)->dominator() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 blocks->adr_at(i)->set_dominator(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // Build dominates array
a61af66fc99e Initial load
duke
parents:
diff changeset
603 for (int i=1; i < blocks->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 Block *block = blocks->adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 int dominator = block->dominator();
a61af66fc99e Initial load
duke
parents:
diff changeset
606 Block *dom_block = blocks->adr_at(dominator);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 dom_block->add_dominates(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 dom_block->add_child(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610 while(dominator != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 dominator = dom_block->dominator();
a61af66fc99e Initial load
duke
parents:
diff changeset
612 dom_block = blocks->adr_at(dominator);
a61af66fc99e Initial load
duke
parents:
diff changeset
613 dom_block->add_child(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615 }
a61af66fc99e Initial load
duke
parents:
diff changeset
616 }
a61af66fc99e Initial load
duke
parents:
diff changeset
617
a61af66fc99e Initial load
duke
parents:
diff changeset
618 void IdealGraphPrinter::build_common_dominator(int **common_dominator, int index, GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 common_dominator[index][index] = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 Block *block = blocks->adr_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
622 for (int i = 0; i < block->dominates()->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 Block *dominated = blocks->adr_at(block->dominates()->at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 for (int j=0; j<dominated->children()->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 Block *child = blocks->adr_at(dominated->children()->at(j));
a61af66fc99e Initial load
duke
parents:
diff changeset
627 common_dominator[index][child->index()] = common_dominator[child->index()][index] = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 for (int k=0; k<i; k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
630 Block *other_dominated = blocks->adr_at(block->dominates()->at(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
631 common_dominator[child->index()][other_dominated->index()] = common_dominator[other_dominated->index()][child->index()] = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 for (int l=0 ; l<other_dominated->children()->length(); l++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 Block *other_child = blocks->adr_at(other_dominated->children()->at(l));
a61af66fc99e Initial load
duke
parents:
diff changeset
635 common_dominator[child->index()][other_child->index()] = common_dominator[other_child->index()][child->index()] = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 build_common_dominator(common_dominator, dominated->index(), blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643
a61af66fc99e Initial load
duke
parents:
diff changeset
644 void IdealGraphPrinter::schedule_latest(int **common_dominator, GrowableArray<Block>* blocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 int queue_size = _nodes.length() + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 NodeDescription **queue = NEW_RESOURCE_ARRAY(NodeDescription *, queue_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
648 int queue_start = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
649 int queue_end = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 Arena *a = new Arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
651 VectorSet on_queue(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 desc->init_succs();
a61af66fc99e Initial load
duke
parents:
diff changeset
657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659
a61af66fc99e Initial load
duke
parents:
diff changeset
660 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
661 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 for (uint j=0; j<desc->node()->len(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
664 Node *n = desc->node()->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
665 if (n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 NodeDescription *other_desc = _nodes.at(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
667 other_desc->add_succ(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
671 }
a61af66fc99e Initial load
duke
parents:
diff changeset
672
a61af66fc99e Initial load
duke
parents:
diff changeset
673 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
674 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
675 if (desc && desc->block_index() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // Put Phi into same block as region
a61af66fc99e Initial load
duke
parents:
diff changeset
678 if (desc->node()->is_Phi() && desc->node()->in(0) && _nodes.at(desc->node()->in(0)->_idx)->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 int index = _nodes.at(desc->node()->in(0)->_idx)->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
680 desc->set_block_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
681 blocks->adr_at(index)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683 // Put Projections to same block as parent
a61af66fc99e Initial load
duke
parents:
diff changeset
684 } else if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
686 desc->set_block_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 blocks->adr_at(index)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
688 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 queue[queue_end] = desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
690 queue_end++;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 on_queue.set(desc->node()->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696
a61af66fc99e Initial load
duke
parents:
diff changeset
697 int z = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 while(queue_start != queue_end && z < 10000) {
a61af66fc99e Initial load
duke
parents:
diff changeset
699
a61af66fc99e Initial load
duke
parents:
diff changeset
700 NodeDescription *desc = queue[queue_start];
a61af66fc99e Initial load
duke
parents:
diff changeset
701 queue_start = (queue_start + 1) % queue_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 on_queue >>= desc->node()->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 Node* node = desc->node();
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 if (desc->succs()->length() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 int x = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 }
a61af66fc99e Initial load
duke
parents:
diff changeset
709
a61af66fc99e Initial load
duke
parents:
diff changeset
710 int block_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
711 if (desc->succs()->length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
712 for (int i = 0; i < desc->succs()->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 NodeDescription *cur_desc = desc->succs()->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 if (cur_desc != desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 if (cur_desc->succs()->length() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 // Ignore nodes with 0 successors
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 } else if (cur_desc->block_index() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 // Let this node schedule first
a61af66fc99e Initial load
duke
parents:
diff changeset
722 block_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
723 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
724
a61af66fc99e Initial load
duke
parents:
diff changeset
725 } else if (cur_desc->node()->is_Phi()){
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // Special treatment for Phi functions
a61af66fc99e Initial load
duke
parents:
diff changeset
728 PhiNode *phi = cur_desc->node()->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
729 assert(phi->in(0) && phi->in(0)->is_Region(), "Must have region node in first input");
a61af66fc99e Initial load
duke
parents:
diff changeset
730 RegionNode *region = phi->in(0)->as_Region();
a61af66fc99e Initial load
duke
parents:
diff changeset
731
a61af66fc99e Initial load
duke
parents:
diff changeset
732 for (uint j=1; j<phi->len(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
733 Node *cur_phi_input = phi->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
734 if (cur_phi_input == desc->node() && region->in(j)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 NodeDescription *cur_region_input = _nodes.at(region->in(j)->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
736 if (cur_region_input->block_index() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 // Let this node schedule first
a61af66fc99e Initial load
duke
parents:
diff changeset
739 block_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
741 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if (block_index == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 block_index = cur_region_input->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
744 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 block_index = common_dominator[block_index][cur_region_input->block_index()];
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750
a61af66fc99e Initial load
duke
parents:
diff changeset
751 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
752 if (block_index == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
753 block_index = cur_desc->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
754 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
755 block_index = common_dominator[block_index][cur_desc->block_index()];
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
759 }
a61af66fc99e Initial load
duke
parents:
diff changeset
760 }
a61af66fc99e Initial load
duke
parents:
diff changeset
761
a61af66fc99e Initial load
duke
parents:
diff changeset
762 if (block_index == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 queue[queue_end] = desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
764 queue_end = (queue_end + 1) % queue_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 on_queue.set(desc->node()->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
766 z++;
a61af66fc99e Initial load
duke
parents:
diff changeset
767 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 assert(desc->block_index() == -1, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
769 desc->set_block_index(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
770 blocks->adr_at(block_index)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
771 z = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
777 if (desc && desc->block_index() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
778
a61af66fc99e Initial load
duke
parents:
diff changeset
779 //if (desc->node()->is_Proj() || desc->node()->is_Con()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 Node *parent = desc->node()->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
781 uint cur = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 while(!parent && cur < desc->node()->len()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 parent = desc->node()->in(cur);
a61af66fc99e Initial load
duke
parents:
diff changeset
784 cur++;
a61af66fc99e Initial load
duke
parents:
diff changeset
785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787 if (parent && _nodes.at(parent->_idx)->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
788 int index = _nodes.at(parent->_idx)->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
789 desc->set_block_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
790 blocks->adr_at(index)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
791 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
792 desc->set_block_index(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 blocks->adr_at(0)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
794 //ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796 //}
a61af66fc99e Initial load
duke
parents:
diff changeset
797 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
798 if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
799 int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
800 desc->set_block_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
801 blocks->adr_at(index)->add_node(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
802 } */
a61af66fc99e Initial load
duke
parents:
diff changeset
803 }
a61af66fc99e Initial load
duke
parents:
diff changeset
804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
808 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 desc->clear_succs();
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
815 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
816 int block_index = desc->block_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 assert(block_index >= 0 && block_index < blocks->length(), "Block index must be in range");
a61af66fc99e Initial load
duke
parents:
diff changeset
819 assert(blocks->adr_at(block_index)->nodes()->contains(desc), "Node must be child of block");
a61af66fc99e Initial load
duke
parents:
diff changeset
820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822 a->destruct_contents();
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824
a61af66fc99e Initial load
duke
parents:
diff changeset
825 void IdealGraphPrinter::build_blocks(Node *root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
826
a61af66fc99e Initial load
duke
parents:
diff changeset
827 Arena *a = new Arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
828 Node_Stack stack(a, 100);
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 VectorSet visited(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 stack.push(root, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 GrowableArray<Block> blocks(a, 2, 0, Block(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 if (_nodes.at(i)) _nodes.at(i)->set_block_index(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // Order nodes such that node index is equal to idx
a61af66fc99e Initial load
duke
parents:
diff changeset
840 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
841
a61af66fc99e Initial load
duke
parents:
diff changeset
842 if (_nodes.at(i)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
843 NodeDescription *node = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
844 int index = node->node()->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 if (index != i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 _nodes.at_grow(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 NodeDescription *tmp = _nodes.at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
848 *(_nodes.adr_at(index)) = node;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 *(_nodes.adr_at(i)) = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
850 i--;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 NodeDescription *node = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
857 if (node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 assert(node->node()->_idx == (uint)i, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861
a61af66fc99e Initial load
duke
parents:
diff changeset
862 while(stack.is_nonempty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864 //Node *n = stack.node();
a61af66fc99e Initial load
duke
parents:
diff changeset
865 //int index = stack.index();
a61af66fc99e Initial load
duke
parents:
diff changeset
866 Node *proj = stack.node();//n->in(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
867 const Node *parent = proj->is_block_proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (parent == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 parent = proj;
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871
a61af66fc99e Initial load
duke
parents:
diff changeset
872 if (!visited.test_set(parent->_idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
873
a61af66fc99e Initial load
duke
parents:
diff changeset
874 NodeDescription *end_desc = _nodes.at(parent->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
875 int block_index = blocks.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
876 Block block(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
877 blocks.append(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
878 Block *b = blocks.adr_at(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 b->set_start(end_desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
880 // assert(end_desc->block_index() == -1, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
881 end_desc->set_block_index(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
882 b->add_node(end_desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
883
a61af66fc99e Initial load
duke
parents:
diff changeset
884 // Skip any control-pinned middle'in stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
885 Node *p = proj;
a61af66fc99e Initial load
duke
parents:
diff changeset
886 NodeDescription *start_desc = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
887 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 proj = p; // Update pointer to last Control
a61af66fc99e Initial load
duke
parents:
diff changeset
889 if (p->in(0) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
890 start_desc = end_desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
891 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
892 }
a61af66fc99e Initial load
duke
parents:
diff changeset
893 p = p->in(0); // Move control forward
a61af66fc99e Initial load
duke
parents:
diff changeset
894 start_desc = _nodes.at(p->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
895 assert(start_desc, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
896
a61af66fc99e Initial load
duke
parents:
diff changeset
897 if (start_desc != end_desc && start_desc->block_index() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 assert(start_desc->block_index() == -1, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
899 assert(block_index < blocks.length(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
900 start_desc->set_block_index(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
901 b->add_node(start_desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
903 } while( !p->is_block_proj() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
904 !p->is_block_start() );
a61af66fc99e Initial load
duke
parents:
diff changeset
905
a61af66fc99e Initial load
duke
parents:
diff changeset
906 for (uint i = 0; i < start_desc->node()->len(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 Node *pred_node = start_desc->node()->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
909
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911 if (pred_node && pred_node != start_desc->node()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
912 const Node *cur_parent = pred_node->is_block_proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
913 if (cur_parent != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
914 pred_node = (Node *)cur_parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
916
a61af66fc99e Initial load
duke
parents:
diff changeset
917 NodeDescription *pred_node_desc = _nodes.at(pred_node->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 if (pred_node_desc->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
919 blocks.adr_at(pred_node_desc->block_index())->add_succ(block_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
922 }
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 for (DUIterator_Fast dmax, i = end_desc->node()->fast_outs(dmax); i < dmax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
925 Node* cur_succ = end_desc->node()->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
926 NodeDescription *cur_succ_desc = _nodes.at(cur_succ->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928 DUIterator_Fast dmax2, i2 = cur_succ->fast_outs(dmax2);
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if (cur_succ->is_block_proj() && i2 < dmax2 && !cur_succ->is_Root()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 for (; i2<dmax2; i2++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 Node *cur_succ2 = cur_succ->fast_out(i2);
a61af66fc99e Initial load
duke
parents:
diff changeset
933 if (cur_succ2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 cur_succ_desc = _nodes.at(cur_succ2->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
935 if (cur_succ_desc == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // dead node so skip it
a61af66fc99e Initial load
duke
parents:
diff changeset
937 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
939 if (cur_succ2 != end_desc->node() && cur_succ_desc->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
940 b->add_succ(cur_succ_desc->block_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942 }
a61af66fc99e Initial load
duke
parents:
diff changeset
943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
944
a61af66fc99e Initial load
duke
parents:
diff changeset
945 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
946
a61af66fc99e Initial load
duke
parents:
diff changeset
947 if (cur_succ != end_desc->node() && cur_succ_desc && cur_succ_desc->block_index() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
948 b->add_succ(cur_succ_desc->block_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
949 }
a61af66fc99e Initial load
duke
parents:
diff changeset
950 }
a61af66fc99e Initial load
duke
parents:
diff changeset
951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
952
a61af66fc99e Initial load
duke
parents:
diff changeset
953
a61af66fc99e Initial load
duke
parents:
diff changeset
954 int num_preds = p->len();
a61af66fc99e Initial load
duke
parents:
diff changeset
955 int bottom = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
956 if (p->is_Region() || p->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 bottom = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
958 }
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 int pushed = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
961 for (int i=num_preds - 1; i > bottom; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
962 if (p->in(i) != NULL && p->in(i) != p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
963 stack.push(p->in(i), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
964 pushed++;
a61af66fc99e Initial load
duke
parents:
diff changeset
965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
966 }
a61af66fc99e Initial load
duke
parents:
diff changeset
967
a61af66fc99e Initial load
duke
parents:
diff changeset
968 if (pushed == 0 && p->is_Root() && !_matcher) {
a61af66fc99e Initial load
duke
parents:
diff changeset
969 // Special case when backedges to root are not yet built
a61af66fc99e Initial load
duke
parents:
diff changeset
970 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
971 if (_nodes.at(i) && _nodes.at(i)->node()->is_SafePoint() && _nodes.at(i)->node()->outcnt() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
972 stack.push(_nodes.at(i)->node(), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
973 }
a61af66fc99e Initial load
duke
parents:
diff changeset
974 }
a61af66fc99e Initial load
duke
parents:
diff changeset
975 }
a61af66fc99e Initial load
duke
parents:
diff changeset
976
a61af66fc99e Initial load
duke
parents:
diff changeset
977 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 stack.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
979 }
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981
a61af66fc99e Initial load
duke
parents:
diff changeset
982 build_dominators(&blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
983
a61af66fc99e Initial load
duke
parents:
diff changeset
984 int **common_dominator = NEW_RESOURCE_ARRAY(int *, blocks.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
985 for (int i = 0; i < blocks.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
986 int *cur = NEW_RESOURCE_ARRAY(int, blocks.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
987 common_dominator[i] = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 for (int j=0; j<blocks.length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 cur[j] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
991 }
a61af66fc99e Initial load
duke
parents:
diff changeset
992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
993
a61af66fc99e Initial load
duke
parents:
diff changeset
994 for (int i = 0; i < blocks.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 blocks.adr_at(i)->add_child(blocks.adr_at(i)->index());
a61af66fc99e Initial load
duke
parents:
diff changeset
996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
997 build_common_dominator(common_dominator, 0, &blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 schedule_latest(common_dominator, &blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
1000
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 start_element(CONTROL_FLOW_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1002
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 for (int i = 0; i < blocks.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 Block *block = blocks.adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1005
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 Properties props;
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 props.add(new Property(BLOCK_NAME_PROPERTY, i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 props.add(new Property(BLOCK_DOMINATOR_PROPERTY, block->dominator()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 start_element(BLOCK_ELEMENT, &props);
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 if (block->succs()->length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 start_element(SUCCESSORS_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 for (int j=0; j<block->succs()->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 int cur_index = block->succs()->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 if (cur_index != 0 /* start_block has must not have inputs */) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 properties.add(new Property(BLOCK_NAME_PROPERTY, cur_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 simple_element(SUCCESSOR_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 end_element(SUCCESSORS_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1023
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 start_element(NODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 for (int j=0; j<block->nodes()->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 NodeDescription *n = block->nodes()->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 properties.add(new Property(NODE_ID_PROPERTY, n->id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 simple_element(NODE_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1032
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 end_element(NODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 end_element(BLOCK_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
a61af66fc99e Initial load
duke
parents:
diff changeset
1038
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 end_element(CONTROL_FLOW_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1040
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 a->destruct_contents();
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1043
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 void IdealGraphPrinter::print_method(Compile* compile, const char *name, int level, bool clear_nodes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 print(compile, name, (Node *)compile->root(), level, clear_nodes);
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1047
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 // Print current ideal graph
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 void IdealGraphPrinter::print(Compile* compile, const char *name, Node *node, int level, bool clear_nodes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1050
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 // if (finish && !in_method) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 if (!_current_method || !_should_send_method || level > PrintIdealGraphLevel) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1053
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 assert(_current_method, "newMethod has to be called first!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 if (clear_nodes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 int x = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1059
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 _clear_nodes = clear_nodes;
a61af66fc99e Initial load
duke
parents:
diff changeset
1061
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 // Warning, unsafe cast?
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 _chaitin = (PhaseChaitin *)compile->regalloc();
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 _matcher = compile->matcher();
a61af66fc99e Initial load
duke
parents:
diff changeset
1065
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // Update nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 desc->set_state(Invalid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 Node *n = node;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 walk(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1076
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 // Update edges
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 for (int i = 0; i < _edges.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 _edges.at(i)->set_state(Invalid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1081
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 if (desc && desc->state() != Invalid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1085
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 int to = desc->id();
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 uint len = desc->node()->len();
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 for (uint j=0; j<len; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 Node *n = desc->node()->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
1090
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 if (n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1092
a61af66fc99e Initial load
duke
parents:
diff changeset
1093
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 intptr_t from = (intptr_t)n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1095
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 // Assert from node is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 bool ok = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 for (int k=0; k<_nodes.length(); k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 NodeDescription *desc = _nodes.at(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 if (desc && desc->id() == from) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 assert(desc->state() != Invalid, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 ok = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 assert(ok, "");*/
a61af66fc99e Initial load
duke
parents:
diff changeset
1107
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 uint index = j;
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 if (index >= desc->node()->req()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 index = desc->node()->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1112
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 print_edge(from, to, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1118
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 bool is_different = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1120
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 if (desc && desc->state() != Valid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 is_different = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 if (!is_different) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 for (int i = 0; i < _edges.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 EdgeDescription *conn = _edges.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 if (conn && conn->state() != Valid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 is_different = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 // No changes -> do not print graph
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if (!is_different) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1141
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 properties.add(new Property(GRAPH_NAME_PROPERTY, (const char *)name));
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 start_element(GRAPH_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 start_element(NODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 for (int i = 0; i < _nodes.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 NodeDescription *desc = _nodes.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 desc->print(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 if (desc->state() == Invalid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 delete desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 _nodes.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 desc->set_state(Valid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 end_element(NODES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1160
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 build_blocks(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 start_element(EDGES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 for (int i = 0; i < _edges.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 EdgeDescription *conn = _edges.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1166
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 // Assert from and to nodes are valid
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 if (!conn->state() == Invalid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 bool ok1 = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 bool ok2 = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 for (int j=0; j<_nodes.length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 NodeDescription *desc = _nodes.at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 if (desc && desc->id() == conn->from()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 ok1 = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1177
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 if (desc && desc->id() == conn->to()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 ok2 = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1182
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 assert(ok1, "from node not found!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 assert(ok2, "to node not found!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 }*/
a61af66fc99e Initial load
duke
parents:
diff changeset
1186
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 conn->print(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 if (conn->state() == Invalid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 _edges.remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 delete conn;
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 i--;
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1194
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 end_element(EDGES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1196
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 end_element(GRAPH_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1198
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 _output->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1201
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 // Print edge
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 void IdealGraphPrinter::print_edge(int from, int to, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 EdgeDescription *conn = new EdgeDescription(from, to, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 for (int i = 0; i < _edges.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 if (_edges.at(i)->equals(conn)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 conn->set_state(Valid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 delete _edges.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 _edges.at_put(i, conn);
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1214
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 _edges.append(conn);
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1217
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 extern const char *NodeClassNames[];
a61af66fc99e Initial load
duke
parents:
diff changeset
1219
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 // Create node description
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 IdealGraphPrinter::NodeDescription *IdealGraphPrinter::create_node_description(Node* node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1222
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 node->_in_dump_cnt++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 NodeDescription *desc = new NodeDescription(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 desc->properties()->add(new Property(NODE_NAME_PROPERTY, (const char *)node->Name()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1227
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 const Type *t = node->bottom_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 desc->properties()->add(new Property("type", (const char *)Type::msg[t->base()]));
a61af66fc99e Initial load
duke
parents:
diff changeset
1230
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 desc->properties()->add(new Property("idx", node->_idx));
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 desc->properties()->add(new Property("debug_idx", node->_debug_idx));
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1235
a61af66fc99e Initial load
duke
parents:
diff changeset
1236
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 const jushort flags = node->flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 if (flags & Node::Flag_is_Copy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 desc->properties()->add(new Property("is_copy", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 if (flags & Node::Flag_is_Call) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 desc->properties()->add(new Property("is_call", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 if (flags & Node::Flag_rematerialize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 desc->properties()->add(new Property("rematerialize", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 if (flags & Node::Flag_needs_anti_dependence_check) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 desc->properties()->add(new Property("needs_anti_dependence_check", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 if (flags & Node::Flag_is_macro) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 desc->properties()->add(new Property("is_macro", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 if (flags & Node::Flag_is_Con) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 desc->properties()->add(new Property("is_con", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 if (flags & Node::Flag_is_cisc_alternate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 desc->properties()->add(new Property("is_cisc_alternate", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 if (flags & Node::Flag_is_Branch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 desc->properties()->add(new Property("is_branch", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 if (flags & Node::Flag_is_block_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 desc->properties()->add(new Property("is_block_start", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 if (flags & Node::Flag_is_Goto) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 desc->properties()->add(new Property("is_goto", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 if (flags & Node::Flag_is_dead_loop_safe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 desc->properties()->add(new Property("is_dead_loop_safe", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 if (flags & Node::Flag_may_be_short_branch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 desc->properties()->add(new Property("may_be_short_branch", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 if (flags & Node::Flag_is_safepoint_node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 desc->properties()->add(new Property("is_safepoint_node", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 if (flags & Node::Flag_is_pc_relative) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 desc->properties()->add(new Property("is_pc_relative", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1280
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 if (_matcher) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 if (_matcher->is_shared(desc->node())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 desc->properties()->add(new Property("is_shared", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 desc->properties()->add(new Property("is_shared", "false"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1287
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 if (_matcher->is_dontcare(desc->node())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 desc->properties()->add(new Property("is_dontcare", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 desc->properties()->add(new Property("is_dontcare", "false"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1294
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 if (node->is_Proj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 desc->properties()->add(new Property("con", (int)node->as_Proj()->_con));
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1298
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 if (node->is_Mach()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 desc->properties()->add(new Property("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()]));
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303
a61af66fc99e Initial load
duke
parents:
diff changeset
1304
a61af66fc99e Initial load
duke
parents:
diff changeset
1305
a61af66fc99e Initial load
duke
parents:
diff changeset
1306
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 outputStream *oldTty = tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 buffer[0] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 stringStream s2(buffer, sizeof(buffer) - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1310
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 node->dump_spec(&s2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 assert(s2.size() < sizeof(buffer), "size in range");
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 desc->properties()->add(new Property("dump_spec", buffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
1314
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 if (node->is_block_proj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 desc->properties()->add(new Property("is_block_proj", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1318
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 if (node->is_block_start()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 desc->properties()->add(new Property("is_block_start", "true"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1322
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 const char *short_name = "short_name";
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 int index = node->as_Proj()->_con - TypeFunc::Parms;
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 if (index >= 10) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 desc->properties()->add(new Property(short_name, "PA"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 sprintf(buffer, "P%d", index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 desc->properties()->add(new Property(short_name, buffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 } else if (strcmp(node->Name(), "IfTrue") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 desc->properties()->add(new Property(short_name, "T"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 } else if (strcmp(node->Name(), "IfFalse") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 desc->properties()->add(new Property(short_name, "F"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1337
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 if (t->base() == Type::Int && t->is_int()->is_con()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 const TypeInt *typeInt = t->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 assert(typeInt->is_con(), "must be constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 jint value = typeInt->get_con();
a61af66fc99e Initial load
duke
parents:
diff changeset
1342
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 // max. 2 chars allowed
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 if (value >= -9 && value <= 99) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 sprintf(buffer, "%d", value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 desc->properties()->add(new Property(short_name, buffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 desc->properties()->add(new Property(short_name, "I"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 } else if (t == Type::TOP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 desc->properties()->add(new Property(short_name, "^"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 } else if (t->base() == Type::Long && t->is_long()->is_con()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 const TypeLong *typeLong = t->is_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 assert(typeLong->is_con(), "must be constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 jlong value = typeLong->get_con();
a61af66fc99e Initial load
duke
parents:
diff changeset
1358
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 // max. 2 chars allowed
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 if (value >= -9 && value <= 99) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 sprintf(buffer, "%d", value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 desc->properties()->add(new Property(short_name, buffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 desc->properties()->add(new Property(short_name, "L"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 } else if (t->base() == Type::KlassPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 const TypeKlassPtr *typeKlass = t->is_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 desc->properties()->add(new Property(short_name, "CP"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 } else if (t->base() == Type::Control) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 desc->properties()->add(new Property(short_name, "C"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 } else if (t->base() == Type::Memory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 desc->properties()->add(new Property(short_name, "M"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 } else if (t->base() == Type::Abio) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 desc->properties()->add(new Property(short_name, "IO"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 } else if (t->base() == Type::Return_Address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 desc->properties()->add(new Property(short_name, "RA"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 } else if (t->base() == Type::AnyPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 desc->properties()->add(new Property(short_name, "P"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 } else if (t->base() == Type::RawPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 desc->properties()->add(new Property(short_name, "RP"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 } else if (t->base() == Type::AryPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 desc->properties()->add(new Property(short_name, "AP"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1387
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 if (node->is_SafePoint()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 SafePointNode *safePointNode = node->as_SafePoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 if (safePointNode->jvms()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 stringStream bciStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 bciStream.print("%d ", safePointNode->jvms()->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 JVMState *caller = safePointNode->jvms()->caller();
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 while(caller) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 bciStream.print("%d ", caller->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1396
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 caller = caller->caller();
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 desc->properties()->add(new Property("bci", bciStream.as_string()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1402
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 buffer[0] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 _chaitin->dump_register(node, buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 desc->properties()->add(new Property("reg", buffer));
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 desc->properties()->add(new Property("lrg", _chaitin->n2lidx(node)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1409
a61af66fc99e Initial load
duke
parents:
diff changeset
1410
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 node->_in_dump_cnt--;
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 return desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1417
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 void IdealGraphPrinter::pre_node(Node* node, void *env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1419
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 IdealGraphPrinter *printer = (IdealGraphPrinter *)env;
a61af66fc99e Initial load
duke
parents:
diff changeset
1421
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 NodeDescription *newDesc = printer->create_node_description(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1423
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 if (printer->_clear_nodes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1425
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 printer->_nodes.append(newDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1428
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 NodeDescription *desc = printer->_nodes.at_grow(node->_idx, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1430
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 if (desc && desc->equals(newDesc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 //desc->set_state(Valid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 //desc->set_node(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 delete desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 printer->_nodes.at_put(node->_idx, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 newDesc->set_state(Valid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 //printer->_nodes.at_put(node->_idx, newDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1439
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 if (desc && desc->id() == newDesc->id()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 delete desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 printer->_nodes.at_put(node->_idx, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 newDesc->set_state(New);
a61af66fc99e Initial load
duke
parents:
diff changeset
1444
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1446
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 //if (desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 // delete desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 //}
a61af66fc99e Initial load
duke
parents:
diff changeset
1450
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 //printer->_nodes.at_put(node->_idx, newDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1453
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 printer->_nodes.append(newDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1457
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 void IdealGraphPrinter::post_node(Node* node, void *env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1460
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 outputStream *IdealGraphPrinter::output() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 return _output;
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1464
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 IdealGraphPrinter::Description::Description() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 _state = New;
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1468
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 void IdealGraphPrinter::Description::print(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 if (_state == Invalid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 print_removed(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 } else if (_state == New) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 print_changed(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1476
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 void IdealGraphPrinter::Description::set_state(State s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 _state = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1480
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 IdealGraphPrinter::State IdealGraphPrinter::Description::state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 return _state;
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1484
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 void IdealGraphPrinter::Block::set_proj(NodeDescription *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 _proj = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1488
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 void IdealGraphPrinter::Block::set_start(NodeDescription *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 _start = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1492
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 int IdealGraphPrinter::Block::semi() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 return _semi;
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1496
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 int IdealGraphPrinter::Block::parent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 return _parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1500
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 GrowableArray<int>* IdealGraphPrinter::Block::bucket() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 return &_bucket;
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1504
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 GrowableArray<int>* IdealGraphPrinter::Block::children() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 return &_children;
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1508
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 void IdealGraphPrinter::Block::add_child(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 _children.append(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1512
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 GrowableArray<int>* IdealGraphPrinter::Block::dominates() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 return &_dominates;
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1516
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 void IdealGraphPrinter::Block::add_dominates(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 _dominates.append(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1520
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 void IdealGraphPrinter::Block::add_to_bucket(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 _bucket.append(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1524
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 void IdealGraphPrinter::Block::clear_bucket() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 _bucket.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1528
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 void IdealGraphPrinter::Block::set_dominator(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 _dominator = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1532
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 void IdealGraphPrinter::Block::set_label(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 _label = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1536
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 int IdealGraphPrinter::Block::label() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 return _label;
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1540
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 int IdealGraphPrinter::Block::ancestor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 return _ancestor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1544
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 void IdealGraphPrinter::Block::set_ancestor(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 _ancestor = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1548
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 int IdealGraphPrinter::Block::dominator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 return _dominator;
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1552
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 int IdealGraphPrinter::Block::index() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 return _index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1556
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 void IdealGraphPrinter::Block::set_parent(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 _parent = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1560
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 GrowableArray<int>* IdealGraphPrinter::Block::pred() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 return &_pred;
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1564
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 void IdealGraphPrinter::Block::set_semi(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 _semi = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1568
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 IdealGraphPrinter::Block::Block() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1571
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 IdealGraphPrinter::Block::Block(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 _index = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 _label = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 _semi = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 _ancestor = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 _dominator = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1579
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 void IdealGraphPrinter::Block::add_pred(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 _pred.append(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1583
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::proj() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 return _proj;
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1587
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::start() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 return _start;
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1591
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 GrowableArray<int>* IdealGraphPrinter::Block::succs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 return &_succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1595
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 void IdealGraphPrinter::Block::add_succ(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1597
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 if (this->_index == 16 && index == 15) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 int x = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1601
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 if (!_succs.contains(index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 _succs.append(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1606
a61af66fc99e Initial load
duke
parents:
diff changeset
1607
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 void IdealGraphPrinter::Block::add_node(NodeDescription *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 if (!_nodes.contains(n)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 _nodes.append(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1613
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::Block::nodes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 return &_nodes;
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1617
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 int IdealGraphPrinter::NodeDescription::count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1619
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 IdealGraphPrinter::NodeDescription::NodeDescription(Node* node) : _node(node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 _id = (intptr_t)(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 _block_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1624
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 IdealGraphPrinter::NodeDescription::~NodeDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 _properties.clean();
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1628
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 // void IdealGraphPrinter::NodeDescription::set_node(Node* node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 // //this->_node = node;
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1632
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 int IdealGraphPrinter::NodeDescription::block_index() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 return _block_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1636
a61af66fc99e Initial load
duke
parents:
diff changeset
1637
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::NodeDescription::succs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 return &_succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1641
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 void IdealGraphPrinter::NodeDescription::clear_succs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 _succs.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1645
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 void IdealGraphPrinter::NodeDescription::init_succs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 _succs = GrowableArray<NodeDescription *>();
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1649
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 void IdealGraphPrinter::NodeDescription::add_succ(NodeDescription *desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 _succs.append(desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1653
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 void IdealGraphPrinter::NodeDescription::set_block_index(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 _block_index = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1657
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 bool IdealGraphPrinter::NodeDescription::equals(NodeDescription *desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 if (desc == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 if (desc->id() != id()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 return properties()->equals(desc->properties());
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1663
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 Node* IdealGraphPrinter::NodeDescription::node() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 return _node;
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1667
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 IdealGraphPrinter::Properties* IdealGraphPrinter::NodeDescription::properties() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 return &_properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1671
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 uint IdealGraphPrinter::NodeDescription::id() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 return _id;
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1675
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 void IdealGraphPrinter::NodeDescription::print_changed(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1677
a61af66fc99e Initial load
duke
parents:
diff changeset
1678
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 properties.add(new Property(NODE_ID_PROPERTY, id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 printer->start_element(NODE_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1682
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 this->properties()->print(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1684
a61af66fc99e Initial load
duke
parents:
diff changeset
1685
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 printer->end_element(NODE_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1688
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 void IdealGraphPrinter::NodeDescription::print_removed(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1690
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 properties.add(new Property(NODE_ID_PROPERTY, id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 printer->simple_element(REMOVE_NODE_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1695
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 IdealGraphPrinter::EdgeDescription::EdgeDescription(int from, int to, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 this->_from = from;
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 this->_to = to;
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 this->_index = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1701
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 IdealGraphPrinter::EdgeDescription::~EdgeDescription() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1704
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 int IdealGraphPrinter::EdgeDescription::from() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 return _from;
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1708
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 int IdealGraphPrinter::EdgeDescription::to() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 return _to;
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1712
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 void IdealGraphPrinter::EdgeDescription::print_changed(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1714
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 properties.add(new Property(INDEX_PROPERTY, _index));
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 properties.add(new Property(FROM_PROPERTY, _from));
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 properties.add(new Property(TO_PROPERTY, _to));
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 printer->simple_element(EDGE_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1721
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 void IdealGraphPrinter::EdgeDescription::print_removed(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1723
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 properties.add(new Property(INDEX_PROPERTY, _index));
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 properties.add(new Property(FROM_PROPERTY, _from));
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 properties.add(new Property(TO_PROPERTY, _to));
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 printer->simple_element(REMOVE_EDGE_ELEMENT, &properties);
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1730
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 bool IdealGraphPrinter::EdgeDescription::equals(IdealGraphPrinter::EdgeDescription *desc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 if (desc == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 return (_from == desc->_from && _to == desc->_to && _index == desc->_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1735
a61af66fc99e Initial load
duke
parents:
diff changeset
1736 IdealGraphPrinter::Properties::Properties() : list(new (ResourceObj::C_HEAP) GrowableArray<Property *>(2, 0, NULL, true)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1738
a61af66fc99e Initial load
duke
parents:
diff changeset
1739 IdealGraphPrinter::Properties::~Properties() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 clean();
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 delete list;
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1743
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 void IdealGraphPrinter::Properties::add(Property *p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 assert(p != NULL, "Property not NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 list->append(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1748
a61af66fc99e Initial load
duke
parents:
diff changeset
1749 void IdealGraphPrinter::Properties::print(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 printer->start_element(PROPERTIES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1751
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 for (int i = 0; i < list->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 list->at(i)->print(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1755
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 printer->end_element(PROPERTIES_ELEMENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1758
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 void IdealGraphPrinter::Properties::clean() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 for (int i = 0; i < list->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 delete list->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 list->at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 list->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 assert(list->length() == 0, "List cleared");
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1767
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 void IdealGraphPrinter::Properties::remove(const char *name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 for (int i = 0; i < list->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 if (strcmp(list->at(i)->name(), name) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 delete list->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 list->remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 i--;
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1777
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 void IdealGraphPrinter::Properties::print_as_attributes(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1779
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 for (int i = 0; i < list->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 assert(list->at(i) != NULL, "Property not null!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 printer->output()->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 list->at(i)->print_as_attribute(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1786
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 bool IdealGraphPrinter::Properties::equals(Properties* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 if (p->list->length() != this->list->length()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1789
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 for (int i = 0; i < list->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 assert(list->at(i) != NULL, "Property not null!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 if (!list->at(i)->equals(p->list->at(i))) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1794
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1797
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 IdealGraphPrinter::Property::Property() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 _name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 _value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1802
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 const char *IdealGraphPrinter::Property::name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 return _name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1806
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 IdealGraphPrinter::Property::Property(const Property* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1808
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 this->_name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 this->_value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1811
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 if (p->_name != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 _name = dup(p->_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1815
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 if (p->_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 _value = dup(p->_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1820
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 IdealGraphPrinter::Property::~Property() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1822
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 clean();
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1825
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 IdealGraphPrinter::Property::Property(const char *name, const char *value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1827
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 assert(name, "Name must not be null!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 assert(value, "Value must not be null!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1830
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 _name = dup(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 _value = dup(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1834
a61af66fc99e Initial load
duke
parents:
diff changeset
1835 IdealGraphPrinter::Property::Property(const char *name, int intValue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 _name = dup(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1837
a61af66fc99e Initial load
duke
parents:
diff changeset
1838 stringStream stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
1839 stream.print("%d", intValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 _value = dup(stream.as_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
1841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1842
a61af66fc99e Initial load
duke
parents:
diff changeset
1843 void IdealGraphPrinter::Property::clean() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1844 if (_name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1845 delete _name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1846 _name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1848
a61af66fc99e Initial load
duke
parents:
diff changeset
1849 if (_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1850 delete _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
1851 _value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1854
a61af66fc99e Initial load
duke
parents:
diff changeset
1855
a61af66fc99e Initial load
duke
parents:
diff changeset
1856 bool IdealGraphPrinter::Property::is_null() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1857 return _name == NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1859
a61af66fc99e Initial load
duke
parents:
diff changeset
1860 void IdealGraphPrinter::Property::print(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1861
a61af66fc99e Initial load
duke
parents:
diff changeset
1862 assert(!is_null(), "null properties cannot be printed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
1863 Properties properties;
a61af66fc99e Initial load
duke
parents:
diff changeset
1864 properties.add(new Property(PROPERTY_NAME_PROPERTY, _name));
a61af66fc99e Initial load
duke
parents:
diff changeset
1865 printer->start_element(PROPERTY_ELEMENT, &properties, false, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1866 printer->print_xml(_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1867 printer->end_element(PROPERTY_ELEMENT, false, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1869
a61af66fc99e Initial load
duke
parents:
diff changeset
1870 void IdealGraphPrinter::Property::print_as_attribute(IdealGraphPrinter *printer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1871
a61af66fc99e Initial load
duke
parents:
diff changeset
1872 printer->output()->print(_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1873 printer->output()->print("=\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 printer->print_xml(_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 printer->output()->print("\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
1876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1877
a61af66fc99e Initial load
duke
parents:
diff changeset
1878
a61af66fc99e Initial load
duke
parents:
diff changeset
1879 bool IdealGraphPrinter::Property::equals(Property* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1880
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 if (is_null() && p->is_null()) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 if (is_null()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 if (p->is_null()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1884
a61af66fc99e Initial load
duke
parents:
diff changeset
1885 int cmp1 = strcmp(p->_name, _name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 if (cmp1 != 0) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1887
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 int cmp2 = strcmp(p->_value, _value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 if (cmp2 != 0) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1890
a61af66fc99e Initial load
duke
parents:
diff changeset
1891 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1893
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 void IdealGraphPrinter::print_xml(const char *value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1895 size_t len = strlen(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1896
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 char buf[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 buf[1] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 for (size_t i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 char c = value[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
1901
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 switch(c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1903 case '<':
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 output()->print("&lt;");
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1906
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 case '>':
a61af66fc99e Initial load
duke
parents:
diff changeset
1908 output()->print("&gt;");
a61af66fc99e Initial load
duke
parents:
diff changeset
1909 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1910
a61af66fc99e Initial load
duke
parents:
diff changeset
1911 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1912 buf[0] = c;
a61af66fc99e Initial load
duke
parents:
diff changeset
1913 output()->print(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1916 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1917 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1918
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 #endif