< prev index next >

src/share/vm/opto/node.cpp

Print this page




  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 "libadt/vectset.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/cfgnode.hpp"
  29 #include "opto/connode.hpp"
  30 #include "opto/loopnode.hpp"
  31 #include "opto/machnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/node.hpp"
  34 #include "opto/opcodes.hpp"
  35 #include "opto/regmask.hpp"
  36 #include "opto/type.hpp"
  37 #include "utilities/copy.hpp"



  38 
  39 class RegMask;
  40 // #include "phase.hpp"
  41 class PhaseTransform;
  42 class PhaseGVN;
  43 
  44 // Arena we are currently building Nodes in
  45 const uint Node::NotAMachineReg = 0xffff0000;
  46 
  47 #ifndef PRODUCT
  48 extern int nodes_created;
  49 #endif
  50 
  51 #ifdef ASSERT
  52 
  53 //-------------------------- construct_node------------------------------------
  54 // Set a breakpoint here to identify where a particular node index is built.
  55 void Node::verify_construction() {
  56   _debug_orig = NULL;
  57   int old_debug_idx = Compile::debug_idx();


 512   // Set the new input pointer array
 513   n->_in = (Node**)(((char*)n)+s);
 514   // Cannot share the old output pointer array, so kill it
 515   n->_out = NO_OUT_ARRAY;
 516   // And reset the counters to 0
 517   n->_outcnt = 0;
 518   n->_outmax = 0;
 519   // Unlock this guy, since he is not in any hash table.
 520   debug_only(n->_hash_lock = 0);
 521   // Walk the old node's input list to duplicate its edges
 522   uint i;
 523   for( i = 0; i < len(); i++ ) {
 524     Node *x = in(i);
 525     n->_in[i] = x;
 526     if (x != NULL) x->add_out(n);
 527   }
 528   if (is_macro())
 529     C->add_macro_node(n);
 530   if (is_expensive())
 531     C->add_expensive_node(n);




 532   // If the cloned node is a range check dependent CastII, add it to the list.
 533   CastIINode* cast = n->isa_CastII();
 534   if (cast != NULL && cast->has_range_check()) {
 535     C->add_range_check_cast(cast);
 536   }
 537 
 538   n->set_idx(C->next_unique()); // Get new unique index as well
 539   debug_only( n->verify_construction() );
 540   NOT_PRODUCT(nodes_created++);
 541   // Do not patch over the debug_idx of a clone, because it makes it
 542   // impossible to break on the clone's moment of creation.
 543   //debug_only( n->set_debug_idx( debug_idx() ) );
 544 
 545   C->copy_node_notes_to(n, (Node*) this);
 546 
 547   // MachNode clone
 548   uint nopnds;
 549   if (this->is_Mach() && (nopnds = this->as_Mach()->num_opnds()) > 0) {
 550     MachNode *mach  = n->as_Mach();
 551     MachNode *mthis = this->as_Mach();


 645 #ifdef ASSERT
 646     if( edge_end == compile->node_arena()->hwm() )
 647       reclaim_in  += edge_size;
 648 #endif
 649     compile->node_arena()->Afree(_in,edge_size);
 650 
 651     // Free just the object
 652 #ifdef ASSERT
 653     if( ((char*)this) + node_size == compile->node_arena()->hwm() )
 654       reclaim_node+= node_size;
 655 #else
 656     compile->node_arena()->Afree(this,node_size);
 657 #endif
 658   }
 659   if (is_macro()) {
 660     compile->remove_macro_node(this);
 661   }
 662   if (is_expensive()) {
 663     compile->remove_expensive_node(this);
 664   }



 665   CastIINode* cast = isa_CastII();
 666   if (cast != NULL && cast->has_range_check()) {
 667     compile->remove_range_check_cast(cast);
 668   }
 669 
 670   if (is_SafePoint()) {
 671     as_SafePoint()->delete_replaced_nodes();
 672   }
 673 #ifdef ASSERT
 674   // We will not actually delete the storage, but we'll make the node unusable.
 675   *(address*)this = badAddress;  // smash the C++ vtbl, probably
 676   _in = _out = (Node**) badAddress;
 677   _max = _cnt = _outmax = _outcnt = 0;
 678 #endif
 679 }
 680 
 681 //------------------------------grow-------------------------------------------
 682 // Grow the input array, making space for more edges
 683 void Node::grow( uint len ) {
 684   Arena* arena = Compile::current()->node_arena();


 945     if (depth_count >= K) {
 946       orig_p->dump(4);
 947       if (p != orig_p)
 948         p->dump(1);
 949     }
 950     assert(depth_count++ < K, "infinite loop in Node::uncast_helper");
 951 #endif
 952     if (p == NULL || p->req() != 2) {
 953       break;
 954     } else if (p->is_ConstraintCast()) {
 955       p = p->in(1);
 956     } else if (p->is_CheckCastPP()) {
 957       p = p->in(1);
 958     } else {
 959       break;
 960     }
 961   }
 962   return (Node*) p;
 963 }
 964 
















 965 //------------------------------add_prec---------------------------------------
 966 // Add a new precedence input.  Precedence inputs are unordered, with
 967 // duplicates removed and NULLs packed down at the end.
 968 void Node::add_prec( Node *n ) {
 969   assert( is_not_dead(n), "can not use dead node");
 970 
 971   // Check for NULL at end
 972   if( _cnt >= _max || in(_max-1) )
 973     grow( _max+1 );
 974 
 975   // Find a precedence edge to move
 976   uint i = _cnt;
 977   while( in(i) != NULL ) i++;
 978   _in[i] = n;                                // Stuff prec edge over NULL
 979   if ( n != NULL) n->add_out((Node *)this);  // Add mirror edge
 980 }
 981 
 982 //------------------------------rm_prec----------------------------------------
 983 // Remove a precedence input.  Precedence inputs are unordered, with
 984 // duplicates removed and NULLs packed down at the end.


