src/share/vm/opto/node.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8504
a96cf90239c6
parent 7535
7ae4e26cb1e0
child 9852
70aa912cebe5
permissions
-rw-r--r--

Merge

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

mercurial