< prev index next >

src/hotspot/share/opto/cfgnode.cpp

Print this page




  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/objArrayKlass.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/convertnode.hpp"
  35 #include "opto/loopnode.hpp"
  36 #include "opto/machnode.hpp"
  37 #include "opto/movenode.hpp"
  38 #include "opto/narrowptrnode.hpp"
  39 #include "opto/mulnode.hpp"
  40 #include "opto/phaseX.hpp"
  41 #include "opto/regmask.hpp"
  42 #include "opto/runtime.hpp"
  43 #include "opto/subnode.hpp"
  44 #include "utilities/vmError.hpp"




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


 597         assert(parent_ctrl != NULL, "Region is a copy of some non-null control");
 598         assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");
 599       }
 600       if (!add_to_worklist)
 601         igvn->add_users_to_worklist(this); // Check for further allowed opts
 602       for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
 603         Node* n = last_out(i);
 604         igvn->hash_delete(n); // Remove from worklist before modifying edges
 605         if( n->is_Phi() ) {   // Collapse all Phis
 606           // Eagerly replace phis to avoid copies generation.
 607           Node* in;
 608           if( cnt == 0 ) {
 609             assert( n->req() == 1, "No data inputs expected" );
 610             in = parent_ctrl; // replaced by top
 611           } else {
 612             assert( n->req() == 2 &&  n->in(1) != NULL, "Only one data input expected" );
 613             in = n->in(1);               // replaced by unique input
 614             if( n->as_Phi()->is_unsafe_data_reference(in) )
 615               in = phase->C->top();      // replaced by top
 616           }



 617           igvn->replace_node(n, in);
 618         }
 619         else if( n->is_Region() ) { // Update all incoming edges
 620           assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");
 621           uint uses_found = 0;
 622           for( uint k=1; k < n->req(); k++ ) {
 623             if( n->in(k) == this ) {
 624               n->set_req(k, parent_ctrl);
 625               uses_found++;
 626             }
 627           }
 628           if( uses_found > 1 ) { // (--i) done at the end of the loop.
 629             i -= (uses_found - 1);
 630           }
 631         }
 632         else {
 633           assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");
 634           n->set_req(0, parent_ctrl);
 635         }
 636 #ifdef ASSERT


1288       return NULL;
1289     flipped = 1-flipped;        // Test is vs 1 instead of 0!
1290   }
1291 
1292   // Check for setting zero/one opposite expected
1293   if( tzero == TypeInt::ZERO ) {
1294     if( tone == TypeInt::ONE ) {
1295     } else return NULL;
1296   } else if( tzero == TypeInt::ONE ) {
1297     if( tone == TypeInt::ZERO ) {
1298       flipped = 1-flipped;
1299     } else return NULL;
1300   } else return NULL;
1301 
1302   // Check for boolean test backwards
1303   if( b->_test._test == BoolTest::ne ) {
1304   } else if( b->_test._test == BoolTest::eq ) {
1305     flipped = 1-flipped;
1306   } else return NULL;
1307 
1308   // Build int->bool conversion
1309   Node *n = new Conv2BNode( cmp->in(1) );




1310   if( flipped )
1311     n = new XorINode( phase->transform(n), phase->intcon(1) );
1312 
1313   return n;
1314 }
1315 
1316 //------------------------------is_cond_add------------------------------------
1317 // Check for simple conditional add pattern:  "(P < Q) ? X+Y : X;"
1318 // To be profitable the control flow has to disappear; there can be no other
1319 // values merging here.  We replace the test-and-branch with:
1320 // "(sgn(P-Q))&Y) + X".  Basically, convert "(P < Q)" into 0 or -1 by
1321 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1322 // Then convert Y to 0-or-Y and finally add.
1323 // This is a key transform for SpecJava _201_compress.
1324 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1325   assert(true_path !=0, "only diamond shape graph expected");
1326 
1327   // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1328   // phi->region->if_proj->ifnode->bool->cmp
1329   RegionNode *region = (RegionNode*)phi->in(0);