1345             }
1346             nstack.push(use);
1347           } else {
1348             igvn->_worklist.push(use);
1349           }
1350         }
1351         // Refresh the iterator, since any number of kills might have happened.
1352         k = dead->last_outs(kmin);
1353       }
1354     } else { // (dead->outcnt() == 0)
1355       // Done with outputs.
1356       igvn->hash_delete(dead);
1357       igvn->_worklist.remove(dead);
1358       igvn->set_type(dead, Type::TOP);
1359       if (dead->is_macro()) {
1360         igvn->C->remove_macro_node(dead);
1361       }
1362       if (dead->is_expensive()) {
1363         igvn->C->remove_expensive_node(dead);
1364       }



1365       CastIINode* cast = dead->isa_CastII();
1366       if (cast != NULL && cast->has_range_check()) {
1367         igvn->C->remove_range_check_cast(cast);
1368       }
1369       igvn->C->record_dead_node(dead->_idx);
1370       // Kill all inputs to the dead guy
1371       for (uint i=0; i < dead->req(); i++) {
1372         Node *n = dead->in(i);      // Get input to dead guy
1373         if (n != NULL && !n->is_top()) { // Input is valid?
1374           dead->set_req(i, top);    // Smash input away
1375           if (n->outcnt() == 0) {   // Input also goes dead?
1376             if (!n->is_Con())
1377               nstack.push(n);       // Clear it out as well
1378           } else if (n->outcnt() == 1 &&
1379                      n->has_special_unique_user()) {
1380             igvn->add_users_to_worklist( n );
1381           } else if (n->outcnt() <= 2 && n->is_Store()) {
1382             // Push store's uses on worklist to enable folding optimization for
1383             // store/store and store/load to the same address.
1384             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1385             // and remove_globally_dead_node().
1386             igvn->add_users_to_worklist( n );


1387           }
1388         }
1389       }
1390     } // (dead->outcnt() == 0)
1391   }   // while (nstack.size() > 0) for outputs
1392   return;
1393 }
1394 
1395 //------------------------------remove_dead_region-----------------------------
1396 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1397   Node *n = in(0);
1398   if( !n ) return false;
1399   // Lost control into this guy?  I.e., it became unreachable?
1400   // Aggressively kill all unreachable code.
1401   if (can_reshape && n->is_top()) {
1402     kill_dead_code(this, phase->is_IterGVN());
1403     return false; // Node is dead.
1404   }
1405 
1406   if( n->is_Region() && n->as_Region()->is_copy() ) {
1407     Node *m = n->nonnull_req();
1408     set_req(0, m);
1409     return true;
1410   }
1411   return false;
1412 }
1413 
1414 //------------------------------Ideal_DU_postCCP-------------------------------
1415 // Idealize graph, using DU info.  Must clone result into new-space
1416 Node *Node::Ideal_DU_postCCP( PhaseCCP * ) {
1417   return NULL;                 // Default to no change
1418 }
1419 
1420 //------------------------------hash-------------------------------------------
1421 // Hash function over Nodes.
1422 uint Node::hash() const {
1423   uint sum = 0;
1424   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1425     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1426   return (sum>>2) + _cnt + Opcode();
1427 }
1428 
1429 //------------------------------cmp--------------------------------------------
1430 // Compare special parts of simple Nodes
1431 uint Node::cmp( const Node &n ) const {
1432   return 1;                     // Must be same
1433 }
1434 
1435 //------------------------------rematerialize-----------------------------------
1436 // Should we clone rather than spill this instruction?
1437 bool Node::rematerialize() const {
1438   if ( is_Mach() )
1439     return this->as_Mach()->rematerialize();


2086         }
2087       }
2088     }
2089   }
2090   return NULL;
2091 }
2092 
2093 
2094 //--------------------------unique_ctrl_out------------------------------
2095 // Return the unique control out if only one. Null if none or more than one.
2096 Node* Node::unique_ctrl_out() {
2097   Node* found = NULL;
2098   for (uint i = 0; i < outcnt(); i++) {
2099     Node* use = raw_out(i);
2100     if (use->is_CFG() && use != this) {
2101       if (found != NULL) return NULL;
2102       found = use;
2103     }
2104   }
2105   return found;








2106 }
2107 
2108 //=============================================================================
2109 //------------------------------yank-------------------------------------------
2110 // Find and remove
2111 void Node_List::yank( Node *n ) {
2112   uint i;
2113   for( i = 0; i < _cnt; i++ )
2114     if( _nodes[i] == n )
2115       break;
2116 
2117   if( i < _cnt )
2118     _nodes[i] = _nodes[--_cnt];
2119 }
2120 
2121 //------------------------------dump-------------------------------------------
2122 void Node_List::dump() const {
2123 #ifndef PRODUCT
2124   for( uint i = 0; i < _cnt; i++ )
2125     if( _nodes[i] ) {




  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 "libadt/vectset.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/cfgnode.hpp"
  29 #include "opto/connode.hpp"
  30 #include "opto/loopnode.hpp"
  31 #include "opto/machnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/node.hpp"
  34 #include "opto/opcodes.hpp"
  35 #include "opto/regmask.hpp"
  36 #include "opto/type.hpp"
  37 #include "utilities/copy.hpp"
  38 #if INCLUDE_ALL_GCS
  39 #include "gc_implementation/shenandoah/shenandoahSupport.hpp"
  40 #endif
  41 
  42 class RegMask;
  43 // #include "phase.hpp"
  44 class PhaseTransform;
  45 class PhaseGVN;
  46 
  47 // Arena we are currently building Nodes in
  48 const uint Node::NotAMachineReg = 0xffff0000;
  49 
  50 #ifndef PRODUCT
  51 extern int nodes_created;
  52 #endif
  53 
  54 #ifdef ASSERT
  55 
  56 //-------------------------- construct_node------------------------------------
  57 // Set a breakpoint here to identify where a particular node index is built.
  58 void Node::verify_construction() {
  59   _debug_orig = NULL;
  60   int old_debug_idx = Compile::debug_idx();


 515   // Set the new input pointer array
 516   n->_in = (Node**)(((char*)n)+s);
 517   // Cannot share the old output pointer array, so kill it
 518   n->_out = NO_OUT_ARRAY;
 519   // And reset the counters to 0
 520   n->_outcnt = 0;
 521   n->_outmax = 0;
 522   // Unlock this guy, since he is not in any hash table.
 523   debug_only(n->_hash_lock = 0);
 524   // Walk the old node's input list to duplicate its edges
 525   uint i;
 526   for( i = 0; i < len(); i++ ) {
 527     Node *x = in(i);
 528     n->_in[i] = x;
 529     if (x != NULL) x->add_out(n);
 530   }
 531   if (is_macro())
 532     C->add_macro_node(n);
 533   if (is_expensive())
 534     C->add_expensive_node(n);
 535 
 536   if (Opcode() == Op_ShenandoahLoadReferenceBarrier) {
 537     C->add_shenandoah_barrier(reinterpret_cast<ShenandoahLoadReferenceBarrierNode*>(n));
 538   }
 539   // If the cloned node is a range check dependent CastII, add it to the list.
 540   CastIINode* cast = n->isa_CastII();
 541   if (cast != NULL && cast->has_range_check()) {
 542     C->add_range_check_cast(cast);
 543   }
 544 
 545   n->set_idx(C->next_unique()); // Get new unique index as well
 546   debug_only( n->verify_construction() );
 547   NOT_PRODUCT(nodes_created++);
 548   // Do not patch over the debug_idx of a clone, because it makes it
 549   // impossible to break on the clone's moment of creation.
 550   //debug_only( n->set_debug_idx( debug_idx() ) );
 551 
 552   C->copy_node_notes_to(n, (Node*) this);
 553 
 554   // MachNode clone
 555   uint nopnds;
 556   if (this->is_Mach() && (nopnds = this->as_Mach()->num_opnds()) > 0) {
 557     MachNode *mach  = n->as_Mach();
 558     MachNode *mthis = this->as_Mach();


 652 #ifdef ASSERT
 653     if( edge_end == compile->node_arena()->hwm() )
 654       reclaim_in  += edge_size;
 655 #endif
 656     compile->node_arena()->Afree(_in,edge_size);
 657 
 658     // Free just the object
 659 #ifdef ASSERT
 660     if( ((char*)this) + node_size == compile->node_arena()->hwm() )
 661       reclaim_node+= node_size;
 662 #else
 663     compile->node_arena()->Afree(this,node_size);
 664 #endif
 665   }
 666   if (is_macro()) {
 667     compile->remove_macro_node(this);
 668   }
 669   if (is_expensive()) {
 670     compile->remove_expensive_node(this);
 671   }
 672   if (Opcode() == Op_ShenandoahLoadReferenceBarrier) {
 673     compile->remove_shenandoah_barrier(reinterpret_cast<ShenandoahLoadReferenceBarrierNode*>(this));
 674   }
 675   CastIINode* cast = isa_CastII();
 676   if (cast != NULL && cast->has_range_check()) {
 677     compile->remove_range_check_cast(cast);
 678   }
 679 
 680   if (is_SafePoint()) {
 681     as_SafePoint()->delete_replaced_nodes();
 682   }
 683 #ifdef ASSERT
 684   // We will not actually delete the storage, but we'll make the node unusable.
 685   *(address*)this = badAddress;  // smash the C++ vtbl, probably
 686   _in = _out = (Node**) badAddress;
 687   _max = _cnt = _outmax = _outcnt = 0;
 688 #endif
 689 }
 690 
 691 //------------------------------grow-------------------------------------------
 692 // Grow the input array, making space for more edges
 693 void Node::grow( uint len ) {
 694   Arena* arena = Compile::current()->node_arena();


 955     if (depth_count >= K) {
 956       orig_p->dump(4);
 957       if (p != orig_p)
 958         p->dump(1);
 959     }
 960     assert(depth_count++ < K, "infinite loop in Node::uncast_helper");
 961 #endif
 962     if (p == NULL || p->req() != 2) {
 963       break;
 964     } else if (p->is_ConstraintCast()) {
 965       p = p->in(1);
 966     } else if (p->is_CheckCastPP()) {
 967       p = p->in(1);
 968     } else {
 969       break;
 970     }
 971   }
 972   return (Node*) p;
 973 }
 974 
 975 // Find out of current node that matches opcode.
 976 Node* Node::find_out_with(int opcode) {
 977   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 978     Node* use = fast_out(i);
 979     if (use->Opcode() == opcode) {
 980       return use;
 981     }
 982   }
 983   return NULL;
 984 }
 985 
 986 // Return true if the current node has an out that matches opcode.
 987 bool Node::has_out_with(int opcode) {
 988   return (find_out_with(opcode) != NULL);
 989 }
 990 
 991 //------------------------------add_prec---------------------------------------
 992 // Add a new precedence input.  Precedence inputs are unordered, with
 993 // duplicates removed and NULLs packed down at the end.
 994 void Node::add_prec( Node *n ) {
 995   assert( is_not_dead(n), "can not use dead node");
 996 
 997   // Check for NULL at end
 998   if( _cnt >= _max || in(_max-1) )
 999     grow( _max+1 );
1000 
1001   // Find a precedence edge to move
1002   uint i = _cnt;
1003   while( in(i) != NULL ) i++;
1004   _in[i] = n;                                // Stuff prec edge over NULL
1005   if ( n != NULL) n->add_out((Node *)this);  // Add mirror edge
1006 }
1007 
1008 //------------------------------rm_prec----------------------------------------
1009 // Remove a precedence input.  Precedence inputs are unordered, with
1010 // duplicates removed and NULLs packed down at the end.


