< prev index next >

src/share/vm/opto/cfgnode.cpp

Print this page




  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 "classfile/systemDictionary.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "oops/objArrayKlass.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/phaseX.hpp"
  36 #include "opto/regmask.hpp"
  37 #include "opto/runtime.hpp"
  38 #include "opto/subnode.hpp"




  39 
  40 // Portions of code courtesy of Clifford Click
  41 
  42 // Optimization - Graph Style
  43 
  44 //=============================================================================
  45 //------------------------------Value------------------------------------------
  46 // Compute the type of the RegionNode.
  47 const Type *RegionNode::Value( PhaseTransform *phase ) const {
  48   for( uint i=1; i<req(); ++i ) {       // For all paths in
  49     Node *n = in(i);            // Get Control source
  50     if( !n ) continue;          // Missing inputs are TOP
  51     if( phase->type(n) == Type::CONTROL )
  52       return Type::CONTROL;
  53   }
  54   return Type::TOP;             // All paths dead?  Then so are we
  55 }
  56 
  57 //------------------------------Identity---------------------------------------
  58 // Check for Region being Identity.


 571         assert(parent_ctrl != NULL, "Region is a copy of some non-null control");
 572         assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");
 573       }
 574       if (!add_to_worklist)
 575         igvn->add_users_to_worklist(this); // Check for further allowed opts
 576       for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
 577         Node* n = last_out(i);
 578         igvn->hash_delete(n); // Remove from worklist before modifying edges
 579         if( n->is_Phi() ) {   // Collapse all Phis
 580           // Eagerly replace phis to avoid copies generation.
 581           Node* in;
 582           if( cnt == 0 ) {
 583             assert( n->req() == 1, "No data inputs expected" );
 584             in = parent_ctrl; // replaced by top
 585           } else {
 586             assert( n->req() == 2 &&  n->in(1) != NULL, "Only one data input expected" );
 587             in = n->in(1);               // replaced by unique input
 588             if( n->as_Phi()->is_unsafe_data_reference(in) )
 589               in = phase->C->top();      // replaced by top
 590           }



 591           igvn->replace_node(n, in);
 592         }
 593         else if( n->is_Region() ) { // Update all incoming edges
 594           assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");
 595           uint uses_found = 0;
 596           for( uint k=1; k < n->req(); k++ ) {
 597             if( n->in(k) == this ) {
 598               n->set_req(k, parent_ctrl);
 599               uses_found++;
 600             }
 601           }
 602           if( uses_found > 1 ) { // (--i) done at the end of the loop.
 603             i -= (uses_found - 1);
 604           }
 605         }
 606         else {
 607           assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");
 608           n->set_req(0, parent_ctrl);
 609         }
 610 #ifdef ASSERT


1245     flipped = 1-flipped;        // Test is vs 1 instead of 0!
1246   }
1247 
1248   // Check for setting zero/one opposite expected
1249   if( tzero == TypeInt::ZERO ) {
1250     if( tone == TypeInt::ONE ) {
1251     } else return NULL;
1252   } else if( tzero == TypeInt::ONE ) {
1253     if( tone == TypeInt::ZERO ) {
1254       flipped = 1-flipped;
1255     } else return NULL;
1256   } else return NULL;
1257 
1258   // Check for boolean test backwards
1259   if( b->_test._test == BoolTest::ne ) {
1260   } else if( b->_test._test == BoolTest::eq ) {
1261     flipped = 1-flipped;
1262   } else return NULL;
1263 
1264   // Build int->bool conversion
1265   Node *n = new (phase->C) Conv2BNode( cmp->in(1) );






1266   if( flipped )
1267     n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
1268 
1269   return n;
1270 }
1271 
1272 //------------------------------is_cond_add------------------------------------
1273 // Check for simple conditional add pattern:  "(P < Q) ? X+Y : X;"
1274 // To be profitable the control flow has to disappear; there can be no other
1275 // values merging here.  We replace the test-and-branch with:
1276 // "(sgn(P-Q))&Y) + X".  Basically, convert "(P < Q)" into 0 or -1 by
1277 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1278 // Then convert Y to 0-or-Y and finally add.
1279 // This is a key transform for SpecJava _201_compress.
1280 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1281   assert(true_path !=0, "only diamond shape graph expected");
1282 
1283   // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1284   // phi->region->if_proj->ifnode->bool->cmp
1285   RegionNode *region = (RegionNode*)phi->in(0);