1655   // No change for igvn if new phi is not hooked
1656   if (new_phi && can_reshape)
1657     return NULL;
1658 
1659   // The are 2 situations when only one valid phi's input is left
1660   // (in addition to Region input).
1661   // One: region is not loop - replace phi with this input.
1662   // Two: region is loop - replace phi with top since this data path is dead
1663   //                       and we need to break the dead data loop.
1664   Node* progress = NULL;        // Record if any progress made
1665   for( uint j = 1; j < req(); ++j ){ // For all paths in
1666     // Check unreachable control paths
1667     Node* rc = r->in(j);
1668     Node* n = in(j);            // Get the input
1669     if (rc == NULL || phase->type(rc) == Type::TOP) {
1670       if (n != top) {           // Not already top?
1671         PhaseIterGVN *igvn = phase->is_IterGVN();
1672         if (can_reshape && igvn != NULL) {
1673           igvn->_worklist.push(r);
1674         }
1675         set_req(j, top);        // Nuke it down





1676         progress = this;        // Record progress
1677       }
1678     }
1679   }
1680 
1681   if (can_reshape && outcnt() == 0) {
1682     // set_req() above may kill outputs if Phi is referenced
1683     // only by itself on the dead (top) control path.
1684     return top;
1685   }
1686 
1687   bool uncasted = false;
1688   Node* uin = unique_input(phase, false);
1689   if (uin == NULL && can_reshape) {
1690     uncasted = true;
1691     uin = unique_input(phase, true);
1692   }
1693   if (uin == top) {             // Simplest case: no alive inputs.
1694     if (can_reshape)            // IGVN transformation
1695       return top;




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


 601         assert(parent_ctrl != NULL, "Region is a copy of some non-null control");
 602         assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");
 603       }
 604       if (!add_to_worklist)
 605         igvn->add_users_to_worklist(this); // Check for further allowed opts
 606       for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
 607         Node* n = last_out(i);
 608         igvn->hash_delete(n); // Remove from worklist before modifying edges
 609         if( n->is_Phi() ) {   // Collapse all Phis
 610           // Eagerly replace phis to avoid copies generation.
 611           Node* in;
 612           if( cnt == 0 ) {
 613             assert( n->req() == 1, "No data inputs expected" );
 614             in = parent_ctrl; // replaced by top
 615           } else {
 616             assert( n->req() == 2 &&  n->in(1) != NULL, "Only one data input expected" );
 617             in = n->in(1);               // replaced by unique input
 618             if( n->as_Phi()->is_unsafe_data_reference(in) )
 619               in = phase->C->top();      // replaced by top
 620           }
 621           if (UseShenandoahGC && n->outcnt() == 0) {
 622             in = phase->C->top();
 623           }
 624           igvn->replace_node(n, in);
 625         }
 626         else if( n->is_Region() ) { // Update all incoming edges
 627           assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");
 628           uint uses_found = 0;
 629           for( uint k=1; k < n->req(); k++ ) {
 630             if( n->in(k) == this ) {
 631               n->set_req(k, parent_ctrl);
 632               uses_found++;
 633             }
 634           }
 635           if( uses_found > 1 ) { // (--i) done at the end of the loop.
 636             i -= (uses_found - 1);
 637           }
 638         }
 639         else {
 640           assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");
 641           n->set_req(0, parent_ctrl);
 642         }
 643 #ifdef ASSERT


1295       return NULL;
1296     flipped = 1-flipped;        // Test is vs 1 instead of 0!
1297   }
1298 
1299   // Check for setting zero/one opposite expected
1300   if( tzero == TypeInt::ZERO ) {
1301     if( tone == TypeInt::ONE ) {
1302     } else return NULL;
1303   } else if( tzero == TypeInt::ONE ) {
1304     if( tone == TypeInt::ZERO ) {
1305       flipped = 1-flipped;
1306     } else return NULL;
1307   } else return NULL;
1308 
1309   // Check for boolean test backwards
1310   if( b->_test._test == BoolTest::ne ) {
1311   } else if( b->_test._test == BoolTest::eq ) {
1312     flipped = 1-flipped;
1313   } else return NULL;
1314 
1315   // Build int->bool concfgversion
1316   Node *in1 = cmp->in(1);
1317 #if INCLUDE_SHENANDOAHGC
1318   in1 = ShenandoahBarrierNode::skip_through_barrier(in1);
1319 #endif
1320   Node *n = new Conv2BNode(in1);
1321   if( flipped )
1322     n = new XorINode( phase->transform(n), phase->intcon(1) );
1323 
1324   return n;
1325 }
1326 
1327 //------------------------------is_cond_add------------------------------------
1328 // Check for simple conditional add pattern:  "(P < Q) ? X+Y : X;"
1329 // To be profitable the control flow has to disappear; there can be no other
1330 // values merging here.  We replace the test-and-branch with:
1331 // "(sgn(P-Q))&Y) + X".  Basically, convert "(P < Q)" into 0 or -1 by
1332 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1333 // Then convert Y to 0-or-Y and finally add.
1334 // This is a key transform for SpecJava _201_compress.
1335 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1336   assert(true_path !=0, "only diamond shape graph expected");
1337 
1338   // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1339   // phi->region->if_proj->ifnode->bool->cmp
1340   RegionNode *region = (RegionNode*)phi->in(0);


1666   // No change for igvn if new phi is not hooked
1667   if (new_phi && can_reshape)
1668     return NULL;
1669 
1670   // The are 2 situations when only one valid phi's input is left
1671   // (in addition to Region input).
1672   // One: region is not loop - replace phi with this input.
1673   // Two: region is loop - replace phi with top since this data path is dead
1674   //                       and we need to break the dead data loop.
1675   Node* progress = NULL;        // Record if any progress made
1676   for( uint j = 1; j < req(); ++j ){ // For all paths in
1677     // Check unreachable control paths
1678     Node* rc = r->in(j);
1679     Node* n = in(j);            // Get the input
1680     if (rc == NULL || phase->type(rc) == Type::TOP) {
1681       if (n != top) {           // Not already top?
1682         PhaseIterGVN *igvn = phase->is_IterGVN();
1683         if (can_reshape && igvn != NULL) {
1684           igvn->_worklist.push(r);
1685         }
1686         // Nuke it down
1687         if (UseShenandoahGC && can_reshape) {
1688           set_req_X(j, top, igvn);
1689         } else {
1690           set_req(j, top);
1691         }
1692         progress = this;        // Record progress
1693       }
1694     }
1695   }
1696 
1697   if (can_reshape && outcnt() == 0) {
1698     // set_req() above may kill outputs if Phi is referenced
1699     // only by itself on the dead (top) control path.
1700     return top;
1701   }
1702 
1703   bool uncasted = false;
1704   Node* uin = unique_input(phase, false);
1705   if (uin == NULL && can_reshape) {
1706     uncasted = true;
1707     uin = unique_input(phase, true);
1708   }
1709   if (uin == top) {             // Simplest case: no alive inputs.
1710     if (can_reshape)            // IGVN transformation
1711       return top;


< prev index next >