src/share/vm/opto/castnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/castnode.cpp

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "opto/addnode.hpp"

  27 #include "opto/castnode.hpp"
  28 #include "opto/connode.hpp"
  29 #include "opto/matcher.hpp"
  30 #include "opto/phaseX.hpp"
  31 #include "opto/subnode.hpp"
  32 #include "opto/type.hpp"
  33 
  34 //=============================================================================
  35 // If input is already higher or equal to cast type, then this is an identity.
  36 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {








  37   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
  38 }
  39 
  40 //------------------------------Value------------------------------------------
  41 // Take 'join' of input and cast-up type
  42 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
  43   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
  44   const Type* ft = phase->type(in(1))->filter_speculative(_type);
  45 
  46 #ifdef ASSERT
  47   // Previous versions of this function had some special case logic,
  48   // which is no longer necessary.  Make sure of the required effects.
  49   switch (Opcode()) {
  50     case Op_CastII:
  51     {
  52       const Type* t1 = phase->type(in(1));
  53       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
  54       const Type* rt = t1->join_speculative(_type);
  55       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
  56       break;
  57     }
  58     case Op_CastPP:
  59     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
  60         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
  61     assert(ft == Type::TOP, "special case #3");
  62     break;
  63   }
  64 #endif //ASSERT
  65 
  66   return ft;
  67 }
  68 
  69 //------------------------------Ideal------------------------------------------
  70 // Return a node which is more "ideal" than the current node.  Strip out
  71 // control copies
  72 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
  73   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
  74 }
  75 
  76 uint CastIINode::size_of() const {




  77   return sizeof(*this);
  78 }
  79 
  80 uint CastIINode::cmp(const Node &n) const {
  81   return TypeNode::cmp(n) && ((CastIINode&)n)._carry_dependency == _carry_dependency;














































  82 }
  83 
  84 Node *CastIINode::Identity(PhaseTransform *phase) {


  85   if (_carry_dependency) {
  86     return this;
  87   }
  88   return ConstraintCastNode::Identity(phase);
  89 }

  90 
  91 const Type *CastIINode::Value(PhaseTransform *phase) const {
  92   const Type *res = ConstraintCastNode::Value(phase);
  93 
  94   // Try to improve the type of the CastII if we recognize a CmpI/If
  95   // pattern.
  96   if (_carry_dependency) {
  97     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
  98       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
  99       Node* proj = in(0);
 100       if (proj->in(0)->in(1)->is_Bool()) {
 101         Node* b = proj->in(0)->in(1);
 102         if (b->in(1)->Opcode() == Op_CmpI) {
 103           Node* cmp = b->in(1);
 104           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
 105             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
 106             const Type* t = TypeInt::INT;
 107             BoolTest test = b->as_Bool()->_test;
 108             if (proj->is_IfFalse()) {
 109               test = test.negate();


 137             if (lo_long != (jlong)lo_int) {
 138               lo_int = min_jint;
 139             }
 140             if (hi_long != (jlong)hi_int) {
 141               hi_int = max_jint;
 142             }
 143 
 144             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
 145 
 146             res = res->filter_speculative(t);
 147 
 148             return res;
 149           }
 150         }
 151       }
 152     }
 153   }
 154   return res;
 155 }
 156 
 157 #ifndef PRODUCT
 158 void CastIINode::dump_spec(outputStream *st) const {
 159   TypeNode::dump_spec(st);
 160   if (_carry_dependency) {
 161     st->print(" carry dependency");
 162   }
 163 }
 164 #endif
 165 
 166 //=============================================================================
 167 //------------------------------Identity---------------------------------------
 168 // If input is already higher or equal to cast type, then this is an identity.
 169 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {








 170   // Toned down to rescue meeting at a Phi 3 different oops all implementing
 171   // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
 172   return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
 173 }
 174 
 175 //------------------------------Value------------------------------------------
 176 // Take 'join' of input and cast-up type, unless working with an Interface
 177 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
 178   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
 179 
 180   const Type *inn = phase->type(in(1));
 181   if( inn == Type::TOP ) return Type::TOP;  // No information yet
 182 
 183   const TypePtr *in_type   = inn->isa_ptr();
 184   const TypePtr *my_type   = _type->isa_ptr();
 185   const Type *result = _type;
 186   if( in_type != NULL && my_type != NULL ) {
 187     TypePtr::PTR   in_ptr    = in_type->ptr();
 188     if (in_ptr == TypePtr::Null) {
 189       result = in_type;


 236   // // history: JOIN used to cause weird corner case bugs
 237   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
 238   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
 239   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
 240   // const Type *join = in->join(_type);
 241   // // Check if join preserved NotNull'ness for pointers
 242   // if( join->isa_ptr() && _type->isa_ptr() ) {
 243   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
 244   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
 245   //   // If there isn't any NotNull'ness to preserve
 246   //   // OR if join preserved NotNull'ness then return it
 247   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
 248   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
 249   //     return join;
 250   //   }
 251   //   // ELSE return same old type as before
 252   //   return _type;
 253   // }
 254   // // Not joining two pointers
 255   // return join;
 256 }
 257 
 258 //------------------------------Ideal------------------------------------------
 259 // Return a node which is more "ideal" than the current node.  Strip out
 260 // control copies
 261 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
 262   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
 263 }
 264 
 265 //=============================================================================
 266 //------------------------------Value------------------------------------------
 267 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
 268   const Type* t = phase->type(in(1));
 269   if (t == Type::TOP) return Type::TOP;
 270   if (t->base() == Type_X && t->singleton()) {
 271     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
 272     if (bits == 0)   return TypePtr::NULL_PTR;
 273     return TypeRawPtr::make((address) bits);
 274   }
 275   return CastX2PNode::bottom_type();
 276 }
 277 
 278 //------------------------------Idealize---------------------------------------
 279 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
 280   if (t == Type::TOP)  return false;
 281   const TypeX* tl = t->is_intptr_t();
 282   jint lo = min_jint;




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "opto/addnode.hpp"
  27 #include "opto/callnode.hpp"
  28 #include "opto/castnode.hpp"
  29 #include "opto/connode.hpp"
  30 #include "opto/matcher.hpp"
  31 #include "opto/phaseX.hpp"
  32 #include "opto/subnode.hpp"
  33 #include "opto/type.hpp"
  34 
  35 //=============================================================================
  36 // If input is already higher or equal to cast type, then this is an identity.
  37 Node *ConstraintCastNode::Identity(PhaseTransform *phase) {
  38   Node* dom = dominating_cast(phase);
  39   if (dom != NULL) {
  40     assert(_carry_dependency, "only for casts that carry a dependency");
  41     return dom;
  42   }
  43   if (_carry_dependency) {
  44     return this;
  45   }
  46   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
  47 }
  48 
  49 //------------------------------Value------------------------------------------
  50 // Take 'join' of input and cast-up type
  51 const Type *ConstraintCastNode::Value(PhaseTransform *phase) const {
  52   if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;
  53   const Type* ft = phase->type(in(1))->filter_speculative(_type);
  54 
  55 #ifdef ASSERT
  56   // Previous versions of this function had some special case logic,
  57   // which is no longer necessary.  Make sure of the required effects.
  58   switch (Opcode()) {
  59     case Op_CastII:
  60     {
  61       const Type* t1 = phase->type(in(1));
  62       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
  63       const Type* rt = t1->join_speculative(_type);
  64       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
  65       break;
  66     }
  67     case Op_CastPP:
  68     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
  69         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
  70     assert(ft == Type::TOP, "special case #3");
  71     break;
  72   }
  73 #endif //ASSERT
  74 
  75   return ft;
  76 }
  77 
  78 //------------------------------Ideal------------------------------------------
  79 // Return a node which is more "ideal" than the current node.  Strip out
  80 // control copies
  81 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  82   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
  83 }
  84 
  85 uint ConstraintCastNode::cmp(const Node &n) const {
  86   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._carry_dependency == _carry_dependency;
  87 }
  88 
  89 uint ConstraintCastNode::size_of() const {
  90   return sizeof(*this);
  91 }
  92 
  93 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, bool carry_dependency) {
  94   switch(opcode) {
  95   case Op_CastII: {
  96     Node* cast = new CastIINode(n, t, carry_dependency);
  97     cast->set_req(0, c);
  98     return cast;
  99   }
 100   case Op_CastPP: {
 101     Node* cast = new CastPPNode(n, t, carry_dependency);
 102     cast->set_req(0, c);
 103     return cast;
 104   }
 105   case Op_CheckCastPP: return new CheckCastPPNode(c, n, t, carry_dependency);
 106   default:
 107     fatal("Bad opcode %d", opcode);
 108   }
 109   return NULL;
 110 }
 111 
 112 TypeNode* ConstraintCastNode::dominating_cast(PhaseTransform *phase) const {
 113   if (!carry_dependency()) {
 114     return NULL;
 115   }
 116   Node* val = in(1);
 117   Node* ctl = in(0);
 118   int opc = Opcode();
 119   if (ctl == NULL) {
 120     return NULL;
 121   }
 122   for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
 123     Node* u = val->fast_out(i);
 124     if (u != this &&
 125         u->Opcode() == opc &&
 126         u->in(0) != NULL &&
 127         u->bottom_type()->higher_equal(type())) {
 128       if (phase->is_dominator(u->in(0), ctl)) {
 129         return u->as_Type();
 130       }
 131       if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
 132           u->in(0)->is_Proj() && u->in(0)->in(0)->is_Initialize() &&
 133           u->in(1)->in(0)->as_Allocate()->initialization() == u->in(0)->in(0)) {
 134         // CheckCastPP following an allocation always dominates all
 135         // use of the allocation result
 136         return u->as_Type();
 137       }
 138     }
 139   }
 140   return NULL;
 141 }
 142 
 143 #ifndef PRODUCT
 144 void ConstraintCastNode::dump_spec(outputStream *st) const {
 145   TypeNode::dump_spec(st);
 146   if (_carry_dependency) {
 147     st->print(" carry dependency");
 148   }

 149 }
 150 #endif
 151 
 152 const Type *CastIINode::Value(PhaseTransform *phase) const {
 153   const Type *res = ConstraintCastNode::Value(phase);
 154 
 155   // Try to improve the type of the CastII if we recognize a CmpI/If
 156   // pattern.
 157   if (_carry_dependency) {
 158     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
 159       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
 160       Node* proj = in(0);
 161       if (proj->in(0)->in(1)->is_Bool()) {
 162         Node* b = proj->in(0)->in(1);
 163         if (b->in(1)->Opcode() == Op_CmpI) {
 164           Node* cmp = b->in(1);
 165           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
 166             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
 167             const Type* t = TypeInt::INT;
 168             BoolTest test = b->as_Bool()->_test;
 169             if (proj->is_IfFalse()) {
 170               test = test.negate();


 198             if (lo_long != (jlong)lo_int) {
 199               lo_int = min_jint;
 200             }
 201             if (hi_long != (jlong)hi_int) {
 202               hi_int = max_jint;
 203             }
 204 
 205             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
 206 
 207             res = res->filter_speculative(t);
 208 
 209             return res;
 210           }
 211         }
 212       }
 213     }
 214   }
 215   return res;
 216 }
 217 









 218 //=============================================================================
 219 //------------------------------Identity---------------------------------------
 220 // If input is already higher or equal to cast type, then this is an identity.
 221 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
 222   Node* dom = dominating_cast(phase);
 223   if (dom != NULL) {
 224     assert(_carry_dependency, "only for casts that carry a dependency");
 225     return dom;
 226   }
 227   if (_carry_dependency) {
 228     return this;
 229   }
 230   // Toned down to rescue meeting at a Phi 3 different oops all implementing
 231   // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
 232   return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
 233 }
 234 
 235 //------------------------------Value------------------------------------------
 236 // Take 'join' of input and cast-up type, unless working with an Interface
 237 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
 238   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
 239 
 240   const Type *inn = phase->type(in(1));
 241   if( inn == Type::TOP ) return Type::TOP;  // No information yet
 242 
 243   const TypePtr *in_type   = inn->isa_ptr();
 244   const TypePtr *my_type   = _type->isa_ptr();
 245   const Type *result = _type;
 246   if( in_type != NULL && my_type != NULL ) {
 247     TypePtr::PTR   in_ptr    = in_type->ptr();
 248     if (in_ptr == TypePtr::Null) {
 249       result = in_type;


 296   // // history: JOIN used to cause weird corner case bugs
 297   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
 298   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
 299   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
 300   // const Type *join = in->join(_type);
 301   // // Check if join preserved NotNull'ness for pointers
 302   // if( join->isa_ptr() && _type->isa_ptr() ) {
 303   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
 304   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
 305   //   // If there isn't any NotNull'ness to preserve
 306   //   // OR if join preserved NotNull'ness then return it
 307   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
 308   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
 309   //     return join;
 310   //   }
 311   //   // ELSE return same old type as before
 312   //   return _type;
 313   // }
 314   // // Not joining two pointers
 315   // return join;







 316 }
 317 
 318 //=============================================================================
 319 //------------------------------Value------------------------------------------
 320 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
 321   const Type* t = phase->type(in(1));
 322   if (t == Type::TOP) return Type::TOP;
 323   if (t->base() == Type_X && t->singleton()) {
 324     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
 325     if (bits == 0)   return TypePtr::NULL_PTR;
 326     return TypeRawPtr::make((address) bits);
 327   }
 328   return CastX2PNode::bottom_type();
 329 }
 330 
 331 //------------------------------Idealize---------------------------------------
 332 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
 333   if (t == Type::TOP)  return false;
 334   const TypeX* tl = t->is_intptr_t();
 335   jint lo = min_jint;


src/share/vm/opto/castnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File