1371             }
1372             nstack.push(use);
1373           } else {
1374             igvn->_worklist.push(use);
1375           }
1376         }
1377         // Refresh the iterator, since any number of kills might have happened.
1378         k = dead->last_outs(kmin);
1379       }
1380     } else { // (dead->outcnt() == 0)
1381       // Done with outputs.
1382       igvn->hash_delete(dead);
1383       igvn->_worklist.remove(dead);
1384       igvn->set_type(dead, Type::TOP);
1385       if (dead->is_macro()) {
1386         igvn->C->remove_macro_node(dead);
1387       }
1388       if (dead->is_expensive()) {
1389         igvn->C->remove_expensive_node(dead);
1390       }
1391       if (dead->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
1392         igvn->C->remove_shenandoah_barrier(reinterpret_cast<ShenandoahLoadReferenceBarrierNode*>(dead));
1393       }
1394       CastIINode* cast = dead->isa_CastII();
1395       if (cast != NULL && cast->has_range_check()) {
1396         igvn->C->remove_range_check_cast(cast);
1397       }
1398       igvn->C->record_dead_node(dead->_idx);
1399       // Kill all inputs to the dead guy
1400       for (uint i=0; i < dead->req(); i++) {
1401         Node *n = dead->in(i);      // Get input to dead guy
1402         if (n != NULL && !n->is_top()) { // Input is valid?
1403           dead->set_req(i, top);    // Smash input away
1404           if (n->outcnt() == 0) {   // Input also goes dead?
1405             if (!n->is_Con())
1406               nstack.push(n);       // Clear it out as well
1407           } else if (n->outcnt() == 1 &&
1408                      n->has_special_unique_user()) {
1409             igvn->add_users_to_worklist( n );
1410           } else if (n->outcnt() <= 2 && n->is_Store()) {
1411             // Push store's uses on worklist to enable folding optimization for
1412             // store/store and store/load to the same address.
1413             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1414             // and remove_globally_dead_node().
1415             igvn->add_users_to_worklist( n );
1416           } else if (n->Opcode() == Op_AddP && CallLeafNode::has_only_g1_wb_pre_uses(n)) {
1417             igvn->add_users_to_worklist(n);
1418           }
1419         }
1420       }
1421     } // (dead->outcnt() == 0)
1422   }   // while (nstack.size() > 0) for outputs
1423   return;
1424 }
1425 
1426 //------------------------------remove_dead_region-----------------------------
1427 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1428   Node *n = in(0);
1429   if( !n ) return false;
1430   // Lost control into this guy?  I.e., it became unreachable?
1431   // Aggressively kill all unreachable code.
1432   if (can_reshape && n->is_top()) {
1433     kill_dead_code(this, phase->is_IterGVN());
1434     return false; // Node is dead.
1435   }
1436 
1437   if( n->is_Region() && n->as_Region()->is_copy() ) {
1438     Node *m = n->nonnull_req();
1439     set_req(0, m);
1440     return true;
1441   }
1442   return false;
1443 }
1444 






