< 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();


 960     if (depth_count >= K) {
 961       orig_p->dump(4);
 962       if (p != orig_p)
 963         p->dump(1);
 964     }
 965     assert(depth_count++ < K, "infinite loop in Node::uncast_helper");
 966 #endif
 967     if (p == NULL || p->req() != 2) {
 968       break;
 969     } else if (p->is_ConstraintCast()) {
 970       p = p->in(1);
 971     } else if (p->is_CheckCastPP()) {
 972       p = p->in(1);
 973     } else {
 974       break;
 975     }
 976   }
 977   return (Node*) p;
 978 }
 979 





 980 //------------------------------add_prec---------------------------------------
 981 // Add a new precedence input.  Precedence inputs are unordered, with
 982 // duplicates removed and NULLs packed down at the end.
 983 void Node::add_prec( Node *n ) {
 984   assert( is_not_dead(n), "can not use dead node");
 985 
 986   // Check for NULL at end
 987   if( _cnt >= _max || in(_max-1) )
 988     grow( _max+1 );
 989 
 990   // Find a precedence edge to move
 991   uint i = _cnt;
 992   while( in(i) != NULL ) {
 993     if (in(i) == n) return; // Avoid spec violation: duplicated prec edge.
 994     i++;
 995   }
 996   _in[i] = n;                                // Stuff prec edge over NULL
 997   if ( n != NULL) n->add_out((Node *)this);  // Add mirror edge
 998 
 999 #ifdef ASSERT


1366             }
1367             nstack.push(use);
1368           } else {
1369             igvn->_worklist.push(use);
1370           }
1371         }
1372         // Refresh the iterator, since any number of kills might have happened.
1373         k = dead->last_outs(kmin);
1374       }
1375     } else { // (dead->outcnt() == 0)
1376       // Done with outputs.
1377       igvn->hash_delete(dead);
1378       igvn->_worklist.remove(dead);
1379       igvn->set_type(dead, Type::TOP);
1380       if (dead->is_macro()) {
1381         igvn->C->remove_macro_node(dead);
1382       }
1383       if (dead->is_expensive()) {
1384         igvn->C->remove_expensive_node(dead);
1385       }



1386       CastIINode* cast = dead->isa_CastII();
1387       if (cast != NULL && cast->has_range_check()) {
1388         igvn->C->remove_range_check_cast(cast);
1389       }
1390       igvn->C->record_dead_node(dead->_idx);
1391       // Kill all inputs to the dead guy
1392       for (uint i=0; i < dead->req(); i++) {
1393         Node *n = dead->in(i);      // Get input to dead guy
1394         if (n != NULL && !n->is_top()) { // Input is valid?
1395           dead->set_req(i, top);    // Smash input away
1396           if (n->outcnt() == 0) {   // Input also goes dead?
1397             if (!n->is_Con())
1398               nstack.push(n);       // Clear it out as well
1399           } else if (n->outcnt() == 1 &&
1400                      n->has_special_unique_user()) {
1401             igvn->add_users_to_worklist( n );
1402           } else if (n->outcnt() <= 2 && n->is_Store()) {
1403             // Push store's uses on worklist to enable folding optimization for
1404             // store/store and store/load to the same address.
1405             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1406             // and remove_globally_dead_node().
1407             igvn->add_users_to_worklist( n );


1408           }
1409         }
1410       }
1411     } // (dead->outcnt() == 0)
1412   }   // while (nstack.size() > 0) for outputs
1413   return;
1414 }
1415 
1416 //------------------------------remove_dead_region-----------------------------
1417 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1418   Node *n = in(0);
1419   if( !n ) return false;
1420   // Lost control into this guy?  I.e., it became unreachable?
1421   // Aggressively kill all unreachable code.
1422   if (can_reshape && n->is_top()) {
1423     kill_dead_code(this, phase->is_IterGVN());
1424     return false; // Node is dead.
1425   }
1426 
1427   if( n->is_Region() && n->as_Region()->is_copy() ) {
1428     Node *m = n->nonnull_req();
1429     set_req(0, m);
1430     return true;
1431   }
1432   return false;
1433 }
1434 
1435 //------------------------------Ideal_DU_postCCP-------------------------------
1436 // Idealize graph, using DU info.  Must clone result into new-space
1437 Node *Node::Ideal_DU_postCCP( PhaseCCP * ) {
1438   return NULL;                 // Default to no change
1439 }
1440 
1441 //------------------------------hash-------------------------------------------
1442 // Hash function over Nodes.
1443 uint Node::hash() const {
1444   uint sum = 0;
1445   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1446     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1447   return (sum>>2) + _cnt + Opcode();
1448 }
1449 
1450 //------------------------------cmp--------------------------------------------
1451 // Compare special parts of simple Nodes
1452 uint Node::cmp( const Node &n ) const {
1453   return 1;                     // Must be same
1454 }
1455 
1456 //------------------------------rematerialize-----------------------------------
1457 // Should we clone rather than spill this instruction?
1458 bool Node::rematerialize() const {
1459   if ( is_Mach() )
1460     return this->as_Mach()->rematerialize();


2107         }
2108       }
2109     }
2110   }
2111   return NULL;
2112 }
2113 
2114 
2115 //--------------------------unique_ctrl_out------------------------------
2116 // Return the unique control out if only one. Null if none or more than one.
2117 Node* Node::unique_ctrl_out() {
2118   Node* found = NULL;
2119   for (uint i = 0; i < outcnt(); i++) {
2120     Node* use = raw_out(i);
2121     if (use->is_CFG() && use != this) {
2122       if (found != NULL) return NULL;
2123       found = use;
2124     }
2125   }
2126   return found;








2127 }
2128 
2129 //=============================================================================
2130 //------------------------------yank-------------------------------------------
2131 // Find and remove
2132 void Node_List::yank( Node *n ) {
2133   uint i;
2134   for( i = 0; i < _cnt; i++ )
2135     if( _nodes[i] == n )
2136       break;
2137 
2138   if( i < _cnt )
2139     _nodes[i] = _nodes[--_cnt];
2140 }
2141 
2142 //------------------------------dump-------------------------------------------
2143 void Node_List::dump() const {
2144 #ifndef PRODUCT
2145   for( uint i = 0; i < _cnt; i++ )
2146     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/c2/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();


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


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






1455 //------------------------------hash-------------------------------------------
1456 // Hash function over Nodes.
1457 uint Node::hash() const {
1458   uint sum = 0;
1459   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1460     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1461   return (sum>>2) + _cnt + Opcode();
1462 }
1463 
1464 //------------------------------cmp--------------------------------------------
1465 // Compare special parts of simple Nodes
1466 uint Node::cmp( const Node &n ) const {
1467   return 1;                     // Must be same
1468 }
1469 
1470 //------------------------------rematerialize-----------------------------------
1471 // Should we clone rather than spill this instruction?
1472 bool Node::rematerialize() const {
1473   if ( is_Mach() )
1474     return this->as_Mach()->rematerialize();


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


< prev index next >