Mercurial > hg > truffle
annotate src/share/vm/opto/node.cpp @ 1721:413ad0331a0c
6977924: Changes for 6975078 produce build error with certain gcc versions
Summary: The changes introduced for 6975078 assign badHeapOopVal to the _allocation field in the ResourceObj class. In 32 bit linux builds with certain versions of gcc this assignment will be flagged as an error while compiling allocation.cpp. In 32 bit builds the constant value badHeapOopVal (which is cast to an intptr_t) is negative. The _allocation field is typed as an unsigned intptr_t and gcc catches this as an error.
Reviewed-by: jcoomes, ysr, phh
author | johnc |
---|---|
date | Wed, 18 Aug 2010 10:59:06 -0700 |
parents | c18cbe5936b8 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_node.cpp.incl" | |
27 | |
28 class RegMask; | |
29 // #include "phase.hpp" | |
30 class PhaseTransform; | |
31 class PhaseGVN; | |
32 | |
33 // Arena we are currently building Nodes in | |
34 const uint Node::NotAMachineReg = 0xffff0000; | |
35 | |
36 #ifndef PRODUCT | |
37 extern int nodes_created; | |
38 #endif | |
39 | |
40 #ifdef ASSERT | |
41 | |
42 //-------------------------- construct_node------------------------------------ | |
43 // Set a breakpoint here to identify where a particular node index is built. | |
44 void Node::verify_construction() { | |
45 _debug_orig = NULL; | |
46 int old_debug_idx = Compile::debug_idx(); | |
47 int new_debug_idx = old_debug_idx+1; | |
48 if (new_debug_idx > 0) { | |
49 // Arrange that the lowest five decimal digits of _debug_idx | |
50 // will repeat thos of _idx. In case this is somehow pathological, | |
51 // we continue to assign negative numbers (!) consecutively. | |
52 const int mod = 100000; | |
53 int bump = (int)(_idx - new_debug_idx) % mod; | |
54 if (bump < 0) bump += mod; | |
55 assert(bump >= 0 && bump < mod, ""); | |
56 new_debug_idx += bump; | |
57 } | |
58 Compile::set_debug_idx(new_debug_idx); | |
59 set_debug_idx( new_debug_idx ); | |
60 assert(Compile::current()->unique() < (uint)MaxNodeLimit, "Node limit exceeded"); | |
61 if (BreakAtNode != 0 && (_debug_idx == BreakAtNode || (int)_idx == BreakAtNode)) { | |
62 tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d", _idx, _debug_idx); | |
63 BREAKPOINT; | |
64 } | |
65 #if OPTO_DU_ITERATOR_ASSERT | |
66 _last_del = NULL; | |
67 _del_tick = 0; | |
68 #endif | |
69 _hash_lock = 0; | |
70 } | |
71 | |
72 | |
73 // #ifdef ASSERT ... | |
74 | |
75 #if OPTO_DU_ITERATOR_ASSERT | |
76 void DUIterator_Common::sample(const Node* node) { | |
77 _vdui = VerifyDUIterators; | |
78 _node = node; | |
79 _outcnt = node->_outcnt; | |
80 _del_tick = node->_del_tick; | |
81 _last = NULL; | |
82 } | |
83 | |
84 void DUIterator_Common::verify(const Node* node, bool at_end_ok) { | |
85 assert(_node == node, "consistent iterator source"); | |
86 assert(_del_tick == node->_del_tick, "no unexpected deletions allowed"); | |
87 } | |
88 | |
89 void DUIterator_Common::verify_resync() { | |
90 // Ensure that the loop body has just deleted the last guy produced. | |
91 const Node* node = _node; | |
92 // Ensure that at least one copy of the last-seen edge was deleted. | |
93 // Note: It is OK to delete multiple copies of the last-seen edge. | |
94 // Unfortunately, we have no way to verify that all the deletions delete | |
95 // that same edge. On this point we must use the Honor System. | |
96 assert(node->_del_tick >= _del_tick+1, "must have deleted an edge"); | |
97 assert(node->_last_del == _last, "must have deleted the edge just produced"); | |
98 // We liked this deletion, so accept the resulting outcnt and tick. | |
99 _outcnt = node->_outcnt; | |
100 _del_tick = node->_del_tick; | |
101 } | |
102 | |
103 void DUIterator_Common::reset(const DUIterator_Common& that) { | |
104 if (this == &that) return; // ignore assignment to self | |
105 if (!_vdui) { | |
106 // We need to initialize everything, overwriting garbage values. | |
107 _last = that._last; | |
108 _vdui = that._vdui; | |
109 } | |
110 // Note: It is legal (though odd) for an iterator over some node x | |
111 // to be reassigned to iterate over another node y. Some doubly-nested | |
112 // progress loops depend on being able to do this. | |
113 const Node* node = that._node; | |
114 // Re-initialize everything, except _last. | |
115 _node = node; | |
116 _outcnt = node->_outcnt; | |
117 _del_tick = node->_del_tick; | |
118 } | |
119 | |
120 void DUIterator::sample(const Node* node) { | |
121 DUIterator_Common::sample(node); // Initialize the assertion data. | |
122 _refresh_tick = 0; // No refreshes have happened, as yet. | |
123 } | |
124 | |
125 void DUIterator::verify(const Node* node, bool at_end_ok) { | |
126 DUIterator_Common::verify(node, at_end_ok); | |
127 assert(_idx < node->_outcnt + (uint)at_end_ok, "idx in range"); | |
128 } | |
129 | |
130 void DUIterator::verify_increment() { | |
131 if (_refresh_tick & 1) { | |
132 // We have refreshed the index during this loop. | |
133 // Fix up _idx to meet asserts. | |
134 if (_idx > _outcnt) _idx = _outcnt; | |
135 } | |
136 verify(_node, true); | |
137 } | |
138 | |
139 void DUIterator::verify_resync() { | |
140 // Note: We do not assert on _outcnt, because insertions are OK here. | |
141 DUIterator_Common::verify_resync(); | |
142 // Make sure we are still in sync, possibly with no more out-edges: | |
143 verify(_node, true); | |
144 } | |
145 | |
146 void DUIterator::reset(const DUIterator& that) { | |
147 if (this == &that) return; // self assignment is always a no-op | |
148 assert(that._refresh_tick == 0, "assign only the result of Node::outs()"); | |
149 assert(that._idx == 0, "assign only the result of Node::outs()"); | |
150 assert(_idx == that._idx, "already assigned _idx"); | |
151 if (!_vdui) { | |
152 // We need to initialize everything, overwriting garbage values. | |
153 sample(that._node); | |
154 } else { | |
155 DUIterator_Common::reset(that); | |
156 if (_refresh_tick & 1) { | |
157 _refresh_tick++; // Clear the "was refreshed" flag. | |
158 } | |
159 assert(_refresh_tick < 2*100000, "DU iteration must converge quickly"); | |
160 } | |
161 } | |
162 | |
163 void DUIterator::refresh() { | |
164 DUIterator_Common::sample(_node); // Re-fetch assertion data. | |
165 _refresh_tick |= 1; // Set the "was refreshed" flag. | |
166 } | |
167 | |
168 void DUIterator::verify_finish() { | |
169 // If the loop has killed the node, do not require it to re-run. | |
170 if (_node->_outcnt == 0) _refresh_tick &= ~1; | |
171 // If this assert triggers, it means that a loop used refresh_out_pos | |
172 // to re-synch an iteration index, but the loop did not correctly | |
173 // re-run itself, using a "while (progress)" construct. | |
174 // This iterator enforces the rule that you must keep trying the loop | |
175 // until it "runs clean" without any need for refreshing. | |
176 assert(!(_refresh_tick & 1), "the loop must run once with no refreshing"); | |
177 } | |
178 | |
179 | |
180 void DUIterator_Fast::verify(const Node* node, bool at_end_ok) { | |
181 DUIterator_Common::verify(node, at_end_ok); | |
182 Node** out = node->_out; | |
183 uint cnt = node->_outcnt; | |
184 assert(cnt == _outcnt, "no insertions allowed"); | |
185 assert(_outp >= out && _outp <= out + cnt - !at_end_ok, "outp in range"); | |
186 // This last check is carefully designed to work for NO_OUT_ARRAY. | |
187 } | |
188 | |
189 void DUIterator_Fast::verify_limit() { | |
190 const Node* node = _node; | |
191 verify(node, true); | |
192 assert(_outp == node->_out + node->_outcnt, "limit still correct"); | |
193 } | |
194 | |
195 void DUIterator_Fast::verify_resync() { | |
196 const Node* node = _node; | |
197 if (_outp == node->_out + _outcnt) { | |
198 // Note that the limit imax, not the pointer i, gets updated with the | |
199 // exact count of deletions. (For the pointer it's always "--i".) | |
200 assert(node->_outcnt+node->_del_tick == _outcnt+_del_tick, "no insertions allowed with deletion(s)"); | |
201 // This is a limit pointer, with a name like "imax". | |
202 // Fudge the _last field so that the common assert will be happy. | |
203 _last = (Node*) node->_last_del; | |
204 DUIterator_Common::verify_resync(); | |
205 } else { | |
206 assert(node->_outcnt < _outcnt, "no insertions allowed with deletion(s)"); | |
207 // A normal internal pointer. | |
208 DUIterator_Common::verify_resync(); | |
209 // Make sure we are still in sync, possibly with no more out-edges: | |
210 verify(node, true); | |
211 } | |
212 } | |
213 | |
214 void DUIterator_Fast::verify_relimit(uint n) { | |
215 const Node* node = _node; | |
216 assert((int)n > 0, "use imax -= n only with a positive count"); | |
217 // This must be a limit pointer, with a name like "imax". | |
218 assert(_outp == node->_out + node->_outcnt, "apply -= only to a limit (imax)"); | |
219 // The reported number of deletions must match what the node saw. | |
220 assert(node->_del_tick == _del_tick + n, "must have deleted n edges"); | |
221 // Fudge the _last field so that the common assert will be happy. | |
222 _last = (Node*) node->_last_del; | |
223 DUIterator_Common::verify_resync(); | |
224 } | |
225 | |
226 void DUIterator_Fast::reset(const DUIterator_Fast& that) { | |
227 assert(_outp == that._outp, "already assigned _outp"); | |
228 DUIterator_Common::reset(that); | |
229 } | |
230 | |
231 void DUIterator_Last::verify(const Node* node, bool at_end_ok) { | |
232 // at_end_ok means the _outp is allowed to underflow by 1 | |
233 _outp += at_end_ok; | |
234 DUIterator_Fast::verify(node, at_end_ok); // check _del_tick, etc. | |
235 _outp -= at_end_ok; | |
236 assert(_outp == (node->_out + node->_outcnt) - 1, "pointer must point to end of nodes"); | |
237 } | |
238 | |
239 void DUIterator_Last::verify_limit() { | |
240 // Do not require the limit address to be resynched. | |
241 //verify(node, true); | |
242 assert(_outp == _node->_out, "limit still correct"); | |
243 } | |
244 | |
245 void DUIterator_Last::verify_step(uint num_edges) { | |
246 assert((int)num_edges > 0, "need non-zero edge count for loop progress"); | |
247 _outcnt -= num_edges; | |
248 _del_tick += num_edges; | |
249 // Make sure we are still in sync, possibly with no more out-edges: | |
250 const Node* node = _node; | |
251 verify(node, true); | |
252 assert(node->_last_del == _last, "must have deleted the edge just produced"); | |
253 } | |
254 | |
255 #endif //OPTO_DU_ITERATOR_ASSERT | |
256 | |
257 | |
258 #endif //ASSERT | |
259 | |
260 | |
261 // This constant used to initialize _out may be any non-null value. | |
262 // The value NULL is reserved for the top node only. | |
263 #define NO_OUT_ARRAY ((Node**)-1) | |
264 | |
265 // This funny expression handshakes with Node::operator new | |
266 // to pull Compile::current out of the new node's _out field, | |
267 // and then calls a subroutine which manages most field | |
268 // initializations. The only one which is tricky is the | |
269 // _idx field, which is const, and so must be initialized | |
270 // by a return value, not an assignment. | |
271 // | |
272 // (Aren't you thankful that Java finals don't require so many tricks?) | |
273 #define IDX_INIT(req) this->Init((req), (Compile*) this->_out) | |
274 #ifdef _MSC_VER // the IDX_INIT hack falls foul of warning C4355 | |
275 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
276 #endif | |
277 | |
278 // Out-of-line code from node constructors. | |
279 // Executed only when extra debug info. is being passed around. | |
280 static void init_node_notes(Compile* C, int idx, Node_Notes* nn) { | |
281 C->set_node_notes_at(idx, nn); | |
282 } | |
283 | |
284 // Shared initialization code. | |
285 inline int Node::Init(int req, Compile* C) { | |
286 assert(Compile::current() == C, "must use operator new(Compile*)"); | |
287 int idx = C->next_unique(); | |
288 | |
289 // If there are default notes floating around, capture them: | |
290 Node_Notes* nn = C->default_node_notes(); | |
291 if (nn != NULL) init_node_notes(C, idx, nn); | |
292 | |
293 // Note: At this point, C is dead, | |
294 // and we begin to initialize the new Node. | |
295 | |
296 _cnt = _max = req; | |
297 _outcnt = _outmax = 0; | |
298 _class_id = Class_Node; | |
299 _flags = 0; | |
300 _out = NO_OUT_ARRAY; | |
301 return idx; | |
302 } | |
303 | |
304 //------------------------------Node------------------------------------------- | |
305 // Create a Node, with a given number of required edges. | |
306 Node::Node(uint req) | |
307 : _idx(IDX_INIT(req)) | |
308 { | |
309 assert( req < (uint)(MaxNodeLimit - NodeLimitFudgeFactor), "Input limit exceeded" ); | |
310 debug_only( verify_construction() ); | |
311 NOT_PRODUCT(nodes_created++); | |
312 if (req == 0) { | |
313 assert( _in == (Node**)this, "Must not pass arg count to 'new'" ); | |
314 _in = NULL; | |
315 } else { | |
316 assert( _in[req-1] == this, "Must pass arg count to 'new'" ); | |
317 Node** to = _in; | |
318 for(uint i = 0; i < req; i++) { | |
319 to[i] = NULL; | |
320 } | |
321 } | |
322 } | |
323 | |
324 //------------------------------Node------------------------------------------- | |
325 Node::Node(Node *n0) | |
326 : _idx(IDX_INIT(1)) | |
327 { | |
328 debug_only( verify_construction() ); | |
329 NOT_PRODUCT(nodes_created++); | |
330 // Assert we allocated space for input array already | |
331 assert( _in[0] == this, "Must pass arg count to 'new'" ); | |
332 assert( is_not_dead(n0), "can not use dead node"); | |
333 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
334 } | |
335 | |
336 //------------------------------Node------------------------------------------- | |
337 Node::Node(Node *n0, Node *n1) | |
338 : _idx(IDX_INIT(2)) | |
339 { | |
340 debug_only( verify_construction() ); | |
341 NOT_PRODUCT(nodes_created++); | |
342 // Assert we allocated space for input array already | |
343 assert( _in[1] == this, "Must pass arg count to 'new'" ); | |
344 assert( is_not_dead(n0), "can not use dead node"); | |
345 assert( is_not_dead(n1), "can not use dead node"); | |
346 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
347 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
348 } | |
349 | |
350 //------------------------------Node------------------------------------------- | |
351 Node::Node(Node *n0, Node *n1, Node *n2) | |
352 : _idx(IDX_INIT(3)) | |
353 { | |
354 debug_only( verify_construction() ); | |
355 NOT_PRODUCT(nodes_created++); | |
356 // Assert we allocated space for input array already | |
357 assert( _in[2] == this, "Must pass arg count to 'new'" ); | |
358 assert( is_not_dead(n0), "can not use dead node"); | |
359 assert( is_not_dead(n1), "can not use dead node"); | |
360 assert( is_not_dead(n2), "can not use dead node"); | |
361 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
362 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
363 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); | |
364 } | |
365 | |
366 //------------------------------Node------------------------------------------- | |
367 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3) | |
368 : _idx(IDX_INIT(4)) | |
369 { | |
370 debug_only( verify_construction() ); | |
371 NOT_PRODUCT(nodes_created++); | |
372 // Assert we allocated space for input array already | |
373 assert( _in[3] == this, "Must pass arg count to 'new'" ); | |
374 assert( is_not_dead(n0), "can not use dead node"); | |
375 assert( is_not_dead(n1), "can not use dead node"); | |
376 assert( is_not_dead(n2), "can not use dead node"); | |
377 assert( is_not_dead(n3), "can not use dead node"); | |
378 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
379 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
380 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); | |
381 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); | |
382 } | |
383 | |
384 //------------------------------Node------------------------------------------- | |
385 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4) | |
386 : _idx(IDX_INIT(5)) | |
387 { | |
388 debug_only( verify_construction() ); | |
389 NOT_PRODUCT(nodes_created++); | |
390 // Assert we allocated space for input array already | |
391 assert( _in[4] == this, "Must pass arg count to 'new'" ); | |
392 assert( is_not_dead(n0), "can not use dead node"); | |
393 assert( is_not_dead(n1), "can not use dead node"); | |
394 assert( is_not_dead(n2), "can not use dead node"); | |
395 assert( is_not_dead(n3), "can not use dead node"); | |
396 assert( is_not_dead(n4), "can not use dead node"); | |
397 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
398 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
399 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); | |
400 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); | |
401 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); | |
402 } | |
403 | |
404 //------------------------------Node------------------------------------------- | |
405 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, | |
406 Node *n4, Node *n5) | |
407 : _idx(IDX_INIT(6)) | |
408 { | |
409 debug_only( verify_construction() ); | |
410 NOT_PRODUCT(nodes_created++); | |
411 // Assert we allocated space for input array already | |
412 assert( _in[5] == this, "Must pass arg count to 'new'" ); | |
413 assert( is_not_dead(n0), "can not use dead node"); | |
414 assert( is_not_dead(n1), "can not use dead node"); | |
415 assert( is_not_dead(n2), "can not use dead node"); | |
416 assert( is_not_dead(n3), "can not use dead node"); | |
417 assert( is_not_dead(n4), "can not use dead node"); | |
418 assert( is_not_dead(n5), "can not use dead node"); | |
419 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
420 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
421 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); | |
422 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); | |
423 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); | |
424 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); | |
425 } | |
426 | |
427 //------------------------------Node------------------------------------------- | |
428 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, | |
429 Node *n4, Node *n5, Node *n6) | |
430 : _idx(IDX_INIT(7)) | |
431 { | |
432 debug_only( verify_construction() ); | |
433 NOT_PRODUCT(nodes_created++); | |
434 // Assert we allocated space for input array already | |
435 assert( _in[6] == this, "Must pass arg count to 'new'" ); | |
436 assert( is_not_dead(n0), "can not use dead node"); | |
437 assert( is_not_dead(n1), "can not use dead node"); | |
438 assert( is_not_dead(n2), "can not use dead node"); | |
439 assert( is_not_dead(n3), "can not use dead node"); | |
440 assert( is_not_dead(n4), "can not use dead node"); | |
441 assert( is_not_dead(n5), "can not use dead node"); | |
442 assert( is_not_dead(n6), "can not use dead node"); | |
443 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); | |
444 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); | |
445 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); | |
446 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); | |
447 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); | |
448 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); | |
449 _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this); | |
450 } | |
451 | |
452 | |
453 //------------------------------clone------------------------------------------ | |
454 // Clone a Node. | |
455 Node *Node::clone() const { | |
456 Compile *compile = Compile::current(); | |
457 uint s = size_of(); // Size of inherited Node | |
458 Node *n = (Node*)compile->node_arena()->Amalloc_D(size_of() + _max*sizeof(Node*)); | |
459 Copy::conjoint_words_to_lower((HeapWord*)this, (HeapWord*)n, s); | |
460 // Set the new input pointer array | |
461 n->_in = (Node**)(((char*)n)+s); | |
462 // Cannot share the old output pointer array, so kill it | |
463 n->_out = NO_OUT_ARRAY; | |
464 // And reset the counters to 0 | |
465 n->_outcnt = 0; | |
466 n->_outmax = 0; | |
467 // Unlock this guy, since he is not in any hash table. | |
468 debug_only(n->_hash_lock = 0); | |
469 // Walk the old node's input list to duplicate its edges | |
470 uint i; | |
471 for( i = 0; i < len(); i++ ) { | |
472 Node *x = in(i); | |
473 n->_in[i] = x; | |
474 if (x != NULL) x->add_out(n); | |
475 } | |
476 if (is_macro()) | |
477 compile->add_macro_node(n); | |
478 | |
479 n->set_idx(compile->next_unique()); // Get new unique index as well | |
480 debug_only( n->verify_construction() ); | |
481 NOT_PRODUCT(nodes_created++); | |
482 // Do not patch over the debug_idx of a clone, because it makes it | |
483 // impossible to break on the clone's moment of creation. | |
484 //debug_only( n->set_debug_idx( debug_idx() ) ); | |
485 | |
486 compile->copy_node_notes_to(n, (Node*) this); | |
487 | |
488 // MachNode clone | |
489 uint nopnds; | |
490 if (this->is_Mach() && (nopnds = this->as_Mach()->num_opnds()) > 0) { | |
491 MachNode *mach = n->as_Mach(); | |
492 MachNode *mthis = this->as_Mach(); | |
493 // Get address of _opnd_array. | |
494 // It should be the same offset since it is the clone of this node. | |
495 MachOper **from = mthis->_opnds; | |
496 MachOper **to = (MachOper **)((size_t)(&mach->_opnds) + | |
497 pointer_delta((const void*)from, | |
498 (const void*)(&mthis->_opnds), 1)); | |
499 mach->_opnds = to; | |
500 for ( uint i = 0; i < nopnds; ++i ) { | |
501 to[i] = from[i]->clone(compile); | |
502 } | |
503 } | |
504 // cloning CallNode may need to clone JVMState | |
505 if (n->is_Call()) { | |
506 CallNode *call = n->as_Call(); | |
507 call->clone_jvms(); | |
508 } | |
509 return n; // Return the clone | |
510 } | |
511 | |
512 //---------------------------setup_is_top-------------------------------------- | |
513 // Call this when changing the top node, to reassert the invariants | |
514 // required by Node::is_top. See Compile::set_cached_top_node. | |
515 void Node::setup_is_top() { | |
516 if (this == (Node*)Compile::current()->top()) { | |
517 // This node has just become top. Kill its out array. | |
518 _outcnt = _outmax = 0; | |
519 _out = NULL; // marker value for top | |
520 assert(is_top(), "must be top"); | |
521 } else { | |
522 if (_out == NULL) _out = NO_OUT_ARRAY; | |
523 assert(!is_top(), "must not be top"); | |
524 } | |
525 } | |
526 | |
527 | |
528 //------------------------------~Node------------------------------------------ | |
529 // Fancy destructor; eagerly attempt to reclaim Node numberings and storage | |
530 extern int reclaim_idx ; | |
531 extern int reclaim_in ; | |
532 extern int reclaim_node; | |
533 void Node::destruct() { | |
534 // Eagerly reclaim unique Node numberings | |
535 Compile* compile = Compile::current(); | |
536 if ((uint)_idx+1 == compile->unique()) { | |
537 compile->set_unique(compile->unique()-1); | |
538 #ifdef ASSERT | |
539 reclaim_idx++; | |
540 #endif | |
541 } | |
542 // Clear debug info: | |
543 Node_Notes* nn = compile->node_notes_at(_idx); | |
544 if (nn != NULL) nn->clear(); | |
545 // Walk the input array, freeing the corresponding output edges | |
546 _cnt = _max; // forget req/prec distinction | |
547 uint i; | |
548 for( i = 0; i < _max; i++ ) { | |
549 set_req(i, NULL); | |
550 //assert(def->out(def->outcnt()-1) == (Node *)this,"bad def-use hacking in reclaim"); | |
551 } | |
552 assert(outcnt() == 0, "deleting a node must not leave a dangling use"); | |
553 // See if the input array was allocated just prior to the object | |
554 int edge_size = _max*sizeof(void*); | |
555 int out_edge_size = _outmax*sizeof(void*); | |
556 char *edge_end = ((char*)_in) + edge_size; | |
557 char *out_array = (char*)(_out == NO_OUT_ARRAY? NULL: _out); | |
558 char *out_edge_end = out_array + out_edge_size; | |
559 int node_size = size_of(); | |
560 | |
561 // Free the output edge array | |
562 if (out_edge_size > 0) { | |
563 #ifdef ASSERT | |
564 if( out_edge_end == compile->node_arena()->hwm() ) | |
565 reclaim_in += out_edge_size; // count reclaimed out edges with in edges | |
566 #endif | |
567 compile->node_arena()->Afree(out_array, out_edge_size); | |
568 } | |
569 | |
570 // Free the input edge array and the node itself | |
571 if( edge_end == (char*)this ) { | |
572 #ifdef ASSERT | |
573 if( edge_end+node_size == compile->node_arena()->hwm() ) { | |
574 reclaim_in += edge_size; | |
575 reclaim_node+= node_size; | |
576 } | |
577 #else | |
578 // It was; free the input array and object all in one hit | |
579 compile->node_arena()->Afree(_in,edge_size+node_size); | |
580 #endif | |
581 } else { | |
582 | |
583 // Free just the input array | |
584 #ifdef ASSERT | |
585 if( edge_end == compile->node_arena()->hwm() ) | |
586 reclaim_in += edge_size; | |
587 #endif | |
588 compile->node_arena()->Afree(_in,edge_size); | |
589 | |
590 // Free just the object | |
591 #ifdef ASSERT | |
592 if( ((char*)this) + node_size == compile->node_arena()->hwm() ) | |
593 reclaim_node+= node_size; | |
594 #else | |
595 compile->node_arena()->Afree(this,node_size); | |
596 #endif | |
597 } | |
598 if (is_macro()) { | |
599 compile->remove_macro_node(this); | |
600 } | |
601 #ifdef ASSERT | |
602 // We will not actually delete the storage, but we'll make the node unusable. | |
603 *(address*)this = badAddress; // smash the C++ vtbl, probably | |
604 _in = _out = (Node**) badAddress; | |
605 _max = _cnt = _outmax = _outcnt = 0; | |
606 #endif | |
607 } | |
608 | |
609 //------------------------------grow------------------------------------------- | |
610 // Grow the input array, making space for more edges | |
611 void Node::grow( uint len ) { | |
612 Arena* arena = Compile::current()->node_arena(); | |
613 uint new_max = _max; | |
614 if( new_max == 0 ) { | |
615 _max = 4; | |
616 _in = (Node**)arena->Amalloc(4*sizeof(Node*)); | |
617 Node** to = _in; | |
618 to[0] = NULL; | |
619 to[1] = NULL; | |
620 to[2] = NULL; | |
621 to[3] = NULL; | |
622 return; | |
623 } | |
624 while( new_max <= len ) new_max <<= 1; // Find next power-of-2 | |
625 // Trimming to limit allows a uint8 to handle up to 255 edges. | |
626 // Previously I was using only powers-of-2 which peaked at 128 edges. | |
627 //if( new_max >= limit ) new_max = limit-1; | |
628 _in = (Node**)arena->Arealloc(_in, _max*sizeof(Node*), new_max*sizeof(Node*)); | |
629 Copy::zero_to_bytes(&_in[_max], (new_max-_max)*sizeof(Node*)); // NULL all new space | |
630 _max = new_max; // Record new max length | |
631 // This assertion makes sure that Node::_max is wide enough to | |
632 // represent the numerical value of new_max. | |
633 assert(_max == new_max && _max > len, "int width of _max is too small"); | |
634 } | |
635 | |
636 //-----------------------------out_grow---------------------------------------- | |
637 // Grow the input array, making space for more edges | |
638 void Node::out_grow( uint len ) { | |
639 assert(!is_top(), "cannot grow a top node's out array"); | |
640 Arena* arena = Compile::current()->node_arena(); | |
641 uint new_max = _outmax; | |
642 if( new_max == 0 ) { | |
643 _outmax = 4; | |
644 _out = (Node **)arena->Amalloc(4*sizeof(Node*)); | |
645 return; | |
646 } | |
647 while( new_max <= len ) new_max <<= 1; // Find next power-of-2 | |
648 // Trimming to limit allows a uint8 to handle up to 255 edges. | |
649 // Previously I was using only powers-of-2 which peaked at 128 edges. | |
650 //if( new_max >= limit ) new_max = limit-1; | |
651 assert(_out != NULL && _out != NO_OUT_ARRAY, "out must have sensible value"); | |
652 _out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*)); | |
653 //Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // NULL all new space | |
654 _outmax = new_max; // Record new max length | |
655 // This assertion makes sure that Node::_max is wide enough to | |
656 // represent the numerical value of new_max. | |
657 assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small"); | |
658 } | |
659 | |
660 #ifdef ASSERT | |
661 //------------------------------is_dead---------------------------------------- | |
662 bool Node::is_dead() const { | |
663 // Mach and pinch point nodes may look like dead. | |
664 if( is_top() || is_Mach() || (Opcode() == Op_Node && _outcnt > 0) ) | |
665 return false; | |
666 for( uint i = 0; i < _max; i++ ) | |
667 if( _in[i] != NULL ) | |
668 return false; | |
669 dump(); | |
670 return true; | |
671 } | |
672 #endif | |
673 | |
674 //------------------------------add_req---------------------------------------- | |
675 // Add a new required input at the end | |
676 void Node::add_req( Node *n ) { | |
677 assert( is_not_dead(n), "can not use dead node"); | |
678 | |
679 // Look to see if I can move precedence down one without reallocating | |
680 if( (_cnt >= _max) || (in(_max-1) != NULL) ) | |
681 grow( _max+1 ); | |
682 | |
683 // Find a precedence edge to move | |
684 if( in(_cnt) != NULL ) { // Next precedence edge is busy? | |
685 uint i; | |
686 for( i=_cnt; i<_max; i++ ) | |
687 if( in(i) == NULL ) // Find the NULL at end of prec edge list | |
688 break; // There must be one, since we grew the array | |
689 _in[i] = in(_cnt); // Move prec over, making space for req edge | |
690 } | |
691 _in[_cnt++] = n; // Stuff over old prec edge | |
692 if (n != NULL) n->add_out((Node *)this); | |
693 } | |
694 | |
695 //---------------------------add_req_batch------------------------------------- | |
696 // Add a new required input at the end | |
697 void Node::add_req_batch( Node *n, uint m ) { | |
698 assert( is_not_dead(n), "can not use dead node"); | |
699 // check various edge cases | |
700 if ((int)m <= 1) { | |
701 assert((int)m >= 0, "oob"); | |
702 if (m != 0) add_req(n); | |
703 return; | |
704 } | |
705 | |
706 // Look to see if I can move precedence down one without reallocating | |
707 if( (_cnt+m) > _max || _in[_max-m] ) | |
708 grow( _max+m ); | |
709 | |
710 // Find a precedence edge to move | |
711 if( _in[_cnt] != NULL ) { // Next precedence edge is busy? | |
712 uint i; | |
713 for( i=_cnt; i<_max; i++ ) | |
714 if( _in[i] == NULL ) // Find the NULL at end of prec edge list | |
715 break; // There must be one, since we grew the array | |
716 // Slide all the precs over by m positions (assume #prec << m). | |
717 Copy::conjoint_words_to_higher((HeapWord*)&_in[_cnt], (HeapWord*)&_in[_cnt+m], ((i-_cnt)*sizeof(Node*))); | |
718 } | |
719 | |
720 // Stuff over the old prec edges | |
721 for(uint i=0; i<m; i++ ) { | |
722 _in[_cnt++] = n; | |
723 } | |
724 | |
725 // Insert multiple out edges on the node. | |
726 if (n != NULL && !n->is_top()) { | |
727 for(uint i=0; i<m; i++ ) { | |
728 n->add_out((Node *)this); | |
729 } | |
730 } | |
731 } | |
732 | |
733 //------------------------------del_req---------------------------------------- | |
734 // Delete the required edge and compact the edge array | |
735 void Node::del_req( uint idx ) { | |
736 // First remove corresponding def-use edge | |
737 Node *n = in(idx); | |
738 if (n != NULL) n->del_out((Node *)this); | |
739 _in[idx] = in(--_cnt); // Compact the array | |
740 _in[_cnt] = NULL; // NULL out emptied slot | |
741 } | |
742 | |
743 //------------------------------ins_req---------------------------------------- | |
744 // Insert a new required input at the end | |
745 void Node::ins_req( uint idx, Node *n ) { | |
746 assert( is_not_dead(n), "can not use dead node"); | |
747 add_req(NULL); // Make space | |
748 assert( idx < _max, "Must have allocated enough space"); | |
749 // Slide over | |
750 if(_cnt-idx-1 > 0) { | |
751 Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*))); | |
752 } | |
753 _in[idx] = n; // Stuff over old required edge | |
754 if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge | |
755 } | |
756 | |
757 //-----------------------------find_edge--------------------------------------- | |
758 int Node::find_edge(Node* n) { | |
759 for (uint i = 0; i < len(); i++) { | |
760 if (_in[i] == n) return i; | |
761 } | |
762 return -1; | |
763 } | |
764 | |
765 //----------------------------replace_edge------------------------------------- | |
766 int Node::replace_edge(Node* old, Node* neww) { | |
767 if (old == neww) return 0; // nothing to do | |
768 uint nrep = 0; | |
769 for (uint i = 0; i < len(); i++) { | |
770 if (in(i) == old) { | |
771 if (i < req()) | |
772 set_req(i, neww); | |
773 else | |
774 set_prec(i, neww); | |
775 nrep++; | |
776 } | |
777 } | |
778 return nrep; | |
779 } | |
780 | |
781 //-------------------------disconnect_inputs----------------------------------- | |
782 // NULL out all inputs to eliminate incoming Def-Use edges. | |
783 // Return the number of edges between 'n' and 'this' | |
784 int Node::disconnect_inputs(Node *n) { | |
785 int edges_to_n = 0; | |
786 | |
787 uint cnt = req(); | |
788 for( uint i = 0; i < cnt; ++i ) { | |
789 if( in(i) == 0 ) continue; | |
790 if( in(i) == n ) ++edges_to_n; | |
791 set_req(i, NULL); | |
792 } | |
793 // Remove precedence edges if any exist | |
794 // Note: Safepoints may have precedence edges, even during parsing | |
795 if( (req() != len()) && (in(req()) != NULL) ) { | |
796 uint max = len(); | |
797 for( uint i = 0; i < max; ++i ) { | |
798 if( in(i) == 0 ) continue; | |
799 if( in(i) == n ) ++edges_to_n; | |
800 set_prec(i, NULL); | |
801 } | |
802 } | |
803 | |
804 // Node::destruct requires all out edges be deleted first | |
805 // debug_only(destruct();) // no reuse benefit expected | |
806 return edges_to_n; | |
807 } | |
808 | |
809 //-----------------------------uncast--------------------------------------- | |
810 // %%% Temporary, until we sort out CheckCastPP vs. CastPP. | |
811 // Strip away casting. (It is depth-limited.) | |
812 Node* Node::uncast() const { | |
813 // Should be inline: | |
814 //return is_ConstraintCast() ? uncast_helper(this) : (Node*) this; | |
65 | 815 if (is_ConstraintCast() || is_CheckCastPP()) |
0 | 816 return uncast_helper(this); |
817 else | |
818 return (Node*) this; | |
819 } | |
820 | |
821 //---------------------------uncast_helper------------------------------------- | |
822 Node* Node::uncast_helper(const Node* p) { | |
823 uint max_depth = 3; | |
824 for (uint i = 0; i < max_depth; i++) { | |
825 if (p == NULL || p->req() != 2) { | |
826 break; | |
827 } else if (p->is_ConstraintCast()) { | |
828 p = p->in(1); | |
65 | 829 } else if (p->is_CheckCastPP()) { |
0 | 830 p = p->in(1); |
831 } else { | |
832 break; | |
833 } | |
834 } | |
835 return (Node*) p; | |
836 } | |
837 | |
838 //------------------------------add_prec--------------------------------------- | |
839 // Add a new precedence input. Precedence inputs are unordered, with | |
840 // duplicates removed and NULLs packed down at the end. | |
841 void Node::add_prec( Node *n ) { | |
842 assert( is_not_dead(n), "can not use dead node"); | |
843 | |
844 // Check for NULL at end | |
845 if( _cnt >= _max || in(_max-1) ) | |
846 grow( _max+1 ); | |
847 | |
848 // Find a precedence edge to move | |
849 uint i = _cnt; | |
850 while( in(i) != NULL ) i++; | |
851 _in[i] = n; // Stuff prec edge over NULL | |
852 if ( n != NULL) n->add_out((Node *)this); // Add mirror edge | |
853 } | |
854 | |
855 //------------------------------rm_prec---------------------------------------- | |
856 // Remove a precedence input. Precedence inputs are unordered, with | |
857 // duplicates removed and NULLs packed down at the end. | |
858 void Node::rm_prec( uint j ) { | |
859 | |
860 // Find end of precedence list to pack NULLs | |
861 uint i; | |
862 for( i=j; i<_max; i++ ) | |
863 if( !_in[i] ) // Find the NULL at end of prec edge list | |
864 break; | |
865 if (_in[j] != NULL) _in[j]->del_out((Node *)this); | |
866 _in[j] = _in[--i]; // Move last element over removed guy | |
867 _in[i] = NULL; // NULL out last element | |
868 } | |
869 | |
870 //------------------------------size_of---------------------------------------- | |
871 uint Node::size_of() const { return sizeof(*this); } | |
872 | |
873 //------------------------------ideal_reg-------------------------------------- | |
874 uint Node::ideal_reg() const { return 0; } | |
875 | |
876 //------------------------------jvms------------------------------------------- | |
877 JVMState* Node::jvms() const { return NULL; } | |
878 | |
879 #ifdef ASSERT | |
880 //------------------------------jvms------------------------------------------- | |
881 bool Node::verify_jvms(const JVMState* using_jvms) const { | |
882 for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) { | |
883 if (jvms == using_jvms) return true; | |
884 } | |
885 return false; | |
886 } | |
887 | |
888 //------------------------------init_NodeProperty------------------------------ | |
889 void Node::init_NodeProperty() { | |
890 assert(_max_classes <= max_jushort, "too many NodeProperty classes"); | |
891 assert(_max_flags <= max_jushort, "too many NodeProperty flags"); | |
892 } | |
893 #endif | |
894 | |
895 //------------------------------format----------------------------------------- | |
896 // Print as assembly | |
897 void Node::format( PhaseRegAlloc *, outputStream *st ) const {} | |
898 //------------------------------emit------------------------------------------- | |
899 // Emit bytes starting at parameter 'ptr'. | |
900 void Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {} | |
901 //------------------------------size------------------------------------------- | |
902 // Size of instruction in bytes | |
903 uint Node::size(PhaseRegAlloc *ra_) const { return 0; } | |
904 | |
905 //------------------------------CFG Construction------------------------------- | |
906 // Nodes that end basic blocks, e.g. IfTrue/IfFalse, JumpProjNode, Root, | |
907 // Goto and Return. | |
908 const Node *Node::is_block_proj() const { return 0; } | |
909 | |
910 // Minimum guaranteed type | |
911 const Type *Node::bottom_type() const { return Type::BOTTOM; } | |
912 | |
913 | |
914 //------------------------------raise_bottom_type------------------------------ | |
915 // Get the worst-case Type output for this Node. | |
916 void Node::raise_bottom_type(const Type* new_type) { | |
917 if (is_Type()) { | |
918 TypeNode *n = this->as_Type(); | |
919 if (VerifyAliases) { | |
920 assert(new_type->higher_equal(n->type()), "new type must refine old type"); | |
921 } | |
922 n->set_type(new_type); | |
923 } else if (is_Load()) { | |
924 LoadNode *n = this->as_Load(); | |
925 if (VerifyAliases) { | |
926 assert(new_type->higher_equal(n->type()), "new type must refine old type"); | |
927 } | |
928 n->set_type(new_type); | |
929 } | |
930 } | |
931 | |
932 //------------------------------Identity--------------------------------------- | |
933 // Return a node that the given node is equivalent to. | |
934 Node *Node::Identity( PhaseTransform * ) { | |
935 return this; // Default to no identities | |
936 } | |
937 | |
938 //------------------------------Value------------------------------------------ | |
939 // Compute a new Type for a node using the Type of the inputs. | |
940 const Type *Node::Value( PhaseTransform * ) const { | |
941 return bottom_type(); // Default to worst-case Type | |
942 } | |
943 | |
944 //------------------------------Ideal------------------------------------------ | |
945 // | |
946 // 'Idealize' the graph rooted at this Node. | |
947 // | |
948 // In order to be efficient and flexible there are some subtle invariants | |
949 // these Ideal calls need to hold. Running with '+VerifyIterativeGVN' checks | |
950 // these invariants, although its too slow to have on by default. If you are | |
951 // hacking an Ideal call, be sure to test with +VerifyIterativeGVN! | |
952 // | |
953 // The Ideal call almost arbitrarily reshape the graph rooted at the 'this' | |
954 // pointer. If ANY change is made, it must return the root of the reshaped | |
955 // graph - even if the root is the same Node. Example: swapping the inputs | |
956 // to an AddINode gives the same answer and same root, but you still have to | |
957 // return the 'this' pointer instead of NULL. | |
958 // | |
959 // You cannot return an OLD Node, except for the 'this' pointer. Use the | |
960 // Identity call to return an old Node; basically if Identity can find | |
961 // another Node have the Ideal call make no change and return NULL. | |
962 // Example: AddINode::Ideal must check for add of zero; in this case it | |
963 // returns NULL instead of doing any graph reshaping. | |
964 // | |
965 // You cannot modify any old Nodes except for the 'this' pointer. Due to | |
966 // sharing there may be other users of the old Nodes relying on their current | |
967 // semantics. Modifying them will break the other users. | |
968 // Example: when reshape "(X+3)+4" into "X+7" you must leave the Node for | |
969 // "X+3" unchanged in case it is shared. | |
970 // | |
605 | 971 // If you modify the 'this' pointer's inputs, you should use |
972 // 'set_req'. If you are making a new Node (either as the new root or | |
973 // some new internal piece) you may use 'init_req' to set the initial | |
974 // value. You can make a new Node with either 'new' or 'clone'. In | |
975 // either case, def-use info is correctly maintained. | |
976 // | |
0 | 977 // Example: reshape "(X+3)+4" into "X+7": |
605 | 978 // set_req(1, in(1)->in(1)); |
979 // set_req(2, phase->intcon(7)); | |
0 | 980 // return this; |
605 | 981 // Example: reshape "X*4" into "X<<2" |
982 // return new (C,3) LShiftINode(in(1), phase->intcon(2)); | |
0 | 983 // |
984 // You must call 'phase->transform(X)' on any new Nodes X you make, except | |
605 | 985 // for the returned root node. Example: reshape "X*31" with "(X<<5)-X". |
0 | 986 // Node *shift=phase->transform(new(C,3)LShiftINode(in(1),phase->intcon(5))); |
605 | 987 // return new (C,3) AddINode(shift, in(1)); |
0 | 988 // |
989 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'. | |
990 // These forms are faster than 'phase->transform(new (C,1) ConNode())' and Do | |
991 // The Right Thing with def-use info. | |
992 // | |
993 // You cannot bury the 'this' Node inside of a graph reshape. If the reshaped | |
994 // graph uses the 'this' Node it must be the root. If you want a Node with | |
995 // the same Opcode as the 'this' pointer use 'clone'. | |
996 // | |
997 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) { | |
998 return NULL; // Default to being Ideal already | |
999 } | |
1000 | |
1001 // Some nodes have specific Ideal subgraph transformations only if they are | |
1002 // unique users of specific nodes. Such nodes should be put on IGVN worklist | |
1003 // for the transformations to happen. | |
1004 bool Node::has_special_unique_user() const { | |
1005 assert(outcnt() == 1, "match only for unique out"); | |
1006 Node* n = unique_out(); | |
1007 int op = Opcode(); | |
1008 if( this->is_Store() ) { | |
1009 // Condition for back-to-back stores folding. | |
1010 return n->Opcode() == op && n->in(MemNode::Memory) == this; | |
1011 } else if( op == Op_AddL ) { | |
1012 // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y)) | |
1013 return n->Opcode() == Op_ConvL2I && n->in(1) == this; | |
1014 } else if( op == Op_SubI || op == Op_SubL ) { | |
1015 // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y) | |
1016 return n->Opcode() == op && n->in(2) == this; | |
1017 } | |
1018 return false; | |
1019 }; | |
1020 | |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1021 //--------------------------find_exact_control--------------------------------- |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1022 // Skip Proj and CatchProj nodes chains. Check for Null and Top. |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1023 Node* Node::find_exact_control(Node* ctrl) { |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1024 if (ctrl == NULL && this->is_Region()) |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1025 ctrl = this->as_Region()->is_copy(); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1026 |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1027 if (ctrl != NULL && ctrl->is_CatchProj()) { |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1028 if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index) |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1029 ctrl = ctrl->in(0); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1030 if (ctrl != NULL && !ctrl->is_top()) |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1031 ctrl = ctrl->in(0); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1032 } |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1033 |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1034 if (ctrl != NULL && ctrl->is_Proj()) |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1035 ctrl = ctrl->in(0); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1036 |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1037 return ctrl; |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1038 } |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1039 |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1040 //--------------------------dominates------------------------------------------ |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1041 // Helper function for MemNode::all_controls_dominate(). |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1042 // Check if 'this' control node dominates or equal to 'sub' control node. |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1043 // We already know that if any path back to Root or Start reaches 'this', |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1044 // then all paths so, so this is a simple search for one example, |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1045 // not an exhaustive search for a counterexample. |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1046 bool Node::dominates(Node* sub, Node_List &nlist) { |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1047 assert(this->is_CFG(), "expecting control"); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1048 assert(sub != NULL && sub->is_CFG(), "expecting control"); |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1049 |
155
723be81c1212
6701887: JDK7 server VM in endless loop in Node::dominates
kvn
parents:
122
diff
changeset
|
1050 // detect dead cycle without regions |
723be81c1212
6701887: JDK7 server VM in endless loop in Node::dominates
kvn
parents:
122
diff
changeset
|
1051 int iterations_without_region_limit = DominatorSearchLimit; |
723be81c1212
6701887: JDK7 server VM in endless loop in Node::dominates
kvn
parents:
122
diff
changeset
|
1052 |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1053 Node* orig_sub = sub; |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1054 Node* dom = this; |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1055 bool met_dom = false; |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1056 nlist.clear(); |
163 | 1057 |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1058 // Walk 'sub' backward up the chain to 'dom', watching for regions. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1059 // After seeing 'dom', continue up to Root or Start. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1060 // If we hit a region (backward split point), it may be a loop head. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1061 // Keep going through one of the region's inputs. If we reach the |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1062 // same region again, go through a different input. Eventually we |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1063 // will either exit through the loop head, or give up. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1064 // (If we get confused, break out and return a conservative 'false'.) |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1065 while (sub != NULL) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1066 if (sub->is_top()) break; // Conservative answer for dead code. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1067 if (sub == dom) { |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1068 if (nlist.size() == 0) { |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1069 // No Region nodes except loops were visited before and the EntryControl |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1070 // path was taken for loops: it did not walk in a cycle. |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1071 return true; |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1072 } else if (met_dom) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1073 break; // already met before: walk in a cycle |
163 | 1074 } else { |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1075 // Region nodes were visited. Continue walk up to Start or Root |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1076 // to make sure that it did not walk in a cycle. |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1077 met_dom = true; // first time meet |
155
723be81c1212
6701887: JDK7 server VM in endless loop in Node::dominates
kvn
parents:
122
diff
changeset
|
1078 iterations_without_region_limit = DominatorSearchLimit; // Reset |
163 | 1079 } |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1080 } |
163 | 1081 if (sub->is_Start() || sub->is_Root()) { |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1082 // Success if we met 'dom' along a path to Start or Root. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1083 // We assume there are no alternative paths that avoid 'dom'. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1084 // (This assumption is up to the caller to ensure!) |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1085 return met_dom; |
163 | 1086 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1087 Node* up = sub->in(0); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1088 // Normalize simple pass-through regions and projections: |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1089 up = sub->find_exact_control(up); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1090 // If sub == up, we found a self-loop. Try to push past it. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1091 if (sub == up && sub->is_Loop()) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1092 // Take loop entry path on the way up to 'dom'. |
163 | 1093 up = sub->in(1); // in(LoopNode::EntryControl); |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1094 } else if (sub == up && sub->is_Region() && sub->req() != 3) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1095 // Always take in(1) path on the way up to 'dom' for clone regions |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1096 // (with only one input) or regions which merge > 2 paths |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1097 // (usually used to merge fast/slow paths). |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1098 up = sub->in(1); |
163 | 1099 } else if (sub == up && sub->is_Region()) { |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1100 // Try both paths for Regions with 2 input paths (it may be a loop head). |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1101 // It could give conservative 'false' answer without information |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1102 // which region's input is the entry path. |
163 | 1103 iterations_without_region_limit = DominatorSearchLimit; // Reset |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1104 |
163 | 1105 bool region_was_visited_before = false; |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1106 // Was this Region node visited before? |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1107 // If so, we have reached it because we accidentally took a |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1108 // loop-back edge from 'sub' back into the body of the loop, |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1109 // and worked our way up again to the loop header 'sub'. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1110 // So, take the first unexplored path on the way up to 'dom'. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1111 for (int j = nlist.size() - 1; j >= 0; j--) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1112 intptr_t ni = (intptr_t)nlist.at(j); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1113 Node* visited = (Node*)(ni & ~1); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1114 bool visited_twice_already = ((ni & 1) != 0); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1115 if (visited == sub) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1116 if (visited_twice_already) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1117 // Visited 2 paths, but still stuck in loop body. Give up. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1118 return false; |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1119 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1120 // The Region node was visited before only once. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1121 // (We will repush with the low bit set, below.) |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1122 nlist.remove(j); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1123 // We will find a new edge and re-insert. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1124 region_was_visited_before = true; |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1125 break; |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1126 } |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1127 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1128 |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1129 // Find an incoming edge which has not been seen yet; walk through it. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1130 assert(up == sub, ""); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1131 uint skip = region_was_visited_before ? 1 : 0; |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1132 for (uint i = 1; i < sub->req(); i++) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1133 Node* in = sub->in(i); |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1134 if (in != NULL && !in->is_top() && in != sub) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1135 if (skip == 0) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1136 up = in; |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1137 break; |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1138 } |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1139 --skip; // skip this nontrivial input |
163 | 1140 } |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1141 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1142 |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1143 // Set 0 bit to indicate that both paths were taken. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1144 nlist.push((Node*)((intptr_t)sub + (region_was_visited_before ? 1 : 0))); |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1145 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1146 |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1147 if (up == sub) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1148 break; // some kind of tight cycle |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1149 } |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1150 if (up == orig_sub && met_dom) { |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1151 // returned back after visiting 'dom' |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1152 break; // some kind of cycle |
163 | 1153 } |
1154 if (--iterations_without_region_limit < 0) { | |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1155 break; // dead cycle |
163 | 1156 } |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1157 sub = up; |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1158 } |
193
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1159 |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1160 // Did not meet Root or Start node in pred. chain. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1161 // Conservative answer for dead code. |
44a553b2809d
6714406: Node::dominates() does not always check for TOP
kvn
parents:
163
diff
changeset
|
1162 return false; |
85
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1163 } |
f3b3fe64f59f
6692301: Side effect in NumberFormat tests with -server -Xcomp
kvn
parents:
65
diff
changeset
|
1164 |
0 | 1165 //------------------------------remove_dead_region----------------------------- |
1166 // This control node is dead. Follow the subgraph below it making everything | |
1167 // using it dead as well. This will happen normally via the usual IterGVN | |
1168 // worklist but this call is more efficient. Do not update use-def info | |
1169 // inside the dead region, just at the borders. | |
305 | 1170 static void kill_dead_code( Node *dead, PhaseIterGVN *igvn ) { |
0 | 1171 // Con's are a popular node to re-hit in the hash table again. |
305 | 1172 if( dead->is_Con() ) return; |
0 | 1173 |
1174 // Can't put ResourceMark here since igvn->_worklist uses the same arena | |
1175 // for verify pass with +VerifyOpto and we add/remove elements in it here. | |
1176 Node_List nstack(Thread::current()->resource_area()); | |
1177 | |
1178 Node *top = igvn->C->top(); | |
1179 nstack.push(dead); | |
1180 | |
1181 while (nstack.size() > 0) { | |
1182 dead = nstack.pop(); | |
1183 if (dead->outcnt() > 0) { | |
1184 // Keep dead node on stack until all uses are processed. | |
1185 nstack.push(dead); | |
1186 // For all Users of the Dead... ;-) | |
1187 for (DUIterator_Last kmin, k = dead->last_outs(kmin); k >= kmin; ) { | |
1188 Node* use = dead->last_out(k); | |
1189 igvn->hash_delete(use); // Yank from hash table prior to mod | |
1190 if (use->in(0) == dead) { // Found another dead node | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
605
diff
changeset
|
1191 assert (!use->is_Con(), "Control for Con node should be Root node."); |
0 | 1192 use->set_req(0, top); // Cut dead edge to prevent processing |
1193 nstack.push(use); // the dead node again. | |
1194 } else { // Else found a not-dead user | |
1195 for (uint j = 1; j < use->req(); j++) { | |
1196 if (use->in(j) == dead) { // Turn all dead inputs into TOP | |
1197 use->set_req(j, top); | |
1198 } | |
1199 } | |
1200 igvn->_worklist.push(use); | |
1201 } | |
1202 // Refresh the iterator, since any number of kills might have happened. | |
1203 k = dead->last_outs(kmin); | |
1204 } | |
1205 } else { // (dead->outcnt() == 0) | |
1206 // Done with outputs. | |
1207 igvn->hash_delete(dead); | |
1208 igvn->_worklist.remove(dead); | |
1209 igvn->set_type(dead, Type::TOP); | |
1210 if (dead->is_macro()) { | |
1211 igvn->C->remove_macro_node(dead); | |
1212 } | |
1213 // Kill all inputs to the dead guy | |
1214 for (uint i=0; i < dead->req(); i++) { | |
1215 Node *n = dead->in(i); // Get input to dead guy | |
1216 if (n != NULL && !n->is_top()) { // Input is valid? | |
1217 dead->set_req(i, top); // Smash input away | |
1218 if (n->outcnt() == 0) { // Input also goes dead? | |
1219 if (!n->is_Con()) | |
1220 nstack.push(n); // Clear it out as well | |
1221 } else if (n->outcnt() == 1 && | |
1222 n->has_special_unique_user()) { | |
1223 igvn->add_users_to_worklist( n ); | |
1224 } else if (n->outcnt() <= 2 && n->is_Store()) { | |
1225 // Push store's uses on worklist to enable folding optimization for | |
1226 // store/store and store/load to the same address. | |
1227 // The restriction (outcnt() <= 2) is the same as in set_req_X() | |
1228 // and remove_globally_dead_node(). | |
1229 igvn->add_users_to_worklist( n ); | |
1230 } | |
1231 } | |
1232 } | |
1233 } // (dead->outcnt() == 0) | |
1234 } // while (nstack.size() > 0) for outputs | |
305 | 1235 return; |
0 | 1236 } |
1237 | |
1238 //------------------------------remove_dead_region----------------------------- | |
1239 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) { | |
1240 Node *n = in(0); | |
1241 if( !n ) return false; | |
1242 // Lost control into this guy? I.e., it became unreachable? | |
1243 // Aggressively kill all unreachable code. | |
1244 if (can_reshape && n->is_top()) { | |
305 | 1245 kill_dead_code(this, phase->is_IterGVN()); |
1246 return false; // Node is dead. | |
0 | 1247 } |
1248 | |
1249 if( n->is_Region() && n->as_Region()->is_copy() ) { | |
1250 Node *m = n->nonnull_req(); | |
1251 set_req(0, m); | |
1252 return true; | |
1253 } | |
1254 return false; | |
1255 } | |
1256 | |
1257 //------------------------------Ideal_DU_postCCP------------------------------- | |
1258 // Idealize graph, using DU info. Must clone result into new-space | |
1259 Node *Node::Ideal_DU_postCCP( PhaseCCP * ) { | |
1260 return NULL; // Default to no change | |
1261 } | |
1262 | |
1263 //------------------------------hash------------------------------------------- | |
1264 // Hash function over Nodes. | |
1265 uint Node::hash() const { | |
1266 uint sum = 0; | |
1267 for( uint i=0; i<_cnt; i++ ) // Add in all inputs | |
1268 sum = (sum<<1)-(uintptr_t)in(i); // Ignore embedded NULLs | |
1269 return (sum>>2) + _cnt + Opcode(); | |
1270 } | |
1271 | |
1272 //------------------------------cmp-------------------------------------------- | |
1273 // Compare special parts of simple Nodes | |
1274 uint Node::cmp( const Node &n ) const { | |
1275 return 1; // Must be same | |
1276 } | |
1277 | |
1278 //------------------------------rematerialize----------------------------------- | |
1279 // Should we clone rather than spill this instruction? | |
1280 bool Node::rematerialize() const { | |
1281 if ( is_Mach() ) | |
1282 return this->as_Mach()->rematerialize(); | |
1283 else | |
1284 return (_flags & Flag_rematerialize) != 0; | |
1285 } | |
1286 | |
1287 //------------------------------needs_anti_dependence_check--------------------- | |
1288 // Nodes which use memory without consuming it, hence need antidependences. | |
1289 bool Node::needs_anti_dependence_check() const { | |
1290 if( req() < 2 || (_flags & Flag_needs_anti_dependence_check) == 0 ) | |
1291 return false; | |
1292 else | |
1293 return in(1)->bottom_type()->has_memory(); | |
1294 } | |
1295 | |
1296 | |
1297 // Get an integer constant from a ConNode (or CastIINode). | |
1298 // Return a default value if there is no apparent constant here. | |
1299 const TypeInt* Node::find_int_type() const { | |
1300 if (this->is_Type()) { | |
1301 return this->as_Type()->type()->isa_int(); | |
1302 } else if (this->is_Con()) { | |
1303 assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode"); | |
1304 return this->bottom_type()->isa_int(); | |
1305 } | |
1306 return NULL; | |
1307 } | |
1308 | |
1309 // Get a pointer constant from a ConstNode. | |
1310 // Returns the constant if it is a pointer ConstNode | |
1311 intptr_t Node::get_ptr() const { | |
1312 assert( Opcode() == Op_ConP, "" ); | |
1313 return ((ConPNode*)this)->type()->is_ptr()->get_con(); | |
1314 } | |
1315 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1316 // Get a narrow oop constant from a ConNNode. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1317 intptr_t Node::get_narrowcon() const { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1318 assert( Opcode() == Op_ConN, "" ); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1319 return ((ConNNode*)this)->type()->is_narrowoop()->get_con(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1320 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
65
diff
changeset
|
1321 |
0 | 1322 // Get a long constant from a ConNode. |
1323 // Return a default value if there is no apparent constant here. | |
1324 const TypeLong* Node::find_long_type() const { | |
1325 if (this->is_Type()) { | |
1326 return this->as_Type()->type()->isa_long(); | |
1327 } else if (this->is_Con()) { | |
1328 assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode"); | |
1329 return this->bottom_type()->isa_long(); | |
1330 } | |
1331 return NULL; | |
1332 } | |
1333 | |
1334 // Get a double constant from a ConstNode. | |
1335 // Returns the constant if it is a double ConstNode | |
1336 jdouble Node::getd() const { | |
1337 assert( Opcode() == Op_ConD, "" ); | |
1338 return ((ConDNode*)this)->type()->is_double_constant()->getd(); | |
1339 } | |
1340 | |
1341 // Get a float constant from a ConstNode. | |
1342 // Returns the constant if it is a float ConstNode | |
1343 jfloat Node::getf() const { | |
1344 assert( Opcode() == Op_ConF, "" ); | |
1345 return ((ConFNode*)this)->type()->is_float_constant()->getf(); | |
1346 } | |
1347 | |
1348 #ifndef PRODUCT | |
1349 | |
1350 //----------------------------NotANode---------------------------------------- | |
1351 // Used in debugging code to avoid walking across dead or uninitialized edges. | |
1352 static inline bool NotANode(const Node* n) { | |
1353 if (n == NULL) return true; | |
1354 if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc. | |
1355 if (*(address*)n == badAddress) return true; // kill by Node::destruct | |
1356 return false; | |
1357 } | |
1358 | |
1359 | |
1360 //------------------------------find------------------------------------------ | |
1361 // Find a neighbor of this Node with the given _idx | |
1362 // If idx is negative, find its absolute value, following both _in and _out. | |
1363 static void find_recur( Node* &result, Node *n, int idx, bool only_ctrl, | |
1364 VectorSet &old_space, VectorSet &new_space ) { | |
1365 int node_idx = (idx >= 0) ? idx : -idx; | |
1366 if (NotANode(n)) return; // Gracefully handle NULL, -1, 0xabababab, etc. | |
1367 // Contained in new_space or old_space? | |
1368 VectorSet *v = Compile::current()->node_arena()->contains(n) ? &new_space : &old_space; | |
1369 if( v->test(n->_idx) ) return; | |
1370 if( (int)n->_idx == node_idx | |
1371 debug_only(|| n->debug_idx() == node_idx) ) { | |
1372 if (result != NULL) | |
1373 tty->print("find: " INTPTR_FORMAT " and " INTPTR_FORMAT " both have idx==%d\n", | |
1374 (uintptr_t)result, (uintptr_t)n, node_idx); | |
1375 result = n; | |
1376 } | |
1377 v->set(n->_idx); | |
1378 for( uint i=0; i<n->len(); i++ ) { | |
1379 if( only_ctrl && !(n->is_Region()) && (n->Opcode() != Op_Root) && (i != TypeFunc::Control) ) continue; | |
1380 find_recur( result, n->in(i), idx, only_ctrl, old_space, new_space ); | |
1381 } | |
1382 // Search along forward edges also: | |
1383 if (idx < 0 && !only_ctrl) { | |
1384 for( uint j=0; j<n->outcnt(); j++ ) { | |
1385 find_recur( result, n->raw_out(j), idx, only_ctrl, old_space, new_space ); | |
1386 } | |
1387 } | |
1388 #ifdef ASSERT | |
1389 // Search along debug_orig edges last: | |
222 | 1390 for (Node* orig = n->debug_orig(); orig != NULL && n != orig; orig = orig->debug_orig()) { |
0 | 1391 if (NotANode(orig)) break; |
1392 find_recur( result, orig, idx, only_ctrl, old_space, new_space ); | |
1393 } | |
1394 #endif //ASSERT | |
1395 } | |
1396 | |
1397 // call this from debugger: | |
1398 Node* find_node(Node* n, int idx) { | |
1399 return n->find(idx); | |
1400 } | |
1401 | |
1402 //------------------------------find------------------------------------------- | |
1403 Node* Node::find(int idx) const { | |
1404 ResourceArea *area = Thread::current()->resource_area(); | |
1405 VectorSet old_space(area), new_space(area); | |
1406 Node* result = NULL; | |
1407 find_recur( result, (Node*) this, idx, false, old_space, new_space ); | |
1408 return result; | |
1409 } | |
1410 | |
1411 //------------------------------find_ctrl-------------------------------------- | |
1412 // Find an ancestor to this node in the control history with given _idx | |
1413 Node* Node::find_ctrl(int idx) const { | |
1414 ResourceArea *area = Thread::current()->resource_area(); | |
1415 VectorSet old_space(area), new_space(area); | |
1416 Node* result = NULL; | |
1417 find_recur( result, (Node*) this, idx, true, old_space, new_space ); | |
1418 return result; | |
1419 } | |
1420 #endif | |
1421 | |
1422 | |
1423 | |
1424 #ifndef PRODUCT | |
1425 int Node::_in_dump_cnt = 0; | |
1426 | |
1427 // -----------------------------Name------------------------------------------- | |
1428 extern const char *NodeClassNames[]; | |
1429 const char *Node::Name() const { return NodeClassNames[Opcode()]; } | |
1430 | |
1431 static bool is_disconnected(const Node* n) { | |
1432 for (uint i = 0; i < n->req(); i++) { | |
1433 if (n->in(i) != NULL) return false; | |
1434 } | |
1435 return true; | |
1436 } | |
1437 | |
1438 #ifdef ASSERT | |
1439 static void dump_orig(Node* orig) { | |
1440 Compile* C = Compile::current(); | |
1441 if (NotANode(orig)) orig = NULL; | |
1442 if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL; | |
1443 if (orig == NULL) return; | |
1444 tty->print(" !orig="); | |
1445 Node* fast = orig->debug_orig(); // tortoise & hare algorithm to detect loops | |
1446 if (NotANode(fast)) fast = NULL; | |
1447 while (orig != NULL) { | |
1448 bool discon = is_disconnected(orig); // if discon, print [123] else 123 | |
1449 if (discon) tty->print("["); | |
1450 if (!Compile::current()->node_arena()->contains(orig)) | |
1451 tty->print("o"); | |
1452 tty->print("%d", orig->_idx); | |
1453 if (discon) tty->print("]"); | |
1454 orig = orig->debug_orig(); | |
1455 if (NotANode(orig)) orig = NULL; | |
1456 if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL; | |
1457 if (orig != NULL) tty->print(","); | |
1458 if (fast != NULL) { | |
1459 // Step fast twice for each single step of orig: | |
1460 fast = fast->debug_orig(); | |
1461 if (NotANode(fast)) fast = NULL; | |
1462 if (fast != NULL && fast != orig) { | |
1463 fast = fast->debug_orig(); | |
1464 if (NotANode(fast)) fast = NULL; | |
1465 } | |
1466 if (fast == orig) { | |
1467 tty->print("..."); | |
1468 break; | |
1469 } | |
1470 } | |
1471 } | |
1472 } | |
1473 | |
1474 void Node::set_debug_orig(Node* orig) { | |
1475 _debug_orig = orig; | |
1476 if (BreakAtNode == 0) return; | |
1477 if (NotANode(orig)) orig = NULL; | |
1478 int trip = 10; | |
1479 while (orig != NULL) { | |
1480 if (orig->debug_idx() == BreakAtNode || (int)orig->_idx == BreakAtNode) { | |
1481 tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d orig._idx=%d orig._debug_idx=%d", | |
1482 this->_idx, this->debug_idx(), orig->_idx, orig->debug_idx()); | |
1483 BREAKPOINT; | |
1484 } | |
1485 orig = orig->debug_orig(); | |
1486 if (NotANode(orig)) orig = NULL; | |
1487 if (trip-- <= 0) break; | |
1488 } | |
1489 } | |
1490 #endif //ASSERT | |
1491 | |
1492 //------------------------------dump------------------------------------------ | |
1493 // Dump a Node | |
1494 void Node::dump() const { | |
1495 Compile* C = Compile::current(); | |
1496 bool is_new = C->node_arena()->contains(this); | |
1497 _in_dump_cnt++; | |
1498 tty->print("%c%d\t%s\t=== ", | |
1499 is_new ? ' ' : 'o', _idx, Name()); | |
1500 | |
1501 // Dump the required and precedence inputs | |
1502 dump_req(); | |
1503 dump_prec(); | |
1504 // Dump the outputs | |
1505 dump_out(); | |
1506 | |
1507 if (is_disconnected(this)) { | |
1508 #ifdef ASSERT | |
1509 tty->print(" [%d]",debug_idx()); | |
1510 dump_orig(debug_orig()); | |
1511 #endif | |
1512 tty->cr(); | |
1513 _in_dump_cnt--; | |
1514 return; // don't process dead nodes | |
1515 } | |
1516 | |
1517 // Dump node-specific info | |
1518 dump_spec(tty); | |
1519 #ifdef ASSERT | |
1520 // Dump the non-reset _debug_idx | |
1521 if( Verbose && WizardMode ) { | |
1522 tty->print(" [%d]",debug_idx()); | |
1523 } | |
1524 #endif | |
1525 | |
1526 const Type *t = bottom_type(); | |
1527 | |
1528 if (t != NULL && (t->isa_instptr() || t->isa_klassptr())) { | |
1529 const TypeInstPtr *toop = t->isa_instptr(); | |
1530 const TypeKlassPtr *tkls = t->isa_klassptr(); | |
1531 ciKlass* klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL ); | |
1532 if( klass && klass->is_loaded() && klass->is_interface() ) { | |
1533 tty->print(" Interface:"); | |
1534 } else if( toop ) { | |
1535 tty->print(" Oop:"); | |
1536 } else if( tkls ) { | |
1537 tty->print(" Klass:"); | |
1538 } | |
1539 t->dump(); | |
1540 } else if( t == Type::MEMORY ) { | |
1541 tty->print(" Memory:"); | |
1542 MemNode::dump_adr_type(this, adr_type(), tty); | |
1543 } else if( Verbose || WizardMode ) { | |
1544 tty->print(" Type:"); | |
1545 if( t ) { | |
1546 t->dump(); | |
1547 } else { | |
1548 tty->print("no type"); | |
1549 } | |
1550 } | |
1551 if (is_new) { | |
1552 debug_only(dump_orig(debug_orig())); | |
1553 Node_Notes* nn = C->node_notes_at(_idx); | |
1554 if (nn != NULL && !nn->is_clear()) { | |
1555 if (nn->jvms() != NULL) { | |
1556 tty->print(" !jvms:"); | |
1557 nn->jvms()->dump_spec(tty); | |
1558 } | |
1559 } | |
1560 } | |
1561 tty->cr(); | |
1562 _in_dump_cnt--; | |
1563 } | |
1564 | |
1565 //------------------------------dump_req-------------------------------------- | |
1566 void Node::dump_req() const { | |
1567 // Dump the required input edges | |
1568 for (uint i = 0; i < req(); i++) { // For all required inputs | |
1569 Node* d = in(i); | |
1570 if (d == NULL) { | |
1571 tty->print("_ "); | |
1572 } else if (NotANode(d)) { | |
1573 tty->print("NotANode "); // uninitialized, sentinel, garbage, etc. | |
1574 } else { | |
1575 tty->print("%c%d ", Compile::current()->node_arena()->contains(d) ? ' ' : 'o', d->_idx); | |
1576 } | |
1577 } | |
1578 } | |
1579 | |
1580 | |
1581 //------------------------------dump_prec------------------------------------- | |
1582 void Node::dump_prec() const { | |
1583 // Dump the precedence edges | |
1584 int any_prec = 0; | |
1585 for (uint i = req(); i < len(); i++) { // For all precedence inputs | |
1586 Node* p = in(i); | |
1587 if (p != NULL) { | |
1588 if( !any_prec++ ) tty->print(" |"); | |
1589 if (NotANode(p)) { tty->print("NotANode "); continue; } | |
1590 tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx); | |
1591 } | |
1592 } | |
1593 } | |
1594 | |
1595 //------------------------------dump_out-------------------------------------- | |
1596 void Node::dump_out() const { | |
1597 // Delimit the output edges | |
1598 tty->print(" [["); | |
1599 // Dump the output edges | |
1600 for (uint i = 0; i < _outcnt; i++) { // For all outputs | |
1601 Node* u = _out[i]; | |
1602 if (u == NULL) { | |
1603 tty->print("_ "); | |
1604 } else if (NotANode(u)) { | |
1605 tty->print("NotANode "); | |
1606 } else { | |
1607 tty->print("%c%d ", Compile::current()->node_arena()->contains(u) ? ' ' : 'o', u->_idx); | |
1608 } | |
1609 } | |
1610 tty->print("]] "); | |
1611 } | |
1612 | |
1613 //------------------------------dump_nodes------------------------------------- | |
1614 static void dump_nodes(const Node* start, int d, bool only_ctrl) { | |
1615 Node* s = (Node*)start; // remove const | |
1616 if (NotANode(s)) return; | |
1617 | |
24
953939ef62ab
6614330: Node::dump(n) does not print full graph for specified depth.
kvn
parents:
0
diff
changeset
|
1618 uint depth = (uint)ABS(d); |
953939ef62ab
6614330: Node::dump(n) does not print full graph for specified depth.
kvn
parents:
0
diff
changeset
|
1619 int direction = d; |
0 | 1620 Compile* C = Compile::current(); |
40 | 1621 GrowableArray <Node *> nstack(C->unique()); |
0 | 1622 |
40 | 1623 nstack.append(s); |
1624 int begin = 0; | |
1625 int end = 0; | |
1626 for(uint i = 0; i < depth; i++) { | |
1627 end = nstack.length(); | |
1628 for(int j = begin; j < end; j++) { | |
1629 Node* tp = nstack.at(j); | |
1630 uint limit = direction > 0 ? tp->len() : tp->outcnt(); | |
1631 for(uint k = 0; k < limit; k++) { | |
1632 Node* n = direction > 0 ? tp->in(k) : tp->raw_out(k); | |
0 | 1633 |
40 | 1634 if (NotANode(n)) continue; |
1635 // do not recurse through top or the root (would reach unrelated stuff) | |
1636 if (n->is_Root() || n->is_top()) continue; | |
1637 if (only_ctrl && !n->is_CFG()) continue; | |
0 | 1638 |
40 | 1639 bool on_stack = nstack.contains(n); |
1640 if (!on_stack) { | |
1641 nstack.append(n); | |
0 | 1642 } |
1643 } | |
1644 } | |
40 | 1645 begin = end; |
1646 } | |
1647 end = nstack.length(); | |
1648 if (direction > 0) { | |
1649 for(int j = end-1; j >= 0; j--) { | |
1650 nstack.at(j)->dump(); | |
1651 } | |
1652 } else { | |
1653 for(int j = 0; j < end; j++) { | |
1654 nstack.at(j)->dump(); | |
1655 } | |
0 | 1656 } |
1657 } | |
1658 | |
1659 //------------------------------dump------------------------------------------- | |
1660 void Node::dump(int d) const { | |
1661 dump_nodes(this, d, false); | |
1662 } | |
1663 | |
1664 //------------------------------dump_ctrl-------------------------------------- | |
1665 // Dump a Node's control history to depth | |
1666 void Node::dump_ctrl(int d) const { | |
1667 dump_nodes(this, d, true); | |
1668 } | |
1669 | |
1670 // VERIFICATION CODE | |
1671 // For each input edge to a node (ie - for each Use-Def edge), verify that | |
1672 // there is a corresponding Def-Use edge. | |
1673 //------------------------------verify_edges----------------------------------- | |
1674 void Node::verify_edges(Unique_Node_List &visited) { | |
1675 uint i, j, idx; | |
1676 int cnt; | |
1677 Node *n; | |
1678 | |
1679 // Recursive termination test | |
1680 if (visited.member(this)) return; | |
1681 visited.push(this); | |
1682 | |
605 | 1683 // Walk over all input edges, checking for correspondence |
0 | 1684 for( i = 0; i < len(); i++ ) { |
1685 n = in(i); | |
1686 if (n != NULL && !n->is_top()) { | |
1687 // Count instances of (Node *)this | |
1688 cnt = 0; | |
1689 for (idx = 0; idx < n->_outcnt; idx++ ) { | |
1690 if (n->_out[idx] == (Node *)this) cnt++; | |
1691 } | |
1692 assert( cnt > 0,"Failed to find Def-Use edge." ); | |
1693 // Check for duplicate edges | |
1694 // walk the input array downcounting the input edges to n | |
1695 for( j = 0; j < len(); j++ ) { | |
1696 if( in(j) == n ) cnt--; | |
1697 } | |
1698 assert( cnt == 0,"Mismatched edge count."); | |
1699 } else if (n == NULL) { | |
1700 assert(i >= req() || i == 0 || is_Region() || is_Phi(), "only regions or phis have null data edges"); | |
1701 } else { | |
1702 assert(n->is_top(), "sanity"); | |
1703 // Nothing to check. | |
1704 } | |
1705 } | |
1706 // Recursive walk over all input edges | |
1707 for( i = 0; i < len(); i++ ) { | |
1708 n = in(i); | |
1709 if( n != NULL ) | |
1710 in(i)->verify_edges(visited); | |
1711 } | |
1712 } | |
1713 | |
1714 //------------------------------verify_recur----------------------------------- | |
1715 static const Node *unique_top = NULL; | |
1716 | |
1717 void Node::verify_recur(const Node *n, int verify_depth, | |
1718 VectorSet &old_space, VectorSet &new_space) { | |
1719 if ( verify_depth == 0 ) return; | |
1720 if (verify_depth > 0) --verify_depth; | |
1721 | |
1722 Compile* C = Compile::current(); | |
1723 | |
1724 // Contained in new_space or old_space? | |
1725 VectorSet *v = C->node_arena()->contains(n) ? &new_space : &old_space; | |
1726 // Check for visited in the proper space. Numberings are not unique | |
605 | 1727 // across spaces so we need a separate VectorSet for each space. |
0 | 1728 if( v->test_set(n->_idx) ) return; |
1729 | |
1730 if (n->is_Con() && n->bottom_type() == Type::TOP) { | |
1731 if (C->cached_top_node() == NULL) | |
1732 C->set_cached_top_node((Node*)n); | |
1733 assert(C->cached_top_node() == n, "TOP node must be unique"); | |
1734 } | |
1735 | |
1736 for( uint i = 0; i < n->len(); i++ ) { | |
1737 Node *x = n->in(i); | |
1738 if (!x || x->is_top()) continue; | |
1739 | |
1740 // Verify my input has a def-use edge to me | |
1741 if (true /*VerifyDefUse*/) { | |
1742 // Count use-def edges from n to x | |
1743 int cnt = 0; | |
1744 for( uint j = 0; j < n->len(); j++ ) | |
1745 if( n->in(j) == x ) | |
1746 cnt++; | |
1747 // Count def-use edges from x to n | |
1748 uint max = x->_outcnt; | |
1749 for( uint k = 0; k < max; k++ ) | |
1750 if (x->_out[k] == n) | |
1751 cnt--; | |
1752 assert( cnt == 0, "mismatched def-use edge counts" ); | |
1753 } | |
1754 | |
1755 verify_recur(x, verify_depth, old_space, new_space); | |
1756 } | |
1757 | |
1758 } | |
1759 | |
1760 //------------------------------verify----------------------------------------- | |
1761 // Check Def-Use info for my subgraph | |
1762 void Node::verify() const { | |
1763 Compile* C = Compile::current(); | |
1764 Node* old_top = C->cached_top_node(); | |
1765 ResourceMark rm; | |
1766 ResourceArea *area = Thread::current()->resource_area(); | |
1767 VectorSet old_space(area), new_space(area); | |
1768 verify_recur(this, -1, old_space, new_space); | |
1769 C->set_cached_top_node(old_top); | |
1770 } | |
1771 #endif | |
1772 | |
1773 | |
1774 //------------------------------walk------------------------------------------- | |
1775 // Graph walk, with both pre-order and post-order functions | |
1776 void Node::walk(NFunc pre, NFunc post, void *env) { | |
1777 VectorSet visited(Thread::current()->resource_area()); // Setup for local walk | |
1778 walk_(pre, post, env, visited); | |
1779 } | |
1780 | |
1781 void Node::walk_(NFunc pre, NFunc post, void *env, VectorSet &visited) { | |
1782 if( visited.test_set(_idx) ) return; | |
1783 pre(*this,env); // Call the pre-order walk function | |
1784 for( uint i=0; i<_max; i++ ) | |
1785 if( in(i) ) // Input exists and is not walked? | |
1786 in(i)->walk_(pre,post,env,visited); // Walk it with pre & post functions | |
1787 post(*this,env); // Call the post-order walk function | |
1788 } | |
1789 | |
1790 void Node::nop(Node &, void*) {} | |
1791 | |
1792 //------------------------------Registers-------------------------------------- | |
1793 // Do we Match on this edge index or not? Generally false for Control | |
1794 // and true for everything else. Weird for calls & returns. | |
1795 uint Node::match_edge(uint idx) const { | |
1796 return idx; // True for other than index 0 (control) | |
1797 } | |
1798 | |
1799 // Register classes are defined for specific machines | |
1800 const RegMask &Node::out_RegMask() const { | |
1801 ShouldNotCallThis(); | |
1802 return *(new RegMask()); | |
1803 } | |
1804 | |
1805 const RegMask &Node::in_RegMask(uint) const { | |
1806 ShouldNotCallThis(); | |
1807 return *(new RegMask()); | |
1808 } | |
1809 | |
1810 //============================================================================= | |
1811 //----------------------------------------------------------------------------- | |
1812 void Node_Array::reset( Arena *new_arena ) { | |
1813 _a->Afree(_nodes,_max*sizeof(Node*)); | |
1814 _max = 0; | |
1815 _nodes = NULL; | |
1816 _a = new_arena; | |
1817 } | |
1818 | |
1819 //------------------------------clear------------------------------------------ | |
1820 // Clear all entries in _nodes to NULL but keep storage | |
1821 void Node_Array::clear() { | |
1822 Copy::zero_to_bytes( _nodes, _max*sizeof(Node*) ); | |
1823 } | |
1824 | |
1825 //----------------------------------------------------------------------------- | |
1826 void Node_Array::grow( uint i ) { | |
1827 if( !_max ) { | |
1828 _max = 1; | |
1829 _nodes = (Node**)_a->Amalloc( _max * sizeof(Node*) ); | |
1830 _nodes[0] = NULL; | |
1831 } | |
1832 uint old = _max; | |
1833 while( i >= _max ) _max <<= 1; // Double to fit | |
1834 _nodes = (Node**)_a->Arealloc( _nodes, old*sizeof(Node*),_max*sizeof(Node*)); | |
1835 Copy::zero_to_bytes( &_nodes[old], (_max-old)*sizeof(Node*) ); | |
1836 } | |
1837 | |
1838 //----------------------------------------------------------------------------- | |
1839 void Node_Array::insert( uint i, Node *n ) { | |
1840 if( _nodes[_max-1] ) grow(_max); // Get more space if full | |
1841 Copy::conjoint_words_to_higher((HeapWord*)&_nodes[i], (HeapWord*)&_nodes[i+1], ((_max-i-1)*sizeof(Node*))); | |
1842 _nodes[i] = n; | |
1843 } | |
1844 | |
1845 //----------------------------------------------------------------------------- | |
1846 void Node_Array::remove( uint i ) { | |
1847 Copy::conjoint_words_to_lower((HeapWord*)&_nodes[i+1], (HeapWord*)&_nodes[i], ((_max-i-1)*sizeof(Node*))); | |
1848 _nodes[_max-1] = NULL; | |
1849 } | |
1850 | |
1851 //----------------------------------------------------------------------------- | |
1852 void Node_Array::sort( C_sort_func_t func) { | |
1853 qsort( _nodes, _max, sizeof( Node* ), func ); | |
1854 } | |
1855 | |
1856 //----------------------------------------------------------------------------- | |
1857 void Node_Array::dump() const { | |
1858 #ifndef PRODUCT | |
1859 for( uint i = 0; i < _max; i++ ) { | |
1860 Node *nn = _nodes[i]; | |
1861 if( nn != NULL ) { | |
1862 tty->print("%5d--> ",i); nn->dump(); | |
1863 } | |
1864 } | |
1865 #endif | |
1866 } | |
1867 | |
1868 //--------------------------is_iteratively_computed------------------------------ | |
1869 // Operation appears to be iteratively computed (such as an induction variable) | |
1870 // It is possible for this operation to return false for a loop-varying | |
1871 // value, if it appears (by local graph inspection) to be computed by a simple conditional. | |
1872 bool Node::is_iteratively_computed() { | |
1873 if (ideal_reg()) { // does operation have a result register? | |
1874 for (uint i = 1; i < req(); i++) { | |
1875 Node* n = in(i); | |
1876 if (n != NULL && n->is_Phi()) { | |
1877 for (uint j = 1; j < n->req(); j++) { | |
1878 if (n->in(j) == this) { | |
1879 return true; | |
1880 } | |
1881 } | |
1882 } | |
1883 } | |
1884 } | |
1885 return false; | |
1886 } | |
1887 | |
1888 //--------------------------find_similar------------------------------ | |
1889 // Return a node with opcode "opc" and same inputs as "this" if one can | |
1890 // be found; Otherwise return NULL; | |
1891 Node* Node::find_similar(int opc) { | |
1892 if (req() >= 2) { | |
1893 Node* def = in(1); | |
1894 if (def && def->outcnt() >= 2) { | |
1895 for (DUIterator_Fast dmax, i = def->fast_outs(dmax); i < dmax; i++) { | |
1896 Node* use = def->fast_out(i); | |
1897 if (use->Opcode() == opc && | |
1898 use->req() == req()) { | |
1899 uint j; | |
1900 for (j = 0; j < use->req(); j++) { | |
1901 if (use->in(j) != in(j)) { | |
1902 break; | |
1903 } | |
1904 } | |
1905 if (j == use->req()) { | |
1906 return use; | |
1907 } | |
1908 } | |
1909 } | |
1910 } | |
1911 } | |
1912 return NULL; | |
1913 } | |
1914 | |
1915 | |
1916 //--------------------------unique_ctrl_out------------------------------ | |
1917 // Return the unique control out if only one. Null if none or more than one. | |
1918 Node* Node::unique_ctrl_out() { | |
1919 Node* found = NULL; | |
1920 for (uint i = 0; i < outcnt(); i++) { | |
1921 Node* use = raw_out(i); | |
1922 if (use->is_CFG() && use != this) { | |
1923 if (found != NULL) return NULL; | |
1924 found = use; | |
1925 } | |
1926 } | |
1927 return found; | |
1928 } | |
1929 | |
1930 //============================================================================= | |
1931 //------------------------------yank------------------------------------------- | |
1932 // Find and remove | |
1933 void Node_List::yank( Node *n ) { | |
1934 uint i; | |
1935 for( i = 0; i < _cnt; i++ ) | |
1936 if( _nodes[i] == n ) | |
1937 break; | |
1938 | |
1939 if( i < _cnt ) | |
1940 _nodes[i] = _nodes[--_cnt]; | |
1941 } | |
1942 | |
1943 //------------------------------dump------------------------------------------- | |
1944 void Node_List::dump() const { | |
1945 #ifndef PRODUCT | |
1946 for( uint i = 0; i < _cnt; i++ ) | |
1947 if( _nodes[i] ) { | |
1948 tty->print("%5d--> ",i); | |
1949 _nodes[i]->dump(); | |
1950 } | |
1951 #endif | |
1952 } | |
1953 | |
1954 //============================================================================= | |
1955 //------------------------------remove----------------------------------------- | |
1956 void Unique_Node_List::remove( Node *n ) { | |
1957 if( _in_worklist[n->_idx] ) { | |
1958 for( uint i = 0; i < size(); i++ ) | |
1959 if( _nodes[i] == n ) { | |
1960 map(i,Node_List::pop()); | |
1961 _in_worklist >>= n->_idx; | |
1962 return; | |
1963 } | |
1964 ShouldNotReachHere(); | |
1965 } | |
1966 } | |
1967 | |
1968 //-----------------------remove_useless_nodes---------------------------------- | |
1969 // Remove useless nodes from worklist | |
1970 void Unique_Node_List::remove_useless_nodes(VectorSet &useful) { | |
1971 | |
1972 for( uint i = 0; i < size(); ++i ) { | |
1973 Node *n = at(i); | |
1974 assert( n != NULL, "Did not expect null entries in worklist"); | |
1975 if( ! useful.test(n->_idx) ) { | |
1976 _in_worklist >>= n->_idx; | |
1977 map(i,Node_List::pop()); | |
1978 // Node *replacement = Node_List::pop(); | |
1979 // if( i != size() ) { // Check if removing last entry | |
1980 // _nodes[i] = replacement; | |
1981 // } | |
1982 --i; // Visit popped node | |
1983 // If it was last entry, loop terminates since size() was also reduced | |
1984 } | |
1985 } | |
1986 } | |
1987 | |
1988 //============================================================================= | |
1989 void Node_Stack::grow() { | |
1990 size_t old_top = pointer_delta(_inode_top,_inodes,sizeof(INode)); // save _top | |
1991 size_t old_max = pointer_delta(_inode_max,_inodes,sizeof(INode)); | |
1992 size_t max = old_max << 1; // max * 2 | |
1993 _inodes = REALLOC_ARENA_ARRAY(_a, INode, _inodes, old_max, max); | |
1994 _inode_max = _inodes + max; | |
1995 _inode_top = _inodes + old_top; // restore _top | |
1996 } | |
1997 | |
1998 //============================================================================= | |
1999 uint TypeNode::size_of() const { return sizeof(*this); } | |
2000 #ifndef PRODUCT | |
2001 void TypeNode::dump_spec(outputStream *st) const { | |
2002 if( !Verbose && !WizardMode ) { | |
2003 // standard dump does this in Verbose and WizardMode | |
2004 st->print(" #"); _type->dump_on(st); | |
2005 } | |
2006 } | |
2007 #endif | |
2008 uint TypeNode::hash() const { | |
2009 return Node::hash() + _type->hash(); | |
2010 } | |
2011 uint TypeNode::cmp( const Node &n ) const | |
2012 { return !Type::cmp( _type, ((TypeNode&)n)._type ); } | |
2013 const Type *TypeNode::bottom_type() const { return _type; } | |
2014 const Type *TypeNode::Value( PhaseTransform * ) const { return _type; } | |
2015 | |
2016 //------------------------------ideal_reg-------------------------------------- | |
2017 uint TypeNode::ideal_reg() const { | |
2018 return Matcher::base2reg[_type->base()]; | |
2019 } |