1445 //------------------------------hash-------------------------------------------
1446 // Hash function over Nodes.
1447 uint Node::hash() const {
1448   uint sum = 0;
1449   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1450     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1451   return (sum>>2) + _cnt + Opcode();
1452 }
1453 
1454 //------------------------------cmp--------------------------------------------
1455 // Compare special parts of simple Nodes
1456 uint Node::cmp( const Node &n ) const {
1457   return 1;                     // Must be same
1458 }
1459 
1460 //------------------------------rematerialize-----------------------------------
1461 // Should we clone rather than spill this instruction?
1462 bool Node::rematerialize() const {
1463   if ( is_Mach() )
1464     return this->as_Mach()->rematerialize();


2111         }
2112       }
2113     }
2114   }
2115   return NULL;
2116 }
2117 
2118 
2119 //--------------------------unique_ctrl_out------------------------------
2120 // Return the unique control out if only one. Null if none or more than one.
2121 Node* Node::unique_ctrl_out() {
2122   Node* found = NULL;
2123   for (uint i = 0; i < outcnt(); i++) {
2124     Node* use = raw_out(i);
2125     if (use->is_CFG() && use != this) {
2126       if (found != NULL) return NULL;
2127       found = use;
2128     }
2129   }
2130   return found;
2131 }
2132 
2133 void Node::ensure_control_or_add_prec(Node* c) {
2134   if (in(0) == NULL) {
2135     set_req(0, c);
2136   } else if (in(0) != c) {
2137     add_prec(c);
2138   }
2139 }
2140 
2141 //=============================================================================
2142 //------------------------------yank-------------------------------------------
2143 // Find and remove
2144 void Node_List::yank( Node *n ) {
2145   uint i;
2146   for( i = 0; i < _cnt; i++ )
2147     if( _nodes[i] == n )
2148       break;
2149 
2150   if( i < _cnt )
2151     _nodes[i] = _nodes[--_cnt];
2152 }
2153 
2154 //------------------------------dump-------------------------------------------
2155 void Node_List::dump() const {
2156 #ifndef PRODUCT
2157   for( uint i = 0; i < _cnt; i++ )
2158     if( _nodes[i] ) {


< prev index next >