< prev index next >

src/share/vm/opto/ifnode.cpp

Print this page
rev 10293 : 8150720: Cleanup code around PrintOptoStatistics
Reviewed-by: TBD


  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciTypeFlow.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/castnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/rootnode.hpp"
  36 #include "opto/subnode.hpp"
  37 
  38 // Portions of code courtesy of Clifford Click
  39 
  40 // Optimization - Graph Style
  41 
  42 

  43 extern int explicit_null_checks_elided;

  44 
  45 //=============================================================================
  46 //------------------------------Value------------------------------------------
  47 // Return a tuple for whichever arm of the IF is reachable
  48 const Type* IfNode::Value(PhaseGVN* phase) const {
  49   if( !in(0) ) return Type::TOP;
  50   if( phase->type(in(0)) == Type::TOP )
  51     return Type::TOP;
  52   const Type *t = phase->type(in(1));
  53   if( t == Type::TOP )          // data is undefined
  54     return TypeTuple::IFNEITHER; // unreachable altogether
  55   if( t == TypeInt::ZERO )      // zero, or false
  56     return TypeTuple::IFFALSE;  // only false branch is reachable
  57   if( t == TypeInt::ONE )       // 1, or true
  58     return TypeTuple::IFTRUE;   // only true branch is reachable
  59   assert( t == TypeInt::BOOL, "expected boolean type" );
  60 
  61   return TypeTuple::IFBOTH;     // No progress
  62 }
  63 


1503   Node* dom = in(0);
1504   Node* prev_dom = this;
1505   int op = Opcode();
1506   // Search up the dominator tree for an If with an identical test
1507   while( dom->Opcode() != op    ||  // Not same opcode?
1508          dom->in(1)    != in(1) ||  // Not same input 1?
1509          (req() == 3 && dom->in(2) != in(2)) || // Not same input 2?
1510          prev_dom->in(0) != dom ) { // One path of test does not dominate?
1511     if( dist < 0 ) return NULL;
1512 
1513     dist--;
1514     prev_dom = dom;
1515     dom = up_one_dom( dom );
1516     if( !dom ) return NULL;
1517   }
1518 
1519   // Check that we did not follow a loop back to ourselves
1520   if( this == dom )
1521     return NULL;
1522 

1523   if( dist > 2 )              // Add to count of NULL checks elided
1524     explicit_null_checks_elided++;

1525 
1526   return prev_dom;
1527 }
1528 
1529 //------------------------------Identity---------------------------------------
1530 // If the test is constant & we match, then we are the input Control
1531 Node* IfProjNode::Identity(PhaseGVN* phase) {
1532   // Can only optimize if cannot go the other way
1533   const TypeTuple *t = phase->type(in(0))->is_tuple();
1534   if (t == TypeTuple::IFNEITHER || (always_taken(t) &&
1535        // During parsing (GVN) we don't remove dead code aggressively.
1536        // Cut off dead branch and let PhaseRemoveUseless take care of it.
1537       (!phase->is_IterGVN() ||
1538        // During IGVN, first wait for the dead branch to be killed.
1539        // Otherwise, the IfNode's control will have two control uses (the IfNode
1540        // that doesn't go away because it still has uses and this branch of the
1541        // If) which breaks other optimizations. Node::has_special_unique_user()
1542        // will cause this node to be reprocessed once the dead branch is killed.
1543        in(0)->outcnt() == 1))) {
1544     // IfNode control




  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciTypeFlow.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/castnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/rootnode.hpp"
  36 #include "opto/subnode.hpp"
  37 
  38 // Portions of code courtesy of Clifford Click
  39 
  40 // Optimization - Graph Style
  41 
  42 
  43 #ifndef PRODUCT
  44 extern int explicit_null_checks_elided;
  45 #endif
  46 
  47 //=============================================================================
  48 //------------------------------Value------------------------------------------
  49 // Return a tuple for whichever arm of the IF is reachable
  50 const Type* IfNode::Value(PhaseGVN* phase) const {
  51   if( !in(0) ) return Type::TOP;
  52   if( phase->type(in(0)) == Type::TOP )
  53     return Type::TOP;
  54   const Type *t = phase->type(in(1));
  55   if( t == Type::TOP )          // data is undefined
  56     return TypeTuple::IFNEITHER; // unreachable altogether
  57   if( t == TypeInt::ZERO )      // zero, or false
  58     return TypeTuple::IFFALSE;  // only false branch is reachable
  59   if( t == TypeInt::ONE )       // 1, or true
  60     return TypeTuple::IFTRUE;   // only true branch is reachable
  61   assert( t == TypeInt::BOOL, "expected boolean type" );
  62 
  63   return TypeTuple::IFBOTH;     // No progress
  64 }
  65 


1505   Node* dom = in(0);
1506   Node* prev_dom = this;
1507   int op = Opcode();
1508   // Search up the dominator tree for an If with an identical test
1509   while( dom->Opcode() != op    ||  // Not same opcode?
1510          dom->in(1)    != in(1) ||  // Not same input 1?
1511          (req() == 3 && dom->in(2) != in(2)) || // Not same input 2?
1512          prev_dom->in(0) != dom ) { // One path of test does not dominate?
1513     if( dist < 0 ) return NULL;
1514 
1515     dist--;
1516     prev_dom = dom;
1517     dom = up_one_dom( dom );
1518     if( !dom ) return NULL;
1519   }
1520 
1521   // Check that we did not follow a loop back to ourselves
1522   if( this == dom )
1523     return NULL;
1524 
1525 #ifndef PRODUCT
1526   if( dist > 2 )              // Add to count of NULL checks elided
1527     explicit_null_checks_elided++;
1528 #endif
1529 
1530   return prev_dom;
1531 }
1532 
1533 //------------------------------Identity---------------------------------------
1534 // If the test is constant & we match, then we are the input Control
1535 Node* IfProjNode::Identity(PhaseGVN* phase) {
1536   // Can only optimize if cannot go the other way
1537   const TypeTuple *t = phase->type(in(0))->is_tuple();
1538   if (t == TypeTuple::IFNEITHER || (always_taken(t) &&
1539        // During parsing (GVN) we don't remove dead code aggressively.
1540        // Cut off dead branch and let PhaseRemoveUseless take care of it.
1541       (!phase->is_IterGVN() ||
1542        // During IGVN, first wait for the dead branch to be killed.
1543        // Otherwise, the IfNode's control will have two control uses (the IfNode
1544        // that doesn't go away because it still has uses and this branch of the
1545        // If) which breaks other optimizations. Node::has_special_unique_user()
1546        // will cause this node to be reprocessed once the dead branch is killed.
1547        in(0)->outcnt() == 1))) {
1548     // IfNode control


< prev index next >