1611   // No change for igvn if new phi is not hooked
1612   if (new_phi && can_reshape)
1613     return NULL;
1614 
1615   // The are 2 situations when only one valid phi's input is left
1616   // (in addition to Region input).
1617   // One: region is not loop - replace phi with this input.
1618   // Two: region is loop - replace phi with top since this data path is dead
1619   //                       and we need to break the dead data loop.
1620   Node* progress = NULL;        // Record if any progress made
1621   for( uint j = 1; j < req(); ++j ){ // For all paths in
1622     // Check unreachable control paths
1623     Node* rc = r->in(j);
1624     Node* n = in(j);            // Get the input
1625     if (rc == NULL || phase->type(rc) == Type::TOP) {
1626       if (n != top) {           // Not already top?
1627         PhaseIterGVN *igvn = phase->is_IterGVN();
1628         if (can_reshape && igvn != NULL) {
1629           igvn->_worklist.push(r);
1630         }
1631         set_req(j, top);        // Nuke it down





1632         progress = this;        // Record progress
1633       }
1634     }
1635   }
1636 
1637   if (can_reshape && outcnt() == 0) {
1638     // set_req() above may kill outputs if Phi is referenced
1639     // only by itself on the dead (top) control path.
1640     return top;
1641   }
1642 
1643   Node* uin = unique_input(phase);
1644   if (uin == top) {             // Simplest case: no alive inputs.
1645     if (can_reshape)            // IGVN transformation
1646       return top;
1647     else
1648       return NULL;              // Identity will return TOP
1649   } else if (uin != NULL) {
1650     // Only one not-NULL unique input path is left.
1651     // Determine if this input is backedge of a loop.




  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 "classfile/systemDictionary.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "oops/objArrayKlass.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/phaseX.hpp"
  36 #include "opto/regmask.hpp"
  37 #include "opto/runtime.hpp"
  38 #include "opto/subnode.hpp"
  39 #if INCLUDE_ALL_GCS
  40 #include "gc_implementation/shenandoah/shenandoahBarrierSetC2.hpp"
  41 #include "gc_implementation/shenandoah/shenandoahSupport.hpp"
  42 #endif
  43 
  44 // Portions of code courtesy of Clifford Click
  45 
  46 // Optimization - Graph Style
  47 
  48 //=============================================================================
  49 //------------------------------Value------------------------------------------
  50 // Compute the type of the RegionNode.
  51 const Type *RegionNode::Value( PhaseTransform *phase ) const {
  52   for( uint i=1; i<req(); ++i ) {       // For all paths in
  53     Node *n = in(i);            // Get Control source
  54     if( !n ) continue;          // Missing inputs are TOP
  55     if( phase->type(n) == Type::CONTROL )
  56       return Type::CONTROL;
  57   }
  58   return Type::TOP;             // All paths dead?  Then so are we
  59 }
  60 
  61 //------------------------------Identity---------------------------------------
  62 // Check for Region being Identity.


 575         assert(parent_ctrl != NULL, "Region is a copy of some non-null control");
 576         assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");
 577       }
 578       if (!add_to_worklist)
 579         igvn->add_users_to_worklist(this); // Check for further allowed opts
 580       for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
 581         Node* n = last_out(i);
 582         igvn->hash_delete(n); // Remove from worklist before modifying edges
 583         if( n->is_Phi() ) {   // Collapse all Phis
 584           // Eagerly replace phis to avoid copies generation.
 585           Node* in;
 586           if( cnt == 0 ) {
 587             assert( n->req() == 1, "No data inputs expected" );
 588             in = parent_ctrl; // replaced by top
 589           } else {
 590             assert( n->req() == 2 &&  n->in(1) != NULL, "Only one data input expected" );
 591             in = n->in(1);               // replaced by unique input
 592             if( n->as_Phi()->is_unsafe_data_reference(in) )
 593               in = phase->C->top();      // replaced by top
 594           }
 595           if (n->outcnt() == 0) {
 596             in = phase->C->top();
 597           }
 598           igvn->replace_node(n, in);
 599         }
 600         else if( n->is_Region() ) { // Update all incoming edges
 601           assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");
 602           uint uses_found = 0;
 603           for( uint k=1; k < n->req(); k++ ) {
 604             if( n->in(k) == this ) {
 605               n->set_req(k, parent_ctrl);
 606               uses_found++;
 607             }
 608           }
 609           if( uses_found > 1 ) { // (--i) done at the end of the loop.
 610             i -= (uses_found - 1);
 611           }
 612         }
 613         else {
 614           assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");
 615           n->set_req(0, parent_ctrl);
 616         }
 617 #ifdef ASSERT


