< prev index next >

src/hotspot/share/opto/cfgnode.cpp

Print this page




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

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


 355   nstack.push(n);
 356   visited.set(n->_idx);
 357   while (nstack.size() != 0) {
 358     n = nstack.pop();
 359     uint max = n->outcnt();
 360     for (uint i = 0; i < max; i++) {
 361       Node* m = n->raw_out(i);
 362       if (m != NULL && m->is_CFG()) {
 363         if (phase->eqv(m, this)) {
 364           return false; // We reached the Region node - it is not dead.
 365         }
 366         if (!visited.test_set(m->_idx))
 367           nstack.push(m);
 368       }
 369     }
 370   }
 371 
 372   return true; // The Region node is unreachable - it is dead.
 373 }
 374 
 375 bool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {
 376   // Incremental inlining + PhaseStringOpts sometimes produce:
 377   //
 378   // cmpP with 1 top input
 379   //           |
 380   //          If
 381   //         /  \
 382   //   IfFalse  IfTrue  /- Some Node
 383   //         \  /      /    /
 384   //        Region    / /-MergeMem
 385   //             \---Phi
 386   //
 387   //
 388   // It's expected by PhaseStringOpts that the Region goes away and is
 389   // replaced by If's control input but because there's still a Phi,
 390   // the Region stays in the graph. The top input from the cmpP is
 391   // propagated forward and a subgraph that is useful goes away. The
 392   // code below replaces the Phi with the MergeMem so that the Region
 393   // is simplified.
 394 
 395   PhiNode* phi = has_unique_phi();
 396   if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {
 397     MergeMemNode* m = NULL;
 398     assert(phi->req() == 3, "same as region");

 399     for (uint i = 1; i < 3; ++i) {
 400       Node *mem = phi->in(i);
 401       if (mem && mem->is_MergeMem() && in(i)->outcnt() == 1) {
 402         // Nothing is control-dependent on path #i except the region itself.
 403         m = mem->as_MergeMem();
 404         uint j = 3 - i;
 405         Node* other = phi->in(j);
 406         if (other && other == m->base_memory()) {
 407           // m is a successor memory to other, and is not pinned inside the diamond, so push it out.
 408           // This will allow the diamond to collapse completely.
 409           phase->is_IterGVN()->replace_node(phi, m);
 410           return true;
 411         }
 412       }
 413     }
 414   }
 415   return false;
 416 }
 417 
 418 //------------------------------Ideal------------------------------------------
 419 // Return a node which is more "ideal" than the current node.  Must preserve
 420 // the CFG, but we can still strip out dead paths.
 421 Node *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 422   if( !can_reshape && !in(0) ) return NULL;     // Already degraded to a Copy
 423   assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");
 424 
 425   // Check for RegionNode with no Phi users and both inputs come from either
 426   // arm of the same IF.  If found, then the control-flow split is useless.
 427   bool has_phis = false;
 428   if (can_reshape) {            // Need DU info to check for Phi users
 429     has_phis = (has_phi() != NULL);       // Cache result
 430     if (has_phis && try_clean_mem_phi(phase)) {
 431       has_phis = false;







 432     }
 433 
 434     if (!has_phis) {            // No Phi users?  Nothing merging?
 435       for (uint i = 1; i < req()-1; i++) {
 436         Node *if1 = in(i);
 437         if( !if1 ) continue;
 438         Node *iff = if1->in(0);
 439         if( !iff || !iff->is_If() ) continue;
 440         for( uint j=i+1; j<req(); j++ ) {
 441           if( in(j) && in(j)->in(0) == iff &&
 442               if1->Opcode() != in(j)->Opcode() ) {
 443             // Add the IF Projections to the worklist. They (and the IF itself)
 444             // will be eliminated if dead.
 445             phase->is_IterGVN()->add_users_to_worklist(iff);
 446             set_req(i, iff->in(0));// Skip around the useless IF diamond
 447             set_req(j, NULL);
 448             return this;      // Record progress
 449           }
 450         }
 451       }


 879 
 880 //=============================================================================
 881 // note that these functions assume that the _adr_type field is flattened
 882 uint PhiNode::hash() const {
 883   const Type* at = _adr_type;
 884   return TypeNode::hash() + (at ? at->hash() : 0);
 885 }
 886 bool PhiNode::cmp( const Node &n ) const {
 887   return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;
 888 }
 889 static inline
 890 const TypePtr* flatten_phi_adr_type(const TypePtr* at) {
 891   if (at == NULL || at == TypePtr::BOTTOM)  return at;
 892   return Compile::current()->alias_type(at)->adr_type();
 893 }
 894 
 895 //----------------------------make---------------------------------------------
 896 // create a new phi with edges matching r and set (initially) to x
 897 PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {
 898   uint preds = r->req();   // Number of predecessor paths
 899   assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");
 900   PhiNode* p = new PhiNode(r, t, at);
 901   for (uint j = 1; j < preds; j++) {
 902     // Fill in all inputs, except those which the region does not yet have
 903     if (r->in(j) != NULL)
 904       p->init_req(j, x);
 905   }
 906   return p;
 907 }
 908 PhiNode* PhiNode::make(Node* r, Node* x) {
 909   const Type*    t  = x->bottom_type();
 910   const TypePtr* at = NULL;
 911   if (t == Type::MEMORY)  at = flatten_phi_adr_type(x->adr_type());
 912   return make(r, x, t, at);
 913 }
 914 PhiNode* PhiNode::make_blank(Node* r, Node* x) {
 915   const Type*    t  = x->bottom_type();
 916   const TypePtr* at = NULL;
 917   if (t == Type::MEMORY)  at = flatten_phi_adr_type(x->adr_type());
 918   return new PhiNode(r, t, at);
 919 }


1089         }
1090       }
1091     } else if (l->in(LoopNode::LoopBackControl) != NULL &&
1092                in(LoopNode::EntryControl) != NULL &&
1093                phase->type(l->in(LoopNode::LoopBackControl)) == Type::TOP) {
1094       // During CCP, if we saturate the type of a counted loop's Phi
1095       // before the special code for counted loop above has a chance
1096       // to run (that is as long as the type of the backedge's control
1097       // is top), we might end up with non monotonic types
1098       return phase->type(in(LoopNode::EntryControl))->filter_speculative(_type);
1099     }
1100   }
1101 
1102   // Until we have harmony between classes and interfaces in the type
1103   // lattice, we must tread carefully around phis which implicitly
1104   // convert the one to the other.
1105   const TypePtr* ttp = _type->make_ptr();
1106   const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;
1107   const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;
1108   bool is_intf = false;
1109   if (ttip != NULL) {
1110     ciKlass* k = ttip->klass();
1111     if (k->is_loaded() && k->is_interface())
1112       is_intf = true;
1113   }
1114   if (ttkp != NULL) {
1115     ciKlass* k = ttkp->klass();
1116     if (k->is_loaded() && k->is_interface())
1117       is_intf = true;
1118   }
1119 
1120   // Default case: merge all inputs
1121   const Type *t = Type::TOP;        // Merged type starting value
1122   for (uint i = 1; i < req(); ++i) {// For all paths in
1123     // Reachable control path?
1124     if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {
1125       const Type* ti = phase->type(in(i));
1126       // We assume that each input of an interface-valued Phi is a true
1127       // subtype of that interface.  This might not be true of the meet
1128       // of all the input types.  The lattice is not distributive in
1129       // such cases.  Ward off asserts in type.cpp by refusing to do
1130       // meets between interfaces and proper classes.
1131       const TypePtr* tip = ti->make_ptr();
1132       const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;
1133       if (tiip) {
1134         bool ti_is_intf = false;
1135         ciKlass* k = tiip->klass();
1136         if (k->is_loaded() && k->is_interface())
1137           ti_is_intf = true;


1154   //   (Occurrences of this case suggest improvements to Value methods.)
1155   //
1156   // It is not possible to see Type::BOTTOM values as phi inputs,
1157   // because the ciTypeFlow pre-pass produces verifier-quality types.
1158   const Type* ft = t->filter_speculative(_type);  // Worst case type
1159 
1160 #ifdef ASSERT
1161   // The following logic has been moved into TypeOopPtr::filter.
1162   const Type* jt = t->join_speculative(_type);
1163   if (jt->empty()) {           // Emptied out???
1164 
1165     // Check for evil case of 't' being a class and '_type' expecting an
1166     // interface.  This can happen because the bytecodes do not contain
1167     // enough type info to distinguish a Java-level interface variable
1168     // from a Java-level object variable.  If we meet 2 classes which
1169     // both implement interface I, but their meet is at 'j/l/O' which
1170     // doesn't implement I, we have no way to tell if the result should
1171     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
1172     // into a Phi which "knows" it's an Interface type we'll have to
1173     // uplift the type.
1174     if (!t->empty() && ttip && ttip->is_loaded() && ttip->klass()->is_interface()) {
1175       assert(ft == _type, ""); // Uplift to interface
1176     } else if (!t->empty() && ttkp && ttkp->is_loaded() && ttkp->klass()->is_interface()) {
1177       assert(ft == _type, ""); // Uplift to interface
1178     } else {
1179       // We also have to handle 'evil cases' of interface- vs. class-arrays
1180       Type::get_arrays_base_elements(jt, _type, NULL, &ttip);
1181       if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {
1182           assert(ft == _type, "");   // Uplift to array of interface
1183       } else {
1184         // Otherwise it's something stupid like non-overlapping int ranges
1185         // found on dying counted loops.
1186         assert(ft == Type::TOP, ""); // Canonical empty value
1187       }
1188     }
1189   }
1190 
1191   else {
1192 
1193     // If we have an interface-typed Phi and we narrow to a class type, the join
1194     // should report back the class.  However, if we have a J/L/Object
1195     // class-typed Phi and an interface flows in, it's possible that the meet &
1196     // join report an interface back out.  This isn't possible but happens


1318 
1319 //------------------------------Identity---------------------------------------
1320 // Check for Region being Identity.
1321 Node* PhiNode::Identity(PhaseGVN* phase) {
1322   // Check for no merging going on
1323   // (There used to be special-case code here when this->region->is_Loop.
1324   // It would check for a tributary phi on the backedge that the main phi
1325   // trivially, perhaps with a single cast.  The unique_input method
1326   // does all this and more, by reducing such tributaries to 'this'.)
1327   Node* uin = unique_input(phase, false);
1328   if (uin != NULL) {
1329     return uin;
1330   }
1331 
1332   int true_path = is_diamond_phi();
1333   if (true_path != 0) {
1334     Node* id = is_cmove_id(phase, true_path);
1335     if (id != NULL)  return id;
1336   }
1337 








1338   return this;                     // No identity
1339 }
1340 
1341 //-----------------------------unique_input------------------------------------
1342 // Find the unique value, discounting top, self-loops, and casts.
1343 // Return top if there are no inputs, and self if there are multiple.
1344 Node* PhiNode::unique_input(PhaseTransform* phase, bool uncast) {
1345   //  1) One unique direct input,
1346   // or if uncast is true:
1347   //  2) some of the inputs have an intervening ConstraintCast
1348   //  3) an input is a self loop
1349   //
1350   //  1) input   or   2) input     or   3) input __
1351   //     /   \           /   \               \  /  \
1352   //     \   /          |    cast             phi  cast
1353   //      phi            \   /               /  \  /
1354   //                      phi               /    --
1355 
1356   Node* r = in(0);                      // RegionNode
1357   if (r == NULL)  return in(1);         // Already degraded to a Copy


1779   return false; // The phi is not reachable from its inputs
1780 }
1781 
1782 
1783 //------------------------------Ideal------------------------------------------
1784 // Return a node which is more "ideal" than the current node.  Must preserve
1785 // the CFG, but we can still strip out dead paths.
1786 Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1787   // The next should never happen after 6297035 fix.
1788   if( is_copy() )               // Already degraded to a Copy ?
1789     return NULL;                // No change
1790 
1791   Node *r = in(0);              // RegionNode
1792   assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");
1793 
1794   // Note: During parsing, phis are often transformed before their regions.
1795   // This means we have to use type_or_null to defend against untyped regions.
1796   if( phase->type_or_null(r) == Type::TOP ) // Dead code?
1797     return NULL;                // No change
1798 


















1799   Node *top = phase->C->top();
1800   bool new_phi = (outcnt() == 0); // transforming new Phi
1801   // No change for igvn if new phi is not hooked
1802   if (new_phi && can_reshape)
1803     return NULL;
1804 
1805   // The are 2 situations when only one valid phi's input is left
1806   // (in addition to Region input).
1807   // One: region is not loop - replace phi with this input.
1808   // Two: region is loop - replace phi with top since this data path is dead
1809   //                       and we need to break the dead data loop.
1810   Node* progress = NULL;        // Record if any progress made
1811   for( uint j = 1; j < req(); ++j ){ // For all paths in
1812     // Check unreachable control paths
1813     Node* rc = r->in(j);
1814     Node* n = in(j);            // Get the input
1815     if (rc == NULL || phase->type(rc) == Type::TOP) {
1816       if (n != top) {           // Not already top?
1817         PhaseIterGVN *igvn = phase->is_IterGVN();
1818         if (can_reshape && igvn != NULL) {


2486   return in(0)->in(0);
2487 }
2488 
2489 
2490 #ifndef PRODUCT
2491 void CatchProjNode::dump_spec(outputStream *st) const {
2492   ProjNode::dump_spec(st);
2493   st->print("@bci %d ",_handler_bci);
2494 }
2495 #endif
2496 
2497 //=============================================================================
2498 //------------------------------Identity---------------------------------------
2499 // Check for CreateEx being Identity.
2500 Node* CreateExNode::Identity(PhaseGVN* phase) {
2501   if( phase->type(in(1)) == Type::TOP ) return in(1);
2502   if( phase->type(in(0)) == Type::TOP ) return in(0);
2503   // We only come from CatchProj, unless the CatchProj goes away.
2504   // If the CatchProj is optimized away, then we just carry the
2505   // exception oop through.






2506   CallNode *call = in(1)->in(0)->as_Call();
2507 
2508   return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )
2509     ? this
2510     : call->in(TypeFunc::Parms);
2511 }
2512 
2513 //=============================================================================
2514 //------------------------------Value------------------------------------------
2515 // Check for being unreachable.
2516 const Type* NeverBranchNode::Value(PhaseGVN* phase) const {
2517   if (!in(0) || in(0)->is_top()) return Type::TOP;
2518   return bottom_type();
2519 }
2520 
2521 //------------------------------Ideal------------------------------------------
2522 // Check for no longer being part of a loop
2523 Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2524   if (can_reshape && !in(0)->is_Loop()) {
2525     // Dead code elimination can sometimes delete this projection so


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


 356   nstack.push(n);
 357   visited.set(n->_idx);
 358   while (nstack.size() != 0) {
 359     n = nstack.pop();
 360     uint max = n->outcnt();
 361     for (uint i = 0; i < max; i++) {
 362       Node* m = n->raw_out(i);
 363       if (m != NULL && m->is_CFG()) {
 364         if (phase->eqv(m, this)) {
 365           return false; // We reached the Region node - it is not dead.
 366         }
 367         if (!visited.test_set(m->_idx))
 368           nstack.push(m);
 369       }
 370     }
 371   }
 372 
 373   return true; // The Region node is unreachable - it is dead.
 374 }
 375 
 376 Node* PhiNode::try_clean_mem_phi(PhaseGVN *phase) {
 377   // Incremental inlining + PhaseStringOpts sometimes produce:
 378   //
 379   // cmpP with 1 top input
 380   //           |
 381   //          If
 382   //         /  \
 383   //   IfFalse  IfTrue  /- Some Node
 384   //         \  /      /    /
 385   //        Region    / /-MergeMem
 386   //             \---Phi
 387   //
 388   //
 389   // It's expected by PhaseStringOpts that the Region goes away and is
 390   // replaced by If's control input but because there's still a Phi,
 391   // the Region stays in the graph. The top input from the cmpP is
 392   // propagated forward and a subgraph that is useful goes away. The
 393   // code below replaces the Phi with the MergeMem so that the Region
 394   // is simplified.
 395 
 396   if (type() == Type::MEMORY && is_diamond_phi(true)) {

 397     MergeMemNode* m = NULL;
 398     assert(req() == 3, "same as region");
 399     Node* r = in(0);
 400     for (uint i = 1; i < 3; ++i) {
 401       Node *mem = in(i);
 402       if (mem && mem->is_MergeMem() && r->in(i)->outcnt() == 1) {
 403         // Nothing is control-dependent on path #i except the region itself.
 404         m = mem->as_MergeMem();
 405         uint j = 3 - i;
 406         Node* other = in(j);
 407         if (other && other == m->base_memory()) {
 408           // m is a successor memory to other, and is not pinned inside the diamond, so push it out.
 409           // This will allow the diamond to collapse completely.
 410           return m;

 411         }
 412       }
 413     }
 414   }
 415   return NULL;
 416 }
 417 
 418 //------------------------------Ideal------------------------------------------
 419 // Return a node which is more "ideal" than the current node.  Must preserve
 420 // the CFG, but we can still strip out dead paths.
 421 Node *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 422   if( !can_reshape && !in(0) ) return NULL;     // Already degraded to a Copy
 423   assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");
 424 
 425   // Check for RegionNode with no Phi users and both inputs come from either
 426   // arm of the same IF.  If found, then the control-flow split is useless.
 427   bool has_phis = false;
 428   if (can_reshape) {            // Need DU info to check for Phi users
 429     has_phis = (has_phi() != NULL);       // Cache result
 430     if (has_phis) {
 431       PhiNode* phi = has_unique_phi();
 432       if (phi != NULL) {
 433         Node* m = phi->try_clean_mem_phi(phase);
 434         if (m != NULL) {
 435           phase->is_IterGVN()->replace_node(phi, m);
 436           has_phis = false;
 437         }
 438       }
 439     }
 440 
 441     if (!has_phis) {            // No Phi users?  Nothing merging?
 442       for (uint i = 1; i < req()-1; i++) {
 443         Node *if1 = in(i);
 444         if( !if1 ) continue;
 445         Node *iff = if1->in(0);
 446         if( !iff || !iff->is_If() ) continue;
 447         for( uint j=i+1; j<req(); j++ ) {
 448           if( in(j) && in(j)->in(0) == iff &&
 449               if1->Opcode() != in(j)->Opcode() ) {
 450             // Add the IF Projections to the worklist. They (and the IF itself)
 451             // will be eliminated if dead.
 452             phase->is_IterGVN()->add_users_to_worklist(iff);
 453             set_req(i, iff->in(0));// Skip around the useless IF diamond
 454             set_req(j, NULL);
 455             return this;      // Record progress
 456           }
 457         }
 458       }


 886 
 887 //=============================================================================
 888 // note that these functions assume that the _adr_type field is flattened
 889 uint PhiNode::hash() const {
 890   const Type* at = _adr_type;
 891   return TypeNode::hash() + (at ? at->hash() : 0);
 892 }
 893 bool PhiNode::cmp( const Node &n ) const {
 894   return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;
 895 }
 896 static inline
 897 const TypePtr* flatten_phi_adr_type(const TypePtr* at) {
 898   if (at == NULL || at == TypePtr::BOTTOM)  return at;
 899   return Compile::current()->alias_type(at)->adr_type();
 900 }
 901 
 902 //----------------------------make---------------------------------------------
 903 // create a new phi with edges matching r and set (initially) to x
 904 PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {
 905   uint preds = r->req();   // Number of predecessor paths
 906   assert(t != Type::MEMORY || at == flatten_phi_adr_type(at) || (flatten_phi_adr_type(at) == TypeAryPtr::VALUES && Compile::current()->flattened_accesses_share_alias()), "flatten at");
 907   PhiNode* p = new PhiNode(r, t, at);
 908   for (uint j = 1; j < preds; j++) {
 909     // Fill in all inputs, except those which the region does not yet have
 910     if (r->in(j) != NULL)
 911       p->init_req(j, x);
 912   }
 913   return p;
 914 }
 915 PhiNode* PhiNode::make(Node* r, Node* x) {
 916   const Type*    t  = x->bottom_type();
 917   const TypePtr* at = NULL;
 918   if (t == Type::MEMORY)  at = flatten_phi_adr_type(x->adr_type());
 919   return make(r, x, t, at);
 920 }
 921 PhiNode* PhiNode::make_blank(Node* r, Node* x) {
 922   const Type*    t  = x->bottom_type();
 923   const TypePtr* at = NULL;
 924   if (t == Type::MEMORY)  at = flatten_phi_adr_type(x->adr_type());
 925   return new PhiNode(r, t, at);
 926 }


1096         }
1097       }
1098     } else if (l->in(LoopNode::LoopBackControl) != NULL &&
1099                in(LoopNode::EntryControl) != NULL &&
1100                phase->type(l->in(LoopNode::LoopBackControl)) == Type::TOP) {
1101       // During CCP, if we saturate the type of a counted loop's Phi
1102       // before the special code for counted loop above has a chance
1103       // to run (that is as long as the type of the backedge's control
1104       // is top), we might end up with non monotonic types
1105       return phase->type(in(LoopNode::EntryControl))->filter_speculative(_type);
1106     }
1107   }
1108 
1109   // Until we have harmony between classes and interfaces in the type
1110   // lattice, we must tread carefully around phis which implicitly
1111   // convert the one to the other.
1112   const TypePtr* ttp = _type->make_ptr();
1113   const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;
1114   const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;
1115   bool is_intf = false;
1116   if (ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {
1117     is_intf = true;
1118   } else if (ttkp != NULL && ttkp->is_loaded() && ttkp->klass()->is_interface()) {
1119     is_intf = true;





1120   }
1121 
1122   // Default case: merge all inputs
1123   const Type *t = Type::TOP;        // Merged type starting value
1124   for (uint i = 1; i < req(); ++i) {// For all paths in
1125     // Reachable control path?
1126     if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {
1127       const Type* ti = phase->type(in(i));
1128       // We assume that each input of an interface-valued Phi is a true
1129       // subtype of that interface.  This might not be true of the meet
1130       // of all the input types.  The lattice is not distributive in
1131       // such cases.  Ward off asserts in type.cpp by refusing to do
1132       // meets between interfaces and proper classes.
1133       const TypePtr* tip = ti->make_ptr();
1134       const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;
1135       if (tiip) {
1136         bool ti_is_intf = false;
1137         ciKlass* k = tiip->klass();
1138         if (k->is_loaded() && k->is_interface())
1139           ti_is_intf = true;


1156   //   (Occurrences of this case suggest improvements to Value methods.)
1157   //
1158   // It is not possible to see Type::BOTTOM values as phi inputs,
1159   // because the ciTypeFlow pre-pass produces verifier-quality types.
1160   const Type* ft = t->filter_speculative(_type);  // Worst case type
1161 
1162 #ifdef ASSERT
1163   // The following logic has been moved into TypeOopPtr::filter.
1164   const Type* jt = t->join_speculative(_type);
1165   if (jt->empty()) {           // Emptied out???
1166 
1167     // Check for evil case of 't' being a class and '_type' expecting an
1168     // interface.  This can happen because the bytecodes do not contain
1169     // enough type info to distinguish a Java-level interface variable
1170     // from a Java-level object variable.  If we meet 2 classes which
1171     // both implement interface I, but their meet is at 'j/l/O' which
1172     // doesn't implement I, we have no way to tell if the result should
1173     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
1174     // into a Phi which "knows" it's an Interface type we'll have to
1175     // uplift the type.
1176     if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {
1177       assert(ft == _type, ""); // Uplift to interface
1178     } else if (!t->empty() && ttkp != NULL && ttkp->is_loaded() && ttkp->klass()->is_interface()) {
1179       assert(ft == _type, ""); // Uplift to interface
1180     } else {
1181       // We also have to handle 'evil cases' of interface- vs. class-arrays
1182       Type::get_arrays_base_elements(jt, _type, NULL, &ttip);
1183       if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {
1184           assert(ft == _type, "");   // Uplift to array of interface
1185       } else {
1186         // Otherwise it's something stupid like non-overlapping int ranges
1187         // found on dying counted loops.
1188         assert(ft == Type::TOP, ""); // Canonical empty value
1189       }
1190     }
1191   }
1192 
1193   else {
1194 
1195     // If we have an interface-typed Phi and we narrow to a class type, the join
1196     // should report back the class.  However, if we have a J/L/Object
1197     // class-typed Phi and an interface flows in, it's possible that the meet &
1198     // join report an interface back out.  This isn't possible but happens


1320 
1321 //------------------------------Identity---------------------------------------
1322 // Check for Region being Identity.
1323 Node* PhiNode::Identity(PhaseGVN* phase) {
1324   // Check for no merging going on
1325   // (There used to be special-case code here when this->region->is_Loop.
1326   // It would check for a tributary phi on the backedge that the main phi
1327   // trivially, perhaps with a single cast.  The unique_input method
1328   // does all this and more, by reducing such tributaries to 'this'.)
1329   Node* uin = unique_input(phase, false);
1330   if (uin != NULL) {
1331     return uin;
1332   }
1333 
1334   int true_path = is_diamond_phi();
1335   if (true_path != 0) {
1336     Node* id = is_cmove_id(phase, true_path);
1337     if (id != NULL)  return id;
1338   }
1339 
1340   if (phase->is_IterGVN()) {
1341     Node* m = try_clean_mem_phi(phase);
1342     if (m != NULL) {
1343       return m;
1344     }
1345   }
1346 
1347 
1348   return this;                     // No identity
1349 }
1350 
1351 //-----------------------------unique_input------------------------------------
1352 // Find the unique value, discounting top, self-loops, and casts.
1353 // Return top if there are no inputs, and self if there are multiple.
1354 Node* PhiNode::unique_input(PhaseTransform* phase, bool uncast) {
1355   //  1) One unique direct input,
1356   // or if uncast is true:
1357   //  2) some of the inputs have an intervening ConstraintCast
1358   //  3) an input is a self loop
1359   //
1360   //  1) input   or   2) input     or   3) input __
1361   //     /   \           /   \               \  /  \
1362   //     \   /          |    cast             phi  cast
1363   //      phi            \   /               /  \  /
1364   //                      phi               /    --
1365 
1366   Node* r = in(0);                      // RegionNode
1367   if (r == NULL)  return in(1);         // Already degraded to a Copy


1789   return false; // The phi is not reachable from its inputs
1790 }
1791 
1792 
1793 //------------------------------Ideal------------------------------------------
1794 // Return a node which is more "ideal" than the current node.  Must preserve
1795 // the CFG, but we can still strip out dead paths.
1796 Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1797   // The next should never happen after 6297035 fix.
1798   if( is_copy() )               // Already degraded to a Copy ?
1799     return NULL;                // No change
1800 
1801   Node *r = in(0);              // RegionNode
1802   assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");
1803 
1804   // Note: During parsing, phis are often transformed before their regions.
1805   // This means we have to use type_or_null to defend against untyped regions.
1806   if( phase->type_or_null(r) == Type::TOP ) // Dead code?
1807     return NULL;                // No change
1808 
1809   // If all inputs are value types of the same type, push the value type node down
1810   // through the phi because value type nodes should be merged through their input values.
1811   if (req() > 2 && in(1) != NULL && in(1)->is_ValueTypeBase() && (can_reshape || in(1)->is_ValueType())) {
1812     int opcode = in(1)->Opcode();
1813     uint i = 2;
1814     // Check if inputs are values of the same type
1815     for (; i < req() && in(i) && in(i)->is_ValueTypeBase() && in(i)->cmp(*in(1)); i++) {
1816       assert(in(i)->Opcode() == opcode, "mixing pointers and values?");
1817     }
1818     if (i == req()) {
1819       ValueTypeBaseNode* vt = in(1)->as_ValueTypeBase()->clone_with_phis(phase, in(0));
1820       for (uint i = 2; i < req(); ++i) {
1821         vt->merge_with(phase, in(i)->as_ValueTypeBase(), i, i == (req()-1));
1822       }
1823       return vt;
1824     }
1825   }
1826 
1827   Node *top = phase->C->top();
1828   bool new_phi = (outcnt() == 0); // transforming new Phi
1829   // No change for igvn if new phi is not hooked
1830   if (new_phi && can_reshape)
1831     return NULL;
1832 
1833   // The are 2 situations when only one valid phi's input is left
1834   // (in addition to Region input).
1835   // One: region is not loop - replace phi with this input.
1836   // Two: region is loop - replace phi with top since this data path is dead
1837   //                       and we need to break the dead data loop.
1838   Node* progress = NULL;        // Record if any progress made
1839   for( uint j = 1; j < req(); ++j ){ // For all paths in
1840     // Check unreachable control paths
1841     Node* rc = r->in(j);
1842     Node* n = in(j);            // Get the input
1843     if (rc == NULL || phase->type(rc) == Type::TOP) {
1844       if (n != top) {           // Not already top?
1845         PhaseIterGVN *igvn = phase->is_IterGVN();
1846         if (can_reshape && igvn != NULL) {


2514   return in(0)->in(0);
2515 }
2516 
2517 
2518 #ifndef PRODUCT
2519 void CatchProjNode::dump_spec(outputStream *st) const {
2520   ProjNode::dump_spec(st);
2521   st->print("@bci %d ",_handler_bci);
2522 }
2523 #endif
2524 
2525 //=============================================================================
2526 //------------------------------Identity---------------------------------------
2527 // Check for CreateEx being Identity.
2528 Node* CreateExNode::Identity(PhaseGVN* phase) {
2529   if( phase->type(in(1)) == Type::TOP ) return in(1);
2530   if( phase->type(in(0)) == Type::TOP ) return in(0);
2531   // We only come from CatchProj, unless the CatchProj goes away.
2532   // If the CatchProj is optimized away, then we just carry the
2533   // exception oop through.
2534 
2535   // CheckCastPPNode::Ideal() for value types reuses the exception
2536   // paths of a call to perform an allocation: we can see a Phi here.
2537   if (in(1)->is_Phi()) {
2538     return this;
2539   }
2540   CallNode *call = in(1)->in(0)->as_Call();
2541 
2542   return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )
2543     ? this
2544     : call->in(TypeFunc::Parms);
2545 }
2546 
2547 //=============================================================================
2548 //------------------------------Value------------------------------------------
2549 // Check for being unreachable.
2550 const Type* NeverBranchNode::Value(PhaseGVN* phase) const {
2551   if (!in(0) || in(0)->is_top()) return Type::TOP;
2552   return bottom_type();
2553 }
2554 
2555 //------------------------------Ideal------------------------------------------
2556 // Check for no longer being part of a loop
2557 Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2558   if (can_reshape && !in(0)->is_Loop()) {
2559     // Dead code elimination can sometimes delete this projection so
< prev index next >