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


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


< prev index next >