1252     flipped = 1-flipped;        // Test is vs 1 instead of 0!
1253   }
1254 
1255   // Check for setting zero/one opposite expected
1256   if( tzero == TypeInt::ZERO ) {
1257     if( tone == TypeInt::ONE ) {
1258     } else return NULL;
1259   } else if( tzero == TypeInt::ONE ) {
1260     if( tone == TypeInt::ZERO ) {
1261       flipped = 1-flipped;
1262     } else return NULL;
1263   } else return NULL;
1264 
1265   // Check for boolean test backwards
1266   if( b->_test._test == BoolTest::ne ) {
1267   } else if( b->_test._test == BoolTest::eq ) {
1268     flipped = 1-flipped;
1269   } else return NULL;
1270 
1271   // Build int->bool conversion
1272   Node* in1 = cmp->in(1);
1273 #if INCLUDE_ALL_GCS
1274   if (UseShenandoahGC) {
1275     in1 = ShenandoahBarrierSetC2::bsc2()->step_over_gc_barrier(in1);
1276   }
1277 #endif
1278   Node *n = new (phase->C) Conv2BNode(in1);
1279   if( flipped )
1280     n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
1281 
1282   return n;
1283 }
1284 
1285 //------------------------------is_cond_add------------------------------------
1286 // Check for simple conditional add pattern:  "(P < Q) ? X+Y : X;"
1287 // To be profitable the control flow has to disappear; there can be no other
1288 // values merging here.  We replace the test-and-branch with:
1289 // "(sgn(P-Q))&Y) + X".  Basically, convert "(P < Q)" into 0 or -1 by
1290 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1291 // Then convert Y to 0-or-Y and finally add.
1292 // This is a key transform for SpecJava _201_compress.
1293 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1294   assert(true_path !=0, "only diamond shape graph expected");
1295 
1296   // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1297   // phi->region->if_proj->ifnode->bool->cmp
1298   RegionNode *region = (RegionNode*)phi->in(0);


1624   // No change for igvn if new phi is not hooked
1625   if (new_phi && can_reshape)
1626     return NULL;
1627 
1628   // The are 2 situations when only one valid phi's input is left
1629   // (in addition to Region input).
1630   // One: region is not loop - replace phi with this input.
1631   // Two: region is loop - replace phi with top since this data path is dead
1632   //                       and we need to break the dead data loop.
1633   Node* progress = NULL;        // Record if any progress made
1634   for( uint j = 1; j < req(); ++j ){ // For all paths in
1635     // Check unreachable control paths
1636     Node* rc = r->in(j);
1637     Node* n = in(j);            // Get the input
1638     if (rc == NULL || phase->type(rc) == Type::TOP) {
1639       if (n != top) {           // Not already top?
1640         PhaseIterGVN *igvn = phase->is_IterGVN();
1641         if (can_reshape && igvn != NULL) {
1642           igvn->_worklist.push(r);
1643         }
1644         // Nuke it down
1645         if (can_reshape) {
1646           set_req_X(j, top, igvn);
1647         } else {
1648           set_req(j, top);
1649         }
1650         progress = this;        // Record progress
1651       }
1652     }
1653   }
1654 
1655   if (can_reshape && outcnt() == 0) {
1656     // set_req() above may kill outputs if Phi is referenced
1657     // only by itself on the dead (top) control path.
1658     return top;
1659   }
1660 
1661   Node* uin = unique_input(phase);
1662   if (uin == top) {             // Simplest case: no alive inputs.
1663     if (can_reshape)            // IGVN transformation
1664       return top;
1665     else
1666       return NULL;              // Identity will return TOP
1667   } else if (uin != NULL) {
1668     // Only one not-NULL unique input path is left.
1669     // Determine if this input is backedge of a loop.


< prev index next >