< 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   if (UseShenandoahGC) {
1319     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1320     in1 = bs->step_over_gc_barrier(in1);
1321   }
1322 #endif
1323   Node *n = new Conv2BNode(in1);
1324   if( flipped )
1325     n = new XorINode( phase->transform(n), phase->intcon(1) );
1326 
1327   return n;
1328 }
1329 
1330 //------------------------------is_cond_add------------------------------------
1331 // Check for simple conditional add pattern:  "(P < Q) ? X+Y : X;"
1332 // To be profitable the control flow has to disappear; there can be no other
1333 // values merging here.  We replace the test-and-branch with:
1334 // "(sgn(P-Q))&Y) + X".  Basically, convert "(P < Q)" into 0 or -1 by
1335 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1336 // Then convert Y to 0-or-Y and finally add.
1337 // This is a key transform for SpecJava _201_compress.
1338 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1339   assert(true_path !=0, "only diamond shape graph expected");
1340 
1341   // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1342   // phi->region->if_proj->ifnode->bool->cmp
1343   RegionNode *region = (RegionNode*)phi->in(0);


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


< prev index next >