hotspot/src/share/vm/opto/cfgnode.cpp
changeset 35545 a8f29dfd62b2
parent 34202 5d19ca9c25a8
child 35549 3415401a6b6e
equal deleted inserted replaced
35544:c7ec868d0923 35545:a8f29dfd62b2
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "classfile/systemDictionary.hpp"
    26 #include "classfile/systemDictionary.hpp"
    27 #include "memory/allocation.inline.hpp"
    27 #include "memory/allocation.inline.hpp"
    28 #include "oops/objArrayKlass.hpp"
    28 #include "oops/objArrayKlass.hpp"
    29 #include "opto/addnode.hpp"
    29 #include "opto/addnode.hpp"
       
    30 #include "opto/castnode.hpp"
    30 #include "opto/cfgnode.hpp"
    31 #include "opto/cfgnode.hpp"
    31 #include "opto/connode.hpp"
    32 #include "opto/connode.hpp"
    32 #include "opto/convertnode.hpp"
    33 #include "opto/convertnode.hpp"
    33 #include "opto/loopnode.hpp"
    34 #include "opto/loopnode.hpp"
    34 #include "opto/machnode.hpp"
    35 #include "opto/machnode.hpp"
  1146   // Check for no merging going on
  1147   // Check for no merging going on
  1147   // (There used to be special-case code here when this->region->is_Loop.
  1148   // (There used to be special-case code here when this->region->is_Loop.
  1148   // It would check for a tributary phi on the backedge that the main phi
  1149   // It would check for a tributary phi on the backedge that the main phi
  1149   // trivially, perhaps with a single cast.  The unique_input method
  1150   // trivially, perhaps with a single cast.  The unique_input method
  1150   // does all this and more, by reducing such tributaries to 'this'.)
  1151   // does all this and more, by reducing such tributaries to 'this'.)
  1151   Node* uin = unique_input(phase);
  1152   Node* uin = unique_input(phase, false);
  1152   if (uin != NULL) {
  1153   if (uin != NULL) {
  1153     return uin;
  1154     return uin;
  1154   }
  1155   }
  1155 
  1156 
  1156   int true_path = is_diamond_phi();
  1157   int true_path = is_diamond_phi();
  1163 }
  1164 }
  1164 
  1165 
  1165 //-----------------------------unique_input------------------------------------
  1166 //-----------------------------unique_input------------------------------------
  1166 // Find the unique value, discounting top, self-loops, and casts.
  1167 // Find the unique value, discounting top, self-loops, and casts.
  1167 // Return top if there are no inputs, and self if there are multiple.
  1168 // Return top if there are no inputs, and self if there are multiple.
  1168 Node* PhiNode::unique_input(PhaseTransform* phase) {
  1169 Node* PhiNode::unique_input(PhaseTransform* phase, bool uncast) {
  1169   //  1) One unique direct input, or
  1170   //  1) One unique direct input,
       
  1171   // or if uncast is true:
  1170   //  2) some of the inputs have an intervening ConstraintCast and
  1172   //  2) some of the inputs have an intervening ConstraintCast and
  1171   //     the type of input is the same or sharper (more specific)
  1173   //     the type of input is the same or sharper (more specific)
  1172   //     than the phi's type.
  1174   //     than the phi's type.
  1173   //  3) an input is a self loop
  1175   //  3) an input is a self loop
  1174   //
  1176   //
  1178   //      phi            \   /               /  \  /
  1180   //      phi            \   /               /  \  /
  1179   //                      phi               /    --
  1181   //                      phi               /    --
  1180 
  1182 
  1181   Node* r = in(0);                      // RegionNode
  1183   Node* r = in(0);                      // RegionNode
  1182   if (r == NULL)  return in(1);         // Already degraded to a Copy
  1184   if (r == NULL)  return in(1);         // Already degraded to a Copy
  1183   Node* uncasted_input = NULL; // The unique uncasted input (ConstraintCasts removed)
  1185   Node* input = NULL; // The unique direct input (maybe uncasted = ConstraintCasts removed)
  1184   Node* direct_input   = NULL; // The unique direct input
       
  1185 
  1186 
  1186   for (uint i = 1, cnt = req(); i < cnt; ++i) {
  1187   for (uint i = 1, cnt = req(); i < cnt; ++i) {
  1187     Node* rc = r->in(i);
  1188     Node* rc = r->in(i);
  1188     if (rc == NULL || phase->type(rc) == Type::TOP)
  1189     if (rc == NULL || phase->type(rc) == Type::TOP)
  1189       continue;                 // ignore unreachable control path
  1190       continue;                 // ignore unreachable control path
  1190     Node* n = in(i);
  1191     Node* n = in(i);
  1191     if (n == NULL)
  1192     if (n == NULL)
  1192       continue;
  1193       continue;
  1193     Node* un = n->uncast();
  1194     Node* un = uncast ? n->uncast() : n;
  1194     if (un == NULL || un == this || phase->type(un) == Type::TOP) {
  1195     if (un == NULL || un == this || phase->type(un) == Type::TOP) {
  1195       continue; // ignore if top, or in(i) and "this" are in a data cycle
  1196       continue; // ignore if top, or in(i) and "this" are in a data cycle
  1196     }
  1197     }
  1197     // Check for a unique uncasted input
  1198     // Check for a unique input (maybe uncasted)
  1198     if (uncasted_input == NULL) {
  1199     if (input == NULL) {
  1199       uncasted_input = un;
  1200       input = un;
  1200     } else if (uncasted_input != un) {
  1201     } else if (input != un) {
  1201       uncasted_input = NodeSentinel; // no unique uncasted input
  1202       input = NodeSentinel; // no unique input
  1202     }
  1203     }
  1203     // Check for a unique direct input
  1204   }
  1204     if (direct_input == NULL) {
  1205   if (input == NULL) {
  1205       direct_input = n;
       
  1206     } else if (direct_input != n) {
       
  1207       direct_input = NodeSentinel; // no unique direct input
       
  1208     }
       
  1209   }
       
  1210   if (direct_input == NULL) {
       
  1211     return phase->C->top();        // no inputs
  1206     return phase->C->top();        // no inputs
  1212   }
  1207   }
  1213   assert(uncasted_input != NULL,"");
  1208 
  1214 
  1209   if (input != NodeSentinel) {
  1215   if (direct_input != NodeSentinel) {
  1210     return input;           // one unique direct input
  1216     return direct_input;           // one unique direct input
       
  1217   }
       
  1218   if (uncasted_input != NodeSentinel &&
       
  1219       phase->type(uncasted_input)->higher_equal(type())) {
       
  1220     return uncasted_input;         // one unique uncasted input
       
  1221   }
  1211   }
  1222 
  1212 
  1223   // Nothing.
  1213   // Nothing.
  1224   return NULL;
  1214   return NULL;
  1225 }
  1215 }
  1648     // set_req() above may kill outputs if Phi is referenced
  1638     // set_req() above may kill outputs if Phi is referenced
  1649     // only by itself on the dead (top) control path.
  1639     // only by itself on the dead (top) control path.
  1650     return top;
  1640     return top;
  1651   }
  1641   }
  1652 
  1642 
  1653   Node* uin = unique_input(phase);
  1643   bool uncasted = false;
       
  1644   Node* uin = unique_input(phase, false);
       
  1645   if (uin == NULL) {
       
  1646     uncasted = true;
       
  1647     uin = unique_input(phase, true);
       
  1648   }
  1654   if (uin == top) {             // Simplest case: no alive inputs.
  1649   if (uin == top) {             // Simplest case: no alive inputs.
  1655     if (can_reshape)            // IGVN transformation
  1650     if (can_reshape)            // IGVN transformation
  1656       return top;
  1651       return top;
  1657     else
  1652     else
  1658       return NULL;              // Identity will return TOP
  1653       return NULL;              // Identity will return TOP
  1681           return NULL;
  1676           return NULL;
  1682         }
  1677         }
  1683       }
  1678       }
  1684     }
  1679     }
  1685 
  1680 
       
  1681     if (uncasted) {
       
  1682       const Type* phi_type = bottom_type();
       
  1683       assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type");
       
  1684       int opcode;
       
  1685       if (phi_type->isa_int()) {
       
  1686         opcode = Op_CastII;
       
  1687       } else {
       
  1688         const Type* uin_type = phase->type(uin);
       
  1689         if (phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) {
       
  1690           opcode = Op_CastPP;
       
  1691         } else {
       
  1692           opcode = Op_CheckCastPP;
       
  1693         }
       
  1694       }
       
  1695       // Add a cast to carry the control dependency of the Phi that is
       
  1696       // going away
       
  1697       Node* cast = ConstraintCastNode::make_cast(opcode, r, uin, phi_type, true);
       
  1698       cast = phase->transform(cast);
       
  1699       // set all inputs to the new cast so the Phi is removed by Identity
       
  1700       for (uint i = 1; i < req(); i++) {
       
  1701         set_req(i, cast);
       
  1702       }
       
  1703       uin = cast;
       
  1704     }
       
  1705 
  1686     // One unique input.
  1706     // One unique input.
  1687     debug_only(Node* ident = Identity(phase));
  1707     debug_only(Node* ident = Identity(phase));
  1688     // The unique input must eventually be detected by the Identity call.
  1708     // The unique input must eventually be detected by the Identity call.
  1689 #ifdef ASSERT
  1709 #ifdef ASSERT
  1690     if (ident != uin && !ident->is_top()) {
  1710     if (ident != uin && !ident->is_top()) {
  1696     }
  1716     }
  1697 #endif
  1717 #endif
  1698     assert(ident == uin || ident->is_top(), "Identity must clean this up");
  1718     assert(ident == uin || ident->is_top(), "Identity must clean this up");
  1699     return NULL;
  1719     return NULL;
  1700   }
  1720   }
  1701 
       
  1702 
  1721 
  1703   Node* opt = NULL;
  1722   Node* opt = NULL;
  1704   int true_path = is_diamond_phi();
  1723   int true_path = is_diamond_phi();
  1705   if( true_path != 0 ) {
  1724   if( true_path != 0 ) {
  1706     // Check for CMove'ing identity. If it would be unsafe,
  1725     // Check for CMove'ing identity. If it would be unsafe,