1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "memory/allocation.inline.hpp" 27 #include "opto/block.hpp" 28 #include "opto/callnode.hpp" 29 #include "opto/cfgnode.hpp" 30 #include "opto/idealGraphPrinter.hpp" 31 #include "opto/loopnode.hpp" 32 #include "opto/machnode.hpp" 33 #include "opto/opcodes.hpp" 34 #include "opto/phaseX.hpp" 35 #include "opto/regalloc.hpp" 36 #include "opto/rootnode.hpp" 37 38 //============================================================================= 39 #define NODE_HASH_MINIMUM_SIZE 255 40 //------------------------------NodeHash--------------------------------------- 41 NodeHash::NodeHash(uint est_max_size) : 42 _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), 43 _a(Thread::current()->resource_area()), 44 _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), // (Node**)_a->Amalloc(_max * sizeof(Node*)) ), 45 _inserts(0), _insert_limit( insert_limit() ), 46 _look_probes(0), _lookup_hits(0), _lookup_misses(0), 47 _total_insert_probes(0), _total_inserts(0), 48 _insert_probes(0), _grows(0) { 49 // _sentinel must be in the current node space 50 _sentinel = new ProjNode(NULL, TypeFunc::Control); 51 memset(_table,0,sizeof(Node*)*_max); 52 } 53 54 //------------------------------NodeHash--------------------------------------- 55 NodeHash::NodeHash(Arena *arena, uint est_max_size) : 56 _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), 57 _a(arena), 58 _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), 59 _inserts(0), _insert_limit( insert_limit() ), 60 _look_probes(0), _lookup_hits(0), _lookup_misses(0), 61 _delete_probes(0), _delete_hits(0), _delete_misses(0), 62 _total_insert_probes(0), _total_inserts(0), 63 _insert_probes(0), _grows(0) { 64 // _sentinel must be in the current node space 65 _sentinel = new ProjNode(NULL, TypeFunc::Control); 66 memset(_table,0,sizeof(Node*)*_max); 67 } 68 69 //------------------------------NodeHash--------------------------------------- 70 NodeHash::NodeHash(NodeHash *nh) { 71 debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= 72 // just copy in all the fields 73 *this = *nh; 74 // nh->_sentinel must be in the current node space 75 } 76 77 void NodeHash::replace_with(NodeHash *nh) { 78 debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= 79 // just copy in all the fields 80 *this = *nh; 81 // nh->_sentinel must be in the current node space 82 } 83 84 //------------------------------hash_find-------------------------------------- 85 // Find in hash table 86 Node *NodeHash::hash_find( const Node *n ) { 87 // ((Node*)n)->set_hash( n->hash() ); 88 uint hash = n->hash(); 89 if (hash == Node::NO_HASH) { 90 debug_only( _lookup_misses++ ); 91 return NULL; 92 } 93 uint key = hash & (_max-1); 94 uint stride = key | 0x01; 95 debug_only( _look_probes++ ); 96 Node *k = _table[key]; // Get hashed value 97 if( !k ) { // ?Miss? 98 debug_only( _lookup_misses++ ); 99 return NULL; // Miss! 100 } 101 102 int op = n->Opcode(); 103 uint req = n->req(); 104 while( 1 ) { // While probing hash table 105 if( k->req() == req && // Same count of inputs 106 k->Opcode() == op ) { // Same Opcode 107 for( uint i=0; i<req; i++ ) 108 if( n->in(i)!=k->in(i)) // Different inputs? 109 goto collision; // "goto" is a speed hack... 110 if( n->cmp(*k) ) { // Check for any special bits 111 debug_only( _lookup_hits++ ); 112 return k; // Hit! 113 } 114 } 115 collision: 116 debug_only( _look_probes++ ); 117 key = (key + stride/*7*/) & (_max-1); // Stride through table with relative prime 118 k = _table[key]; // Get hashed value 119 if( !k ) { // ?Miss? 120 debug_only( _lookup_misses++ ); 121 return NULL; // Miss! 122 } 123 } 124 ShouldNotReachHere(); 125 return NULL; 126 } 127 128 //------------------------------hash_find_insert------------------------------- 129 // Find in hash table, insert if not already present 130 // Used to preserve unique entries in hash table 131 Node *NodeHash::hash_find_insert( Node *n ) { 132 // n->set_hash( ); 133 uint hash = n->hash(); 134 if (hash == Node::NO_HASH) { 135 debug_only( _lookup_misses++ ); 136 return NULL; 137 } 138 uint key = hash & (_max-1); 139 uint stride = key | 0x01; // stride must be relatively prime to table siz 140 uint first_sentinel = 0; // replace a sentinel if seen. 141 debug_only( _look_probes++ ); 142 Node *k = _table[key]; // Get hashed value 143 if( !k ) { // ?Miss? 144 debug_only( _lookup_misses++ ); 145 _table[key] = n; // Insert into table! 146 debug_only(n->enter_hash_lock()); // Lock down the node while in the table. 147 check_grow(); // Grow table if insert hit limit 148 return NULL; // Miss! 149 } 150 else if( k == _sentinel ) { 151 first_sentinel = key; // Can insert here 152 } 153 154 int op = n->Opcode(); 155 uint req = n->req(); 156 while( 1 ) { // While probing hash table 157 if( k->req() == req && // Same count of inputs 158 k->Opcode() == op ) { // Same Opcode 159 for( uint i=0; i<req; i++ ) 160 if( n->in(i)!=k->in(i)) // Different inputs? 161 goto collision; // "goto" is a speed hack... 162 if( n->cmp(*k) ) { // Check for any special bits 163 debug_only( _lookup_hits++ ); 164 return k; // Hit! 165 } 166 } 167 collision: 168 debug_only( _look_probes++ ); 169 key = (key + stride) & (_max-1); // Stride through table w/ relative prime 170 k = _table[key]; // Get hashed value 171 if( !k ) { // ?Miss? 172 debug_only( _lookup_misses++ ); 173 key = (first_sentinel == 0) ? key : first_sentinel; // ?saw sentinel? 174 _table[key] = n; // Insert into table! 175 debug_only(n->enter_hash_lock()); // Lock down the node while in the table. 176 check_grow(); // Grow table if insert hit limit 177 return NULL; // Miss! 178 } 179 else if( first_sentinel == 0 && k == _sentinel ) { 180 first_sentinel = key; // Can insert here 181 } 182 183 } 184 ShouldNotReachHere(); 185 return NULL; 186 } 187 188 //------------------------------hash_insert------------------------------------ 189 // Insert into hash table 190 void NodeHash::hash_insert( Node *n ) { 191 // // "conflict" comments -- print nodes that conflict 192 // bool conflict = false; 193 // n->set_hash(); 194 uint hash = n->hash(); 195 if (hash == Node::NO_HASH) { 196 return; 197 } 198 check_grow(); 199 uint key = hash & (_max-1); 200 uint stride = key | 0x01; 201 202 while( 1 ) { // While probing hash table 203 debug_only( _insert_probes++ ); 204 Node *k = _table[key]; // Get hashed value 205 if( !k || (k == _sentinel) ) break; // Found a slot 206 assert( k != n, "already inserted" ); 207 // if( PrintCompilation && PrintOptoStatistics && Verbose ) { tty->print(" conflict: "); k->dump(); conflict = true; } 208 key = (key + stride) & (_max-1); // Stride through table w/ relative prime 209 } 210 _table[key] = n; // Insert into table! 211 debug_only(n->enter_hash_lock()); // Lock down the node while in the table. 212 // if( conflict ) { n->dump(); } 213 } 214 215 //------------------------------hash_delete------------------------------------ 216 // Replace in hash table with sentinel 217 bool NodeHash::hash_delete( const Node *n ) { 218 Node *k; 219 uint hash = n->hash(); 220 if (hash == Node::NO_HASH) { 221 debug_only( _delete_misses++ ); 222 return false; 223 } 224 uint key = hash & (_max-1); 225 uint stride = key | 0x01; 226 debug_only( uint counter = 0; ); 227 for( ; /* (k != NULL) && (k != _sentinel) */; ) { 228 debug_only( counter++ ); 229 debug_only( _delete_probes++ ); 230 k = _table[key]; // Get hashed value 231 if( !k ) { // Miss? 232 debug_only( _delete_misses++ ); 233 #ifdef ASSERT 234 if( VerifyOpto ) { 235 for( uint i=0; i < _max; i++ ) 236 assert( _table[i] != n, "changed edges with rehashing" ); 237 } 238 #endif 239 return false; // Miss! Not in chain 240 } 241 else if( n == k ) { 242 debug_only( _delete_hits++ ); 243 _table[key] = _sentinel; // Hit! Label as deleted entry 244 debug_only(((Node*)n)->exit_hash_lock()); // Unlock the node upon removal from table. 245 return true; 246 } 247 else { 248 // collision: move through table with prime offset 249 key = (key + stride/*7*/) & (_max-1); 250 assert( counter <= _insert_limit, "Cycle in hash-table"); 251 } 252 } 253 ShouldNotReachHere(); 254 return false; 255 } 256 257 //------------------------------round_up--------------------------------------- 258 // Round up to nearest power of 2 259 uint NodeHash::round_up( uint x ) { 260 x += (x>>2); // Add 25% slop 261 if( x <16 ) return 16; // Small stuff 262 uint i=16; 263 while( i < x ) i <<= 1; // Double to fit 264 return i; // Return hash table size 265 } 266 267 //------------------------------grow------------------------------------------- 268 // Grow _table to next power of 2 and insert old entries 269 void NodeHash::grow() { 270 // Record old state 271 uint old_max = _max; 272 Node **old_table = _table; 273 // Construct new table with twice the space 274 _grows++; 275 _total_inserts += _inserts; 276 _total_insert_probes += _insert_probes; 277 _inserts = 0; 278 _insert_probes = 0; 279 _max = _max << 1; 280 _table = NEW_ARENA_ARRAY( _a , Node* , _max ); // (Node**)_a->Amalloc( _max * sizeof(Node*) ); 281 memset(_table,0,sizeof(Node*)*_max); 282 _insert_limit = insert_limit(); 283 // Insert old entries into the new table 284 for( uint i = 0; i < old_max; i++ ) { 285 Node *m = *old_table++; 286 if( !m || m == _sentinel ) continue; 287 debug_only(m->exit_hash_lock()); // Unlock the node upon removal from old table. 288 hash_insert(m); 289 } 290 } 291 292 //------------------------------clear------------------------------------------ 293 // Clear all entries in _table to NULL but keep storage 294 void NodeHash::clear() { 295 #ifdef ASSERT 296 // Unlock all nodes upon removal from table. 297 for (uint i = 0; i < _max; i++) { 298 Node* n = _table[i]; 299 if (!n || n == _sentinel) continue; 300 n->exit_hash_lock(); 301 } 302 #endif 303 304 memset( _table, 0, _max * sizeof(Node*) ); 305 } 306 307 //-----------------------remove_useless_nodes---------------------------------- 308 // Remove useless nodes from value table, 309 // implementation does not depend on hash function 310 void NodeHash::remove_useless_nodes(VectorSet &useful) { 311 312 // Dead nodes in the hash table inherited from GVN should not replace 313 // existing nodes, remove dead nodes. 314 uint max = size(); 315 Node *sentinel_node = sentinel(); 316 for( uint i = 0; i < max; ++i ) { 317 Node *n = at(i); 318 if(n != NULL && n != sentinel_node && !useful.test(n->_idx)) { 319 debug_only(n->exit_hash_lock()); // Unlock the node when removed 320 _table[i] = sentinel_node; // Replace with placeholder 321 } 322 } 323 } 324 325 326 void NodeHash::check_no_speculative_types() { 327 #ifdef ASSERT 328 uint max = size(); 329 Node *sentinel_node = sentinel(); 330 for (uint i = 0; i < max; ++i) { 331 Node *n = at(i); 332 if(n != NULL && n != sentinel_node && n->is_Type() && n->outcnt() > 0) { 333 TypeNode* tn = n->as_Type(); 334 const Type* t = tn->type(); 335 const Type* t_no_spec = t->remove_speculative(); 336 assert(t == t_no_spec, "dead node in hash table or missed node during speculative cleanup"); 337 } 338 } 339 #endif 340 } 341 342 #ifndef PRODUCT 343 //------------------------------dump------------------------------------------- 344 // Dump statistics for the hash table 345 void NodeHash::dump() { 346 _total_inserts += _inserts; 347 _total_insert_probes += _insert_probes; 348 if (PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0)) { 349 if (WizardMode) { 350 for (uint i=0; i<_max; i++) { 351 if (_table[i]) 352 tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx); 353 } 354 } 355 tty->print("\nGVN Hash stats: %d grows to %d max_size\n", _grows, _max); 356 tty->print(" %d/%d (%8.1f%% full)\n", _inserts, _max, (double)_inserts/_max*100.0); 357 tty->print(" %dp/(%dh+%dm) (%8.2f probes/lookup)\n", _look_probes, _lookup_hits, _lookup_misses, (double)_look_probes/(_lookup_hits+_lookup_misses)); 358 tty->print(" %dp/%di (%8.2f probes/insert)\n", _total_insert_probes, _total_inserts, (double)_total_insert_probes/_total_inserts); 359 // sentinels increase lookup cost, but not insert cost 360 assert((_lookup_misses+_lookup_hits)*4+100 >= _look_probes, "bad hash function"); 361 assert( _inserts+(_inserts>>3) < _max, "table too full" ); 362 assert( _inserts*3+100 >= _insert_probes, "bad hash function" ); 363 } 364 } 365 366 Node *NodeHash::find_index(uint idx) { // For debugging 367 // Find an entry by its index value 368 for( uint i = 0; i < _max; i++ ) { 369 Node *m = _table[i]; 370 if( !m || m == _sentinel ) continue; 371 if( m->_idx == (uint)idx ) return m; 372 } 373 return NULL; 374 } 375 #endif 376 377 #ifdef ASSERT 378 NodeHash::~NodeHash() { 379 // Unlock all nodes upon destruction of table. 380 if (_table != (Node**)badAddress) clear(); 381 } 382 383 void NodeHash::operator=(const NodeHash& nh) { 384 // Unlock all nodes upon replacement of table. 385 if (&nh == this) return; 386 if (_table != (Node**)badAddress) clear(); 387 memcpy(this, &nh, sizeof(*this)); 388 // Do not increment hash_lock counts again. 389 // Instead, be sure we never again use the source table. 390 ((NodeHash*)&nh)->_table = (Node**)badAddress; 391 } 392 393 394 #endif 395 396 397 //============================================================================= 398 //------------------------------PhaseRemoveUseless----------------------------- 399 // 1) Use a breadthfirst walk to collect useful nodes reachable from root. 400 PhaseRemoveUseless::PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist ) : Phase(Remove_Useless), 401 _useful(Thread::current()->resource_area()) { 402 403 // Implementation requires 'UseLoopSafepoints == true' and an edge from root 404 // to each SafePointNode at a backward branch. Inserted in add_safepoint(). 405 if( !UseLoopSafepoints || !OptoRemoveUseless ) return; 406 407 // Identify nodes that are reachable from below, useful. 408 C->identify_useful_nodes(_useful); 409 // Update dead node list 410 C->update_dead_node_list(_useful); 411 412 // Remove all useless nodes from PhaseValues' recorded types 413 // Must be done before disconnecting nodes to preserve hash-table-invariant 414 gvn->remove_useless_nodes(_useful.member_set()); 415 416 // Remove all useless nodes from future worklist 417 worklist->remove_useless_nodes(_useful.member_set()); 418 419 // Disconnect 'useless' nodes that are adjacent to useful nodes 420 C->remove_useless_nodes(_useful); 421 422 // Remove edges from "root" to each SafePoint at a backward branch. 423 // They were inserted during parsing (see add_safepoint()) to make infinite 424 // loops without calls or exceptions visible to root, i.e., useful. 425 Node *root = C->root(); 426 if( root != NULL ) { 427 for( uint i = root->req(); i < root->len(); ++i ) { 428 Node *n = root->in(i); 429 if( n != NULL && n->is_SafePoint() ) { 430 root->rm_prec(i); 431 --i; 432 } 433 } 434 } 435 } 436 437 438 //============================================================================= 439 //------------------------------PhaseTransform--------------------------------- 440 PhaseTransform::PhaseTransform( PhaseNumber pnum ) : Phase(pnum), 441 _arena(Thread::current()->resource_area()), 442 _nodes(_arena), 443 _types(_arena) 444 { 445 init_con_caches(); 446 #ifndef PRODUCT 447 clear_progress(); 448 clear_transforms(); 449 set_allow_progress(true); 450 #endif 451 // Force allocation for currently existing nodes 452 _types.map(C->unique(), NULL); 453 } 454 455 //------------------------------PhaseTransform--------------------------------- 456 PhaseTransform::PhaseTransform( Arena *arena, PhaseNumber pnum ) : Phase(pnum), 457 _arena(arena), 458 _nodes(arena), 459 _types(arena) 460 { 461 init_con_caches(); 462 #ifndef PRODUCT 463 clear_progress(); 464 clear_transforms(); 465 set_allow_progress(true); 466 #endif 467 // Force allocation for currently existing nodes 468 _types.map(C->unique(), NULL); 469 } 470 471 //------------------------------PhaseTransform--------------------------------- 472 // Initialize with previously generated type information 473 PhaseTransform::PhaseTransform( PhaseTransform *pt, PhaseNumber pnum ) : Phase(pnum), 474 _arena(pt->_arena), 475 _nodes(pt->_nodes), 476 _types(pt->_types) 477 { 478 init_con_caches(); 479 #ifndef PRODUCT 480 clear_progress(); 481 clear_transforms(); 482 set_allow_progress(true); 483 #endif 484 } 485 486 void PhaseTransform::init_con_caches() { 487 memset(_icons,0,sizeof(_icons)); 488 memset(_lcons,0,sizeof(_lcons)); 489 memset(_zcons,0,sizeof(_zcons)); 490 } 491 492 493 //--------------------------------find_int_type-------------------------------- 494 const TypeInt* PhaseTransform::find_int_type(Node* n) { 495 if (n == NULL) return NULL; 496 // Call type_or_null(n) to determine node's type since we might be in 497 // parse phase and call n->Value() may return wrong type. 498 // (For example, a phi node at the beginning of loop parsing is not ready.) 499 const Type* t = type_or_null(n); 500 if (t == NULL) return NULL; 501 return t->isa_int(); 502 } 503 504 505 //-------------------------------find_long_type-------------------------------- 506 const TypeLong* PhaseTransform::find_long_type(Node* n) { 507 if (n == NULL) return NULL; 508 // (See comment above on type_or_null.) 509 const Type* t = type_or_null(n); 510 if (t == NULL) return NULL; 511 return t->isa_long(); 512 } 513 514 515 #ifndef PRODUCT 516 void PhaseTransform::dump_old2new_map() const { 517 _nodes.dump(); 518 } 519 520 void PhaseTransform::dump_new( uint nidx ) const { 521 for( uint i=0; i<_nodes.Size(); i++ ) 522 if( _nodes[i] && _nodes[i]->_idx == nidx ) { 523 _nodes[i]->dump(); 524 tty->cr(); 525 tty->print_cr("Old index= %d",i); 526 return; 527 } 528 tty->print_cr("Node %d not found in the new indices", nidx); 529 } 530 531 //------------------------------dump_types------------------------------------- 532 void PhaseTransform::dump_types( ) const { 533 _types.dump(); 534 } 535 536 //------------------------------dump_nodes_and_types--------------------------- 537 void PhaseTransform::dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl) { 538 VectorSet visited(Thread::current()->resource_area()); 539 dump_nodes_and_types_recur( root, depth, only_ctrl, visited ); 540 } 541 542 //------------------------------dump_nodes_and_types_recur--------------------- 543 void PhaseTransform::dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited) { 544 if( !n ) return; 545 if( depth == 0 ) return; 546 if( visited.test_set(n->_idx) ) return; 547 for( uint i=0; i<n->len(); i++ ) { 548 if( only_ctrl && !(n->is_Region()) && i != TypeFunc::Control ) continue; 549 dump_nodes_and_types_recur( n->in(i), depth-1, only_ctrl, visited ); 550 } 551 n->dump(); 552 if (type_or_null(n) != NULL) { 553 tty->print(" "); type(n)->dump(); tty->cr(); 554 } 555 } 556 557 #endif 558 559 560 //============================================================================= 561 //------------------------------PhaseValues------------------------------------ 562 // Set minimum table size to "255" 563 PhaseValues::PhaseValues( Arena *arena, uint est_max_size ) : PhaseTransform(arena, GVN), _table(arena, est_max_size) { 564 NOT_PRODUCT( clear_new_values(); ) 565 } 566 567 //------------------------------PhaseValues------------------------------------ 568 // Set minimum table size to "255" 569 PhaseValues::PhaseValues( PhaseValues *ptv ) : PhaseTransform( ptv, GVN ), 570 _table(&ptv->_table) { 571 NOT_PRODUCT( clear_new_values(); ) 572 } 573 574 //------------------------------PhaseValues------------------------------------ 575 // Used by +VerifyOpto. Clear out hash table but copy _types array. 576 PhaseValues::PhaseValues( PhaseValues *ptv, const char *dummy ) : PhaseTransform( ptv, GVN ), 577 _table(ptv->arena(),ptv->_table.size()) { 578 NOT_PRODUCT( clear_new_values(); ) 579 } 580 581 //------------------------------~PhaseValues----------------------------------- 582 #ifndef PRODUCT 583 PhaseValues::~PhaseValues() { 584 _table.dump(); 585 586 // Statistics for value progress and efficiency 587 if( PrintCompilation && Verbose && WizardMode ) { 588 tty->print("\n%sValues: %d nodes ---> %d/%d (%d)", 589 is_IterGVN() ? "Iter" : " ", C->unique(), made_progress(), made_transforms(), made_new_values()); 590 if( made_transforms() != 0 ) { 591 tty->print_cr(" ratio %f", made_progress()/(float)made_transforms() ); 592 } else { 593 tty->cr(); 594 } 595 } 596 } 597 #endif 598 599 //------------------------------makecon---------------------------------------- 600 ConNode* PhaseTransform::makecon(const Type *t) { 601 assert(t->singleton(), "must be a constant"); 602 assert(!t->empty() || t == Type::TOP, "must not be vacuous range"); 603 switch (t->base()) { // fast paths 604 case Type::Half: 605 case Type::Top: return (ConNode*) C->top(); 606 case Type::Int: return intcon( t->is_int()->get_con() ); 607 case Type::Long: return longcon( t->is_long()->get_con() ); 608 } 609 if (t->is_zero_type()) 610 return zerocon(t->basic_type()); 611 return uncached_makecon(t); 612 } 613 614 //--------------------------uncached_makecon----------------------------------- 615 // Make an idealized constant - one of ConINode, ConPNode, etc. 616 ConNode* PhaseValues::uncached_makecon(const Type *t) { 617 assert(t->singleton(), "must be a constant"); 618 ConNode* x = ConNode::make(C, t); 619 ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering 620 if (k == NULL) { 621 set_type(x, t); // Missed, provide type mapping 622 GrowableArray<Node_Notes*>* nna = C->node_note_array(); 623 if (nna != NULL) { 624 Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true); 625 loc->clear(); // do not put debug info on constants 626 } 627 } else { 628 x->destruct(); // Hit, destroy duplicate constant 629 x = k; // use existing constant 630 } 631 return x; 632 } 633 634 //------------------------------intcon----------------------------------------- 635 // Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))" 636 ConINode* PhaseTransform::intcon(int i) { 637 // Small integer? Check cache! Check that cached node is not dead 638 if (i >= _icon_min && i <= _icon_max) { 639 ConINode* icon = _icons[i-_icon_min]; 640 if (icon != NULL && icon->in(TypeFunc::Control) != NULL) 641 return icon; 642 } 643 ConINode* icon = (ConINode*) uncached_makecon(TypeInt::make(i)); 644 assert(icon->is_Con(), ""); 645 if (i >= _icon_min && i <= _icon_max) 646 _icons[i-_icon_min] = icon; // Cache small integers 647 return icon; 648 } 649 650 //------------------------------longcon---------------------------------------- 651 // Fast long constant. 652 ConLNode* PhaseTransform::longcon(jlong l) { 653 // Small integer? Check cache! Check that cached node is not dead 654 if (l >= _lcon_min && l <= _lcon_max) { 655 ConLNode* lcon = _lcons[l-_lcon_min]; 656 if (lcon != NULL && lcon->in(TypeFunc::Control) != NULL) 657 return lcon; 658 } 659 ConLNode* lcon = (ConLNode*) uncached_makecon(TypeLong::make(l)); 660 assert(lcon->is_Con(), ""); 661 if (l >= _lcon_min && l <= _lcon_max) 662 _lcons[l-_lcon_min] = lcon; // Cache small integers 663 return lcon; 664 } 665 666 //------------------------------zerocon----------------------------------------- 667 // Fast zero or null constant. Same as "transform(ConNode::make(Type::get_zero_type(bt)))" 668 ConNode* PhaseTransform::zerocon(BasicType bt) { 669 assert((uint)bt <= _zcon_max, "domain check"); 670 ConNode* zcon = _zcons[bt]; 671 if (zcon != NULL && zcon->in(TypeFunc::Control) != NULL) 672 return zcon; 673 zcon = (ConNode*) uncached_makecon(Type::get_zero_type(bt)); 674 _zcons[bt] = zcon; 675 return zcon; 676 } 677 678 679 680 //============================================================================= 681 //------------------------------transform-------------------------------------- 682 // Return a node which computes the same function as this node, but in a 683 // faster or cheaper fashion. 684 Node *PhaseGVN::transform( Node *n ) { 685 return transform_no_reclaim(n); 686 } 687 688 //------------------------------transform-------------------------------------- 689 // Return a node which computes the same function as this node, but 690 // in a faster or cheaper fashion. 691 Node *PhaseGVN::transform_no_reclaim( Node *n ) { 692 NOT_PRODUCT( set_transforms(); ) 693 694 // Apply the Ideal call in a loop until it no longer applies 695 Node *k = n; 696 NOT_PRODUCT( uint loop_count = 0; ) 697 while( 1 ) { 698 Node *i = k->Ideal(this, /*can_reshape=*/false); 699 if( !i ) break; 700 assert( i->_idx >= k->_idx, "Idealize should return new nodes, use Identity to return old nodes" ); 701 k = i; 702 assert(loop_count++ < K, "infinite loop in PhaseGVN::transform"); 703 } 704 NOT_PRODUCT( if( loop_count != 0 ) { set_progress(); } ) 705 706 707 // If brand new node, make space in type array. 708 ensure_type_or_null(k); 709 710 // Since I just called 'Value' to compute the set of run-time values 711 // for this Node, and 'Value' is non-local (and therefore expensive) I'll 712 // cache Value. Later requests for the local phase->type of this Node can 713 // use the cached Value instead of suffering with 'bottom_type'. 714 const Type *t = k->Value(this); // Get runtime Value set 715 assert(t != NULL, "value sanity"); 716 if (type_or_null(k) != t) { 717 #ifndef PRODUCT 718 // Do not count initial visit to node as a transformation 719 if (type_or_null(k) == NULL) { 720 inc_new_values(); 721 set_progress(); 722 } 723 #endif 724 set_type(k, t); 725 // If k is a TypeNode, capture any more-precise type permanently into Node 726 k->raise_bottom_type(t); 727 } 728 729 if( t->singleton() && !k->is_Con() ) { 730 NOT_PRODUCT( set_progress(); ) 731 return makecon(t); // Turn into a constant 732 } 733 734 // Now check for Identities 735 Node *i = k->Identity(this); // Look for a nearby replacement 736 if( i != k ) { // Found? Return replacement! 737 NOT_PRODUCT( set_progress(); ) 738 return i; 739 } 740 741 // Global Value Numbering 742 i = hash_find_insert(k); // Insert if new 743 if( i && (i != k) ) { 744 // Return the pre-existing node 745 NOT_PRODUCT( set_progress(); ) 746 return i; 747 } 748 749 // Return Idealized original 750 return k; 751 } 752 753 #ifdef ASSERT 754 //------------------------------dead_loop_check-------------------------------- 755 // Check for a simple dead loop when a data node references itself directly 756 // or through an other data node excluding cons and phis. 757 void PhaseGVN::dead_loop_check( Node *n ) { 758 // Phi may reference itself in a loop 759 if (n != NULL && !n->is_dead_loop_safe() && !n->is_CFG()) { 760 // Do 2 levels check and only data inputs. 761 bool no_dead_loop = true; 762 uint cnt = n->req(); 763 for (uint i = 1; i < cnt && no_dead_loop; i++) { 764 Node *in = n->in(i); 765 if (in == n) { 766 no_dead_loop = false; 767 } else if (in != NULL && !in->is_dead_loop_safe()) { 768 uint icnt = in->req(); 769 for (uint j = 1; j < icnt && no_dead_loop; j++) { 770 if (in->in(j) == n || in->in(j) == in) 771 no_dead_loop = false; 772 } 773 } 774 } 775 if (!no_dead_loop) n->dump(3); 776 assert(no_dead_loop, "dead loop detected"); 777 } 778 } 779 #endif 780 781 //============================================================================= 782 //------------------------------PhaseIterGVN----------------------------------- 783 // Initialize hash table to fresh and clean for +VerifyOpto 784 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ), 785 _stack(C->unique() >> 1), 786 _delay_transform(false) { 787 } 788 789 //------------------------------PhaseIterGVN----------------------------------- 790 // Initialize with previous PhaseIterGVN info; used by PhaseCCP 791 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn), 792 _worklist( igvn->_worklist ), 793 _stack( igvn->_stack ), 794 _delay_transform(igvn->_delay_transform) 795 { 796 } 797 798 //------------------------------PhaseIterGVN----------------------------------- 799 // Initialize with previous PhaseGVN info from Parser 800 PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), 801 _worklist(*C->for_igvn()), 802 _stack(C->unique() >> 1), 803 _delay_transform(false) 804 { 805 uint max; 806 807 // Dead nodes in the hash table inherited from GVN were not treated as 808 // roots during def-use info creation; hence they represent an invisible 809 // use. Clear them out. 810 max = _table.size(); 811 for( uint i = 0; i < max; ++i ) { 812 Node *n = _table.at(i); 813 if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) { 814 if( n->is_top() ) continue; 815 assert( false, "Parse::remove_useless_nodes missed this node"); 816 hash_delete(n); 817 } 818 } 819 820 // Any Phis or Regions on the worklist probably had uses that could not 821 // make more progress because the uses were made while the Phis and Regions 822 // were in half-built states. Put all uses of Phis and Regions on worklist. 823 max = _worklist.size(); 824 for( uint j = 0; j < max; j++ ) { 825 Node *n = _worklist.at(j); 826 uint uop = n->Opcode(); 827 if( uop == Op_Phi || uop == Op_Region || 828 n->is_Type() || 829 n->is_Mem() ) 830 add_users_to_worklist(n); 831 } 832 } 833 834 /** 835 * Initialize worklist for each node. 836 */ 837 void PhaseIterGVN::init_worklist(Node* first) { 838 Unique_Node_List to_process; 839 to_process.push(first); 840 841 while (to_process.size() > 0) { 842 Node* n = to_process.pop(); 843 if (!_worklist.member(n)) { 844 _worklist.push(n); 845 846 uint cnt = n->req(); 847 for(uint i = 0; i < cnt; i++) { 848 Node* m = n->in(i); 849 if (m != NULL) { 850 to_process.push(m); 851 } 852 } 853 } 854 } 855 } 856 857 #ifndef PRODUCT 858 void PhaseIterGVN::verify_step(Node* n) { 859 if (VerifyIterativeGVN) { 860 _verify_window[_verify_counter % _verify_window_size] = n; 861 ++_verify_counter; 862 ResourceMark rm; 863 ResourceArea* area = Thread::current()->resource_area(); 864 VectorSet old_space(area), new_space(area); 865 if (C->unique() < 1000 || 866 0 == _verify_counter % (C->unique() < 10000 ? 10 : 100)) { 867 ++_verify_full_passes; 868 Node::verify_recur(C->root(), -1, old_space, new_space); 869 } 870 const int verify_depth = 4; 871 for ( int i = 0; i < _verify_window_size; i++ ) { 872 Node* n = _verify_window[i]; 873 if ( n == NULL ) continue; 874 if( n->in(0) == NodeSentinel ) { // xform_idom 875 _verify_window[i] = n->in(1); 876 --i; continue; 877 } 878 // Typical fanout is 1-2, so this call visits about 6 nodes. 879 Node::verify_recur(n, verify_depth, old_space, new_space); 880 } 881 } 882 } 883 884 void PhaseIterGVN::trace_PhaseIterGVN(Node* n, Node* nn, const Type* oldtype) { 885 if (TraceIterativeGVN) { 886 uint wlsize = _worklist.size(); 887 const Type* newtype = type_or_null(n); 888 if (nn != n) { 889 // print old node 890 tty->print("< "); 891 if (oldtype != newtype && oldtype != NULL) { 892 oldtype->dump(); 893 } 894 do { tty->print("\t"); } while (tty->position() < 16); 895 tty->print("<"); 896 n->dump(); 897 } 898 if (oldtype != newtype || nn != n) { 899 // print new node and/or new type 900 if (oldtype == NULL) { 901 tty->print("* "); 902 } else if (nn != n) { 903 tty->print("> "); 904 } else { 905 tty->print("= "); 906 } 907 if (newtype == NULL) { 908 tty->print("null"); 909 } else { 910 newtype->dump(); 911 } 912 do { tty->print("\t"); } while (tty->position() < 16); 913 nn->dump(); 914 } 915 if (Verbose && wlsize < _worklist.size()) { 916 tty->print(" Push {"); 917 while (wlsize != _worklist.size()) { 918 Node* pushed = _worklist.at(wlsize++); 919 tty->print(" %d", pushed->_idx); 920 } 921 tty->print_cr(" }"); 922 } 923 if (nn != n) { 924 // ignore n, it might be subsumed 925 verify_step((Node*) NULL); 926 } 927 } 928 } 929 930 void PhaseIterGVN::init_verifyPhaseIterGVN() { 931 _verify_counter = 0; 932 _verify_full_passes = 0; 933 for (int i = 0; i < _verify_window_size; i++) { 934 _verify_window[i] = NULL; 935 } 936 #ifdef ASSERT 937 // Verify that all modified nodes are on _worklist 938 Unique_Node_List* modified_list = C->modified_nodes(); 939 while (modified_list != NULL && modified_list->size()) { 940 Node* n = modified_list->pop(); 941 if (n->outcnt() != 0 && !n->is_Con() && !_worklist.member(n)) { 942 n->dump(); 943 assert(false, "modified node is not on IGVN._worklist"); 944 } 945 } 946 #endif 947 } 948 949 void PhaseIterGVN::verify_PhaseIterGVN() { 950 #ifdef ASSERT 951 // Verify nodes with changed inputs. 952 Unique_Node_List* modified_list = C->modified_nodes(); 953 while (modified_list != NULL && modified_list->size()) { 954 Node* n = modified_list->pop(); 955 if (n->outcnt() != 0 && !n->is_Con()) { // skip dead and Con nodes 956 n->dump(); 957 assert(false, "modified node was not processed by IGVN.transform_old()"); 958 } 959 } 960 #endif 961 962 C->verify_graph_edges(); 963 if( VerifyOpto && allow_progress() ) { 964 // Must turn off allow_progress to enable assert and break recursion 965 C->root()->verify(); 966 { // Check if any progress was missed using IterGVN 967 // Def-Use info enables transformations not attempted in wash-pass 968 // e.g. Region/Phi cleanup, ... 969 // Null-check elision -- may not have reached fixpoint 970 // do not propagate to dominated nodes 971 ResourceMark rm; 972 PhaseIterGVN igvn2(this,"Verify"); // Fresh and clean! 973 // Fill worklist completely 974 igvn2.init_worklist(C->root()); 975 976 igvn2.set_allow_progress(false); 977 igvn2.optimize(); 978 igvn2.set_allow_progress(true); 979 } 980 } 981 if (VerifyIterativeGVN && PrintOpto) { 982 if (_verify_counter == _verify_full_passes) { 983 tty->print_cr("VerifyIterativeGVN: %d transforms and verify passes", 984 (int) _verify_full_passes); 985 } else { 986 tty->print_cr("VerifyIterativeGVN: %d transforms, %d full verify passes", 987 (int) _verify_counter, (int) _verify_full_passes); 988 } 989 } 990 991 #ifdef ASSERT 992 while (modified_list->size()) { 993 Node* n = modified_list->pop(); 994 n->dump(); 995 assert(false, "VerifyIterativeGVN: new modified node was added"); 996 } 997 #endif 998 } 999 #endif /* PRODUCT */ 1000 1001 #ifdef ASSERT 1002 /** 1003 * Dumps information that can help to debug the problem. A debug 1004 * build fails with an assert. 1005 */ 1006 void PhaseIterGVN::dump_infinite_loop_info(Node* n) { 1007 n->dump(4); 1008 _worklist.dump(); 1009 assert(false, "infinite loop in PhaseIterGVN::optimize"); 1010 } 1011 1012 /** 1013 * Prints out information about IGVN if the 'verbose' option is used. 1014 */ 1015 void PhaseIterGVN::trace_PhaseIterGVN_verbose(Node* n, int num_processed) { 1016 if (TraceIterativeGVN && Verbose) { 1017 tty->print(" Pop "); 1018 n->dump(); 1019 if ((num_processed % 100) == 0) { 1020 _worklist.print_set(); 1021 } 1022 } 1023 } 1024 #endif /* ASSERT */ 1025 1026 void PhaseIterGVN::optimize() { 1027 DEBUG_ONLY(uint num_processed = 0;) 1028 NOT_PRODUCT(init_verifyPhaseIterGVN();) 1029 1030 uint loop_count = 0; 1031 // Pull from worklist and transform the node. If the node has changed, 1032 // update edge info and put uses on worklist. 1033 while(_worklist.size()) { 1034 if (C->check_node_count(NodeLimitFudgeFactor * 2, "Out of nodes")) { 1035 return; 1036 } 1037 Node* n = _worklist.pop(); 1038 if (++loop_count >= K * C->live_nodes()) { 1039 DEBUG_ONLY(dump_infinite_loop_info(n);) 1040 C->record_method_not_compilable("infinite loop in PhaseIterGVN::optimize"); 1041 return; 1042 } 1043 DEBUG_ONLY(trace_PhaseIterGVN_verbose(n, num_processed++);) 1044 if (n->outcnt() != 0) { 1045 NOT_PRODUCT(const Type* oldtype = type_or_null(n)); 1046 // Do the transformation 1047 Node* nn = transform_old(n); 1048 NOT_PRODUCT(trace_PhaseIterGVN(n, nn, oldtype);) 1049 } else if (!n->is_top()) { 1050 remove_dead_node(n); 1051 } 1052 } 1053 NOT_PRODUCT(verify_PhaseIterGVN();) 1054 } 1055 1056 1057 /** 1058 * Register a new node with the optimizer. Update the types array, the def-use 1059 * info. Put on worklist. 1060 */ 1061 Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) { 1062 set_type_bottom(n); 1063 _worklist.push(n); 1064 if (orig != NULL) C->copy_node_notes_to(n, orig); 1065 return n; 1066 } 1067 1068 //------------------------------transform-------------------------------------- 1069 // Non-recursive: idealize Node 'n' with respect to its inputs and its value 1070 Node *PhaseIterGVN::transform( Node *n ) { 1071 if (_delay_transform) { 1072 // Register the node but don't optimize for now 1073 register_new_node_with_optimizer(n); 1074 return n; 1075 } 1076 1077 // If brand new node, make space in type array, and give it a type. 1078 ensure_type_or_null(n); 1079 if (type_or_null(n) == NULL) { 1080 set_type_bottom(n); 1081 } 1082 1083 return transform_old(n); 1084 } 1085 1086 Node *PhaseIterGVN::transform_old(Node* n) { 1087 DEBUG_ONLY(uint loop_count = 0;); 1088 NOT_PRODUCT(set_transforms()); 1089 1090 // Remove 'n' from hash table in case it gets modified 1091 _table.hash_delete(n); 1092 if (VerifyIterativeGVN) { 1093 assert(!_table.find_index(n->_idx), "found duplicate entry in table"); 1094 } 1095 1096 // Apply the Ideal call in a loop until it no longer applies 1097 Node* k = n; 1098 DEBUG_ONLY(dead_loop_check(k);) 1099 DEBUG_ONLY(bool is_new = (k->outcnt() == 0);) 1100 C->remove_modified_node(k); 1101 Node* i = k->Ideal(this, /*can_reshape=*/true); 1102 assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); 1103 #ifndef PRODUCT 1104 verify_step(k); 1105 if (i && VerifyOpto ) { 1106 if (!allow_progress()) { 1107 if (i->is_Add() && (i->outcnt() == 1)) { 1108 // Switched input to left side because this is the only use 1109 } else if (i->is_If() && (i->in(0) == NULL)) { 1110 // This IF is dead because it is dominated by an equivalent IF When 1111 // dominating if changed, info is not propagated sparsely to 'this' 1112 // Propagating this info further will spuriously identify other 1113 // progress. 1114 return i; 1115 } else 1116 set_progress(); 1117 } else { 1118 set_progress(); 1119 } 1120 } 1121 #endif 1122 1123 while (i != NULL) { 1124 #ifdef ASSERT 1125 if (loop_count >= K) { 1126 dump_infinite_loop_info(i); 1127 } 1128 loop_count++; 1129 #endif 1130 assert((i->_idx >= k->_idx) || i->is_top(), "Idealize should return new nodes, use Identity to return old nodes"); 1131 // Made a change; put users of original Node on worklist 1132 add_users_to_worklist(k); 1133 // Replacing root of transform tree? 1134 if (k != i) { 1135 // Make users of old Node now use new. 1136 subsume_node(k, i); 1137 k = i; 1138 } 1139 DEBUG_ONLY(dead_loop_check(k);) 1140 // Try idealizing again 1141 DEBUG_ONLY(is_new = (k->outcnt() == 0);) 1142 C->remove_modified_node(k); 1143 i = k->Ideal(this, /*can_reshape=*/true); 1144 assert(i != k || is_new || (i->outcnt() > 0), "don't return dead nodes"); 1145 #ifndef PRODUCT 1146 verify_step(k); 1147 if (i && VerifyOpto) { 1148 set_progress(); 1149 } 1150 #endif 1151 } 1152 1153 // If brand new node, make space in type array. 1154 ensure_type_or_null(k); 1155 1156 // See what kind of values 'k' takes on at runtime 1157 const Type* t = k->Value(this); 1158 assert(t != NULL, "value sanity"); 1159 1160 // Since I just called 'Value' to compute the set of run-time values 1161 // for this Node, and 'Value' is non-local (and therefore expensive) I'll 1162 // cache Value. Later requests for the local phase->type of this Node can 1163 // use the cached Value instead of suffering with 'bottom_type'. 1164 if (type_or_null(k) != t) { 1165 #ifndef PRODUCT 1166 inc_new_values(); 1167 set_progress(); 1168 #endif 1169 set_type(k, t); 1170 // If k is a TypeNode, capture any more-precise type permanently into Node 1171 k->raise_bottom_type(t); 1172 // Move users of node to worklist 1173 add_users_to_worklist(k); 1174 } 1175 // If 'k' computes a constant, replace it with a constant 1176 if (t->singleton() && !k->is_Con()) { 1177 NOT_PRODUCT(set_progress();) 1178 Node* con = makecon(t); // Make a constant 1179 add_users_to_worklist(k); 1180 subsume_node(k, con); // Everybody using k now uses con 1181 return con; 1182 } 1183 1184 // Now check for Identities 1185 i = k->Identity(this); // Look for a nearby replacement 1186 if (i != k) { // Found? Return replacement! 1187 NOT_PRODUCT(set_progress();) 1188 add_users_to_worklist(k); 1189 subsume_node(k, i); // Everybody using k now uses i 1190 return i; 1191 } 1192 1193 // Global Value Numbering 1194 i = hash_find_insert(k); // Check for pre-existing node 1195 if (i && (i != k)) { 1196 // Return the pre-existing node if it isn't dead 1197 NOT_PRODUCT(set_progress();) 1198 add_users_to_worklist(k); 1199 subsume_node(k, i); // Everybody using k now uses i 1200 return i; 1201 } 1202 1203 // Return Idealized original 1204 return k; 1205 } 1206 1207 //---------------------------------saturate------------------------------------ 1208 const Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type, 1209 const Type* limit_type) const { 1210 return new_type->narrow(old_type); 1211 } 1212 1213 //------------------------------remove_globally_dead_node---------------------- 1214 // Kill a globally dead Node. All uses are also globally dead and are 1215 // aggressively trimmed. 1216 void PhaseIterGVN::remove_globally_dead_node( Node *dead ) { 1217 enum DeleteProgress { 1218 PROCESS_INPUTS, 1219 PROCESS_OUTPUTS 1220 }; 1221 assert(_stack.is_empty(), "not empty"); 1222 _stack.push(dead, PROCESS_INPUTS); 1223 1224 while (_stack.is_nonempty()) { 1225 dead = _stack.node(); 1226 uint progress_state = _stack.index(); 1227 assert(dead != C->root(), "killing root, eh?"); 1228 assert(!dead->is_top(), "add check for top when pushing"); 1229 NOT_PRODUCT( set_progress(); ) 1230 if (progress_state == PROCESS_INPUTS) { 1231 // After following inputs, continue to outputs 1232 _stack.set_index(PROCESS_OUTPUTS); 1233 if (!dead->is_Con()) { // Don't kill cons but uses 1234 bool recurse = false; 1235 // Remove from hash table 1236 _table.hash_delete( dead ); 1237 // Smash all inputs to 'dead', isolating him completely 1238 for (uint i = 0; i < dead->req(); i++) { 1239 Node *in = dead->in(i); 1240 if (in != NULL && in != C->top()) { // Points to something? 1241 int nrep = dead->replace_edge(in, NULL); // Kill edges 1242 assert((nrep > 0), "sanity"); 1243 if (in->outcnt() == 0) { // Made input go dead? 1244 _stack.push(in, PROCESS_INPUTS); // Recursively remove 1245 recurse = true; 1246 } else if (in->outcnt() == 1 && 1247 in->has_special_unique_user()) { 1248 _worklist.push(in->unique_out()); 1249 } else if (in->outcnt() <= 2 && dead->is_Phi()) { 1250 if (in->Opcode() == Op_Region) { 1251 _worklist.push(in); 1252 } else if (in->is_Store()) { 1253 DUIterator_Fast imax, i = in->fast_outs(imax); 1254 _worklist.push(in->fast_out(i)); 1255 i++; 1256 if (in->outcnt() == 2) { 1257 _worklist.push(in->fast_out(i)); 1258 i++; 1259 } 1260 assert(!(i < imax), "sanity"); 1261 } 1262 } 1263 if (ReduceFieldZeroing && dead->is_Load() && i == MemNode::Memory && 1264 in->is_Proj() && in->in(0) != NULL && in->in(0)->is_Initialize()) { 1265 // A Load that directly follows an InitializeNode is 1266 // going away. The Stores that follow are candidates 1267 // again to be captured by the InitializeNode. 1268 for (DUIterator_Fast jmax, j = in->fast_outs(jmax); j < jmax; j++) { 1269 Node *n = in->fast_out(j); 1270 if (n->is_Store()) { 1271 _worklist.push(n); 1272 } 1273 } 1274 } 1275 } // if (in != NULL && in != C->top()) 1276 } // for (uint i = 0; i < dead->req(); i++) 1277 if (recurse) { 1278 continue; 1279 } 1280 } // if (!dead->is_Con()) 1281 } // if (progress_state == PROCESS_INPUTS) 1282 1283 // Aggressively kill globally dead uses 1284 // (Rather than pushing all the outs at once, we push one at a time, 1285 // plus the parent to resume later, because of the indefinite number 1286 // of edge deletions per loop trip.) 1287 if (dead->outcnt() > 0) { 1288 // Recursively remove output edges 1289 _stack.push(dead->raw_out(0), PROCESS_INPUTS); 1290 } else { 1291 // Finished disconnecting all input and output edges. 1292 _stack.pop(); 1293 // Remove dead node from iterative worklist 1294 _worklist.remove(dead); 1295 C->remove_modified_node(dead); 1296 // Constant node that has no out-edges and has only one in-edge from 1297 // root is usually dead. However, sometimes reshaping walk makes 1298 // it reachable by adding use edges. So, we will NOT count Con nodes 1299 // as dead to be conservative about the dead node count at any 1300 // given time. 1301 if (!dead->is_Con()) { 1302 C->record_dead_node(dead->_idx); 1303 } 1304 if (dead->is_macro()) { 1305 C->remove_macro_node(dead); 1306 } 1307 if (dead->is_expensive()) { 1308 C->remove_expensive_node(dead); 1309 } 1310 } 1311 } // while (_stack.is_nonempty()) 1312 } 1313 1314 //------------------------------subsume_node----------------------------------- 1315 // Remove users from node 'old' and add them to node 'nn'. 1316 void PhaseIterGVN::subsume_node( Node *old, Node *nn ) { 1317 assert( old != hash_find(old), "should already been removed" ); 1318 assert( old != C->top(), "cannot subsume top node"); 1319 // Copy debug or profile information to the new version: 1320 C->copy_node_notes_to(nn, old); 1321 // Move users of node 'old' to node 'nn' 1322 for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { 1323 Node* use = old->last_out(i); // for each use... 1324 // use might need re-hashing (but it won't if it's a new node) 1325 rehash_node_delayed(use); 1326 // Update use-def info as well 1327 // We remove all occurrences of old within use->in, 1328 // so as to avoid rehashing any node more than once. 1329 // The hash table probe swamps any outer loop overhead. 1330 uint num_edges = 0; 1331 for (uint jmax = use->len(), j = 0; j < jmax; j++) { 1332 if (use->in(j) == old) { 1333 use->set_req(j, nn); 1334 ++num_edges; 1335 } 1336 } 1337 i -= num_edges; // we deleted 1 or more copies of this edge 1338 } 1339 1340 // Smash all inputs to 'old', isolating him completely 1341 Node *temp = new Node(1); 1342 temp->init_req(0,nn); // Add a use to nn to prevent him from dying 1343 remove_dead_node( old ); 1344 temp->del_req(0); // Yank bogus edge 1345 #ifndef PRODUCT 1346 if( VerifyIterativeGVN ) { 1347 for ( int i = 0; i < _verify_window_size; i++ ) { 1348 if ( _verify_window[i] == old ) 1349 _verify_window[i] = nn; 1350 } 1351 } 1352 #endif 1353 _worklist.remove(temp); // this can be necessary 1354 temp->destruct(); // reuse the _idx of this little guy 1355 } 1356 1357 //------------------------------add_users_to_worklist-------------------------- 1358 void PhaseIterGVN::add_users_to_worklist0( Node *n ) { 1359 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { 1360 _worklist.push(n->fast_out(i)); // Push on worklist 1361 } 1362 } 1363 1364 void PhaseIterGVN::add_users_to_worklist( Node *n ) { 1365 add_users_to_worklist0(n); 1366 1367 // Move users of node to worklist 1368 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { 1369 Node* use = n->fast_out(i); // Get use 1370 1371 if( use->is_Multi() || // Multi-definer? Push projs on worklist 1372 use->is_Store() ) // Enable store/load same address 1373 add_users_to_worklist0(use); 1374 1375 // If we changed the receiver type to a call, we need to revisit 1376 // the Catch following the call. It's looking for a non-NULL 1377 // receiver to know when to enable the regular fall-through path 1378 // in addition to the NullPtrException path. 1379 if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) { 1380 Node* p = use->as_CallDynamicJava()->proj_out(TypeFunc::Control); 1381 if (p != NULL) { 1382 add_users_to_worklist0(p); 1383 } 1384 } 1385 1386 if( use->is_Cmp() ) { // Enable CMP/BOOL optimization 1387 add_users_to_worklist(use); // Put Bool on worklist 1388 // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the 1389 // phi merging either 0 or 1 onto the worklist 1390 if (use->outcnt() > 0) { 1391 Node* bol = use->raw_out(0); 1392 if (bol->outcnt() > 0) { 1393 Node* iff = bol->raw_out(0); 1394 if (iff->outcnt() == 2) { 1395 Node* ifproj0 = iff->raw_out(0); 1396 Node* ifproj1 = iff->raw_out(1); 1397 if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) { 1398 Node* region0 = ifproj0->raw_out(0); 1399 Node* region1 = ifproj1->raw_out(0); 1400 if( region0 == region1 ) 1401 add_users_to_worklist0(region0); 1402 } 1403 } 1404 } 1405 } 1406 } 1407 1408 uint use_op = use->Opcode(); 1409 // If changed Cast input, check Phi users for simple cycles 1410 if( use->is_ConstraintCast() || use->is_CheckCastPP() ) { 1411 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { 1412 Node* u = use->fast_out(i2); 1413 if (u->is_Phi()) 1414 _worklist.push(u); 1415 } 1416 } 1417 // If changed LShift inputs, check RShift users for useless sign-ext 1418 if( use_op == Op_LShiftI ) { 1419 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { 1420 Node* u = use->fast_out(i2); 1421 if (u->Opcode() == Op_RShiftI) 1422 _worklist.push(u); 1423 } 1424 } 1425 // If changed AddI/SubI inputs, check CmpU for range check optimization. 1426 if (use_op == Op_AddI || use_op == Op_SubI) { 1427 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { 1428 Node* u = use->fast_out(i2); 1429 if (u->is_Cmp() && (u->Opcode() == Op_CmpU)) { 1430 _worklist.push(u); 1431 } 1432 } 1433 } 1434 // If changed AddP inputs, check Stores for loop invariant 1435 if( use_op == Op_AddP ) { 1436 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { 1437 Node* u = use->fast_out(i2); 1438 if (u->is_Mem()) 1439 _worklist.push(u); 1440 } 1441 } 1442 // If changed initialization activity, check dependent Stores 1443 if (use_op == Op_Allocate || use_op == Op_AllocateArray) { 1444 InitializeNode* init = use->as_Allocate()->initialization(); 1445 if (init != NULL) { 1446 Node* imem = init->proj_out(TypeFunc::Memory); 1447 if (imem != NULL) add_users_to_worklist0(imem); 1448 } 1449 } 1450 if (use_op == Op_Initialize) { 1451 Node* imem = use->as_Initialize()->proj_out(TypeFunc::Memory); 1452 if (imem != NULL) add_users_to_worklist0(imem); 1453 } 1454 } 1455 } 1456 1457 /** 1458 * Remove the speculative part of all types that we know of 1459 */ 1460 void PhaseIterGVN::remove_speculative_types() { 1461 assert(UseTypeSpeculation, "speculation is off"); 1462 for (uint i = 0; i < _types.Size(); i++) { 1463 const Type* t = _types.fast_lookup(i); 1464 if (t != NULL) { 1465 _types.map(i, t->remove_speculative()); 1466 } 1467 } 1468 _table.check_no_speculative_types(); 1469 } 1470 1471 //============================================================================= 1472 #ifndef PRODUCT 1473 uint PhaseCCP::_total_invokes = 0; 1474 uint PhaseCCP::_total_constants = 0; 1475 #endif 1476 //------------------------------PhaseCCP--------------------------------------- 1477 // Conditional Constant Propagation, ala Wegman & Zadeck 1478 PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) { 1479 NOT_PRODUCT( clear_constants(); ) 1480 assert( _worklist.size() == 0, "" ); 1481 // Clear out _nodes from IterGVN. Must be clear to transform call. 1482 _nodes.clear(); // Clear out from IterGVN 1483 analyze(); 1484 } 1485 1486 #ifndef PRODUCT 1487 //------------------------------~PhaseCCP-------------------------------------- 1488 PhaseCCP::~PhaseCCP() { 1489 inc_invokes(); 1490 _total_constants += count_constants(); 1491 } 1492 #endif 1493 1494 1495 #ifdef ASSERT 1496 static bool ccp_type_widens(const Type* t, const Type* t0) { 1497 assert(t->meet(t0) == t, "Not monotonic"); 1498 switch (t->base() == t0->base() ? t->base() : Type::Top) { 1499 case Type::Int: 1500 assert(t0->isa_int()->_widen <= t->isa_int()->_widen, "widen increases"); 1501 break; 1502 case Type::Long: 1503 assert(t0->isa_long()->_widen <= t->isa_long()->_widen, "widen increases"); 1504 break; 1505 } 1506 return true; 1507 } 1508 #endif //ASSERT 1509 1510 //------------------------------analyze---------------------------------------- 1511 void PhaseCCP::analyze() { 1512 // Initialize all types to TOP, optimistic analysis 1513 for (int i = C->unique() - 1; i >= 0; i--) { 1514 _types.map(i,Type::TOP); 1515 } 1516 1517 // Push root onto worklist 1518 Unique_Node_List worklist; 1519 worklist.push(C->root()); 1520 1521 // Pull from worklist; compute new value; push changes out. 1522 // This loop is the meat of CCP. 1523 while( worklist.size() ) { 1524 Node *n = worklist.pop(); 1525 const Type *t = n->Value(this); 1526 if (t != type(n)) { 1527 assert(ccp_type_widens(t, type(n)), "ccp type must widen"); 1528 #ifndef PRODUCT 1529 if( TracePhaseCCP ) { 1530 t->dump(); 1531 do { tty->print("\t"); } while (tty->position() < 16); 1532 n->dump(); 1533 } 1534 #endif 1535 set_type(n, t); 1536 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { 1537 Node* m = n->fast_out(i); // Get user 1538 if( m->is_Region() ) { // New path to Region? Must recheck Phis too 1539 for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { 1540 Node* p = m->fast_out(i2); // Propagate changes to uses 1541 if( p->bottom_type() != type(p) ) // If not already bottomed out 1542 worklist.push(p); // Propagate change to user 1543 } 1544 } 1545 // If we changed the receiver type to a call, we need to revisit 1546 // the Catch following the call. It's looking for a non-NULL 1547 // receiver to know when to enable the regular fall-through path 1548 // in addition to the NullPtrException path 1549 if (m->is_Call()) { 1550 for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { 1551 Node* p = m->fast_out(i2); // Propagate changes to uses 1552 if (p->is_Proj() && p->as_Proj()->_con == TypeFunc::Control && p->outcnt() == 1) 1553 worklist.push(p->unique_out()); 1554 } 1555 } 1556 if( m->bottom_type() != type(m) ) // If not already bottomed out 1557 worklist.push(m); // Propagate change to user 1558 } 1559 } 1560 } 1561 } 1562 1563 //------------------------------do_transform----------------------------------- 1564 // Top level driver for the recursive transformer 1565 void PhaseCCP::do_transform() { 1566 // Correct leaves of new-space Nodes; they point to old-space. 1567 C->set_root( transform(C->root())->as_Root() ); 1568 assert( C->top(), "missing TOP node" ); 1569 assert( C->root(), "missing root" ); 1570 1571 // Eagerly remove castPP nodes here. CastPP nodes might not be 1572 // removed in the subsequent IGVN phase if a node that changes 1573 // in(1) of a castPP is processed prior to the castPP node. 1574 for (uint i = 0; i < _worklist.size(); i++) { 1575 Node* n = _worklist.at(i); 1576 1577 if (n->is_ConstraintCast()) { 1578 Node* nn = n->Identity(this); 1579 if (nn != n) { 1580 replace_node(n, nn); 1581 --i; 1582 } 1583 } 1584 } 1585 } 1586 1587 //------------------------------transform-------------------------------------- 1588 // Given a Node in old-space, clone him into new-space. 1589 // Convert any of his old-space children into new-space children. 1590 Node *PhaseCCP::transform( Node *n ) { 1591 Node *new_node = _nodes[n->_idx]; // Check for transformed node 1592 if( new_node != NULL ) 1593 return new_node; // Been there, done that, return old answer 1594 new_node = transform_once(n); // Check for constant 1595 _nodes.map( n->_idx, new_node ); // Flag as having been cloned 1596 1597 // Allocate stack of size _nodes.Size()/2 to avoid frequent realloc 1598 GrowableArray <Node *> trstack(C->unique() >> 1); 1599 1600 trstack.push(new_node); // Process children of cloned node 1601 while ( trstack.is_nonempty() ) { 1602 Node *clone = trstack.pop(); 1603 uint cnt = clone->req(); 1604 for( uint i = 0; i < cnt; i++ ) { // For all inputs do 1605 Node *input = clone->in(i); 1606 if( input != NULL ) { // Ignore NULLs 1607 Node *new_input = _nodes[input->_idx]; // Check for cloned input node 1608 if( new_input == NULL ) { 1609 new_input = transform_once(input); // Check for constant 1610 _nodes.map( input->_idx, new_input );// Flag as having been cloned 1611 trstack.push(new_input); 1612 } 1613 assert( new_input == clone->in(i), "insanity check"); 1614 } 1615 } 1616 } 1617 return new_node; 1618 } 1619 1620 1621 //------------------------------transform_once--------------------------------- 1622 // For PhaseCCP, transformation is IDENTITY unless Node computed a constant. 1623 Node *PhaseCCP::transform_once( Node *n ) { 1624 const Type *t = type(n); 1625 // Constant? Use constant Node instead 1626 if( t->singleton() ) { 1627 Node *nn = n; // Default is to return the original constant 1628 if( t == Type::TOP ) { 1629 // cache my top node on the Compile instance 1630 if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) { 1631 C->set_cached_top_node( ConNode::make(C, Type::TOP) ); 1632 set_type(C->top(), Type::TOP); 1633 } 1634 nn = C->top(); 1635 } 1636 if( !n->is_Con() ) { 1637 if( t != Type::TOP ) { 1638 nn = makecon(t); // ConNode::make(t); 1639 NOT_PRODUCT( inc_constants(); ) 1640 } else if( n->is_Region() ) { // Unreachable region 1641 // Note: nn == C->top() 1642 n->set_req(0, NULL); // Cut selfreference 1643 // Eagerly remove dead phis to avoid phis copies creation. 1644 for (DUIterator i = n->outs(); n->has_out(i); i++) { 1645 Node* m = n->out(i); 1646 if( m->is_Phi() ) { 1647 assert(type(m) == Type::TOP, "Unreachable region should not have live phis."); 1648 replace_node(m, nn); 1649 --i; // deleted this phi; rescan starting with next position 1650 } 1651 } 1652 } 1653 replace_node(n,nn); // Update DefUse edges for new constant 1654 } 1655 return nn; 1656 } 1657 1658 // If x is a TypeNode, capture any more-precise type permanently into Node 1659 if (t != n->bottom_type()) { 1660 hash_delete(n); // changing bottom type may force a rehash 1661 n->raise_bottom_type(t); 1662 _worklist.push(n); // n re-enters the hash table via the worklist 1663 } 1664 1665 // Idealize graph using DU info. Must clone() into new-space. 1666 // DU info is generally used to show profitability, progress or safety 1667 // (but generally not needed for correctness). 1668 Node *nn = n->Ideal_DU_postCCP(this); 1669 1670 // TEMPORARY fix to ensure that 2nd GVN pass eliminates NULL checks 1671 switch( n->Opcode() ) { 1672 case Op_FastLock: // Revisit FastLocks for lock coarsening 1673 case Op_If: 1674 case Op_CountedLoopEnd: 1675 case Op_Region: 1676 case Op_Loop: 1677 case Op_CountedLoop: 1678 case Op_Conv2B: 1679 case Op_Opaque1: 1680 case Op_Opaque2: 1681 _worklist.push(n); 1682 break; 1683 default: 1684 break; 1685 } 1686 if( nn ) { 1687 _worklist.push(n); 1688 // Put users of 'n' onto worklist for second igvn transform 1689 add_users_to_worklist(n); 1690 return nn; 1691 } 1692 1693 return n; 1694 } 1695 1696 //---------------------------------saturate------------------------------------ 1697 const Type* PhaseCCP::saturate(const Type* new_type, const Type* old_type, 1698 const Type* limit_type) const { 1699 const Type* wide_type = new_type->widen(old_type, limit_type); 1700 if (wide_type != new_type) { // did we widen? 1701 // If so, we may have widened beyond the limit type. Clip it back down. 1702 new_type = wide_type->filter(limit_type); 1703 } 1704 return new_type; 1705 } 1706 1707 //------------------------------print_statistics------------------------------- 1708 #ifndef PRODUCT 1709 void PhaseCCP::print_statistics() { 1710 tty->print_cr("CCP: %d constants found: %d", _total_invokes, _total_constants); 1711 } 1712 #endif 1713 1714 1715 //============================================================================= 1716 #ifndef PRODUCT 1717 uint PhasePeephole::_total_peepholes = 0; 1718 #endif 1719 //------------------------------PhasePeephole---------------------------------- 1720 // Conditional Constant Propagation, ala Wegman & Zadeck 1721 PhasePeephole::PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg ) 1722 : PhaseTransform(Peephole), _regalloc(regalloc), _cfg(cfg) { 1723 NOT_PRODUCT( clear_peepholes(); ) 1724 } 1725 1726 #ifndef PRODUCT 1727 //------------------------------~PhasePeephole--------------------------------- 1728 PhasePeephole::~PhasePeephole() { 1729 _total_peepholes += count_peepholes(); 1730 } 1731 #endif 1732 1733 //------------------------------transform-------------------------------------- 1734 Node *PhasePeephole::transform( Node *n ) { 1735 ShouldNotCallThis(); 1736 return NULL; 1737 } 1738 1739 //------------------------------do_transform----------------------------------- 1740 void PhasePeephole::do_transform() { 1741 bool method_name_not_printed = true; 1742 1743 // Examine each basic block 1744 for (uint block_number = 1; block_number < _cfg.number_of_blocks(); ++block_number) { 1745 Block* block = _cfg.get_block(block_number); 1746 bool block_not_printed = true; 1747 1748 // and each instruction within a block 1749 uint end_index = block->number_of_nodes(); 1750 // block->end_idx() not valid after PhaseRegAlloc 1751 for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) { 1752 Node *n = block->get_node(instruction_index); 1753 if( n->is_Mach() ) { 1754 MachNode *m = n->as_Mach(); 1755 int deleted_count = 0; 1756 // check for peephole opportunities 1757 MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count, C ); 1758 if( m2 != NULL ) { 1759 #ifndef PRODUCT 1760 if( PrintOptoPeephole ) { 1761 // Print method, first time only 1762 if( C->method() && method_name_not_printed ) { 1763 C->method()->print_short_name(); tty->cr(); 1764 method_name_not_printed = false; 1765 } 1766 // Print this block 1767 if( Verbose && block_not_printed) { 1768 tty->print_cr("in block"); 1769 block->dump(); 1770 block_not_printed = false; 1771 } 1772 // Print instructions being deleted 1773 for( int i = (deleted_count - 1); i >= 0; --i ) { 1774 block->get_node(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr(); 1775 } 1776 tty->print_cr("replaced with"); 1777 // Print new instruction 1778 m2->format(_regalloc); 1779 tty->print("\n\n"); 1780 } 1781 #endif 1782 // Remove old nodes from basic block and update instruction_index 1783 // (old nodes still exist and may have edges pointing to them 1784 // as register allocation info is stored in the allocator using 1785 // the node index to live range mappings.) 1786 uint safe_instruction_index = (instruction_index - deleted_count); 1787 for( ; (instruction_index > safe_instruction_index); --instruction_index ) { 1788 block->remove_node( instruction_index ); 1789 } 1790 // install new node after safe_instruction_index 1791 block->insert_node(m2, safe_instruction_index + 1); 1792 end_index = block->number_of_nodes() - 1; // Recompute new block size 1793 NOT_PRODUCT( inc_peepholes(); ) 1794 } 1795 } 1796 } 1797 } 1798 } 1799 1800 //------------------------------print_statistics------------------------------- 1801 #ifndef PRODUCT 1802 void PhasePeephole::print_statistics() { 1803 tty->print_cr("Peephole: peephole rules applied: %d", _total_peepholes); 1804 } 1805 #endif 1806 1807 1808 //============================================================================= 1809 //------------------------------set_req_X-------------------------------------- 1810 void Node::set_req_X( uint i, Node *n, PhaseIterGVN *igvn ) { 1811 assert( is_not_dead(n), "can not use dead node"); 1812 assert( igvn->hash_find(this) != this, "Need to remove from hash before changing edges" ); 1813 Node *old = in(i); 1814 set_req(i, n); 1815 1816 // old goes dead? 1817 if( old ) { 1818 switch (old->outcnt()) { 1819 case 0: 1820 // Put into the worklist to kill later. We do not kill it now because the 1821 // recursive kill will delete the current node (this) if dead-loop exists 1822 if (!old->is_top()) 1823 igvn->_worklist.push( old ); 1824 break; 1825 case 1: 1826 if( old->is_Store() || old->has_special_unique_user() ) 1827 igvn->add_users_to_worklist( old ); 1828 break; 1829 case 2: 1830 if( old->is_Store() ) 1831 igvn->add_users_to_worklist( old ); 1832 if( old->Opcode() == Op_Region ) 1833 igvn->_worklist.push(old); 1834 break; 1835 case 3: 1836 if( old->Opcode() == Op_Region ) { 1837 igvn->_worklist.push(old); 1838 igvn->add_users_to_worklist( old ); 1839 } 1840 break; 1841 default: 1842 break; 1843 } 1844 } 1845 1846 } 1847 1848 //-------------------------------replace_by----------------------------------- 1849 // Using def-use info, replace one node for another. Follow the def-use info 1850 // to all users of the OLD node. Then make all uses point to the NEW node. 1851 void Node::replace_by(Node *new_node) { 1852 assert(!is_top(), "top node has no DU info"); 1853 for (DUIterator_Last imin, i = last_outs(imin); i >= imin; ) { 1854 Node* use = last_out(i); 1855 uint uses_found = 0; 1856 for (uint j = 0; j < use->len(); j++) { 1857 if (use->in(j) == this) { 1858 if (j < use->req()) 1859 use->set_req(j, new_node); 1860 else use->set_prec(j, new_node); 1861 uses_found++; 1862 } 1863 } 1864 i -= uses_found; // we deleted 1 or more copies of this edge 1865 } 1866 } 1867 1868 //============================================================================= 1869 //----------------------------------------------------------------------------- 1870 void Type_Array::grow( uint i ) { 1871 if( !_max ) { 1872 _max = 1; 1873 _types = (const Type**)_a->Amalloc( _max * sizeof(Type*) ); 1874 _types[0] = NULL; 1875 } 1876 uint old = _max; 1877 while( i >= _max ) _max <<= 1; // Double to fit 1878 _types = (const Type**)_a->Arealloc( _types, old*sizeof(Type*),_max*sizeof(Type*)); 1879 memset( &_types[old], 0, (_max-old)*sizeof(Type*) ); 1880 } 1881 1882 //------------------------------dump------------------------------------------- 1883 #ifndef PRODUCT 1884 void Type_Array::dump() const { 1885 uint max = Size(); 1886 for( uint i = 0; i < max; i++ ) { 1887 if( _types[i] != NULL ) { 1888 tty->print(" %d\t== ", i); _types[i]->dump(); tty->cr(); 1889 } 1890 } 1891 } 1892 #endif