< prev index next >

src/hotspot/share/opto/castnode.cpp

Print this page

 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 #include "castnode.hpp"
 35 
 36 //=============================================================================
 37 // If input is already higher or equal to cast type, then this is an identity.
 38 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 39   Node* dom = dominating_cast(phase, phase);
 40   if (dom != NULL) {
 41     return dom;
 42   }
 43   if (_dependency != RegularDependency) {
 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(PhaseGVN* phase) const {

 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 bool ConstraintCastNode::cmp(const Node &n) const {
 86   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _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, DependencyType dependency) {
 94   switch(opcode) {
 95   case Op_CastII: {
 96     Node* cast = new CastIINode(n, t, dependency);
 97     cast->set_req(0, c);
 98     return cast;
 99   }
100   case Op_CastLL: {
101     Node* cast = new CastLLNode(n, t, dependency);
102     cast->set_req(0, c);

358       const TypeLong* tl = t->is_long();
359       const TypeLong* t_in_l = t_in->is_long();
360       assert(tl->_lo >= t_in_l->_lo && tl->_hi <= t_in_l->_hi, "CastLL type should be narrower than or equal to the type of its input");
361       assert((tl != t_in_l) == (tl->_lo > t_in_l->_lo || tl->_hi < t_in_l->_hi), "if type differs then this nodes's type must be narrower");
362       if (tl != t_in_l) {
363         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
364         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
365         Node* convi2l = in1->clone();
366         convi2l->set_req(1, castii);
367         return convi2l;
368       }
369     }
370   }
371   return optimize_integer_cast(phase, T_LONG);
372 }
373 
374 //=============================================================================
375 //------------------------------Identity---------------------------------------
376 // If input is already higher or equal to cast type, then this is an identity.
377 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {



378   Node* dom = dominating_cast(phase, phase);
379   if (dom != NULL) {
380     return dom;
381   }
382   if (_dependency != RegularDependency) {
383     return this;
384   }
385   const Type* t = phase->type(in(1));
386   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
387     if (t->higher_equal_speculative(phase->type(this))) {
388       return in(1);
389     }
390   } else if (t == phase->type(this)) {
391     // Toned down to rescue meeting at a Phi 3 different oops all implementing
392     // the same interface.
393     return in(1);
394   }
395   return this;
396 }
397 
398 //------------------------------Value------------------------------------------
399 // Take 'join' of input and cast-up type, unless working with an Interface
400 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
401   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
402 
403   const Type *inn = phase->type(in(1));
404   if( inn == Type::TOP ) return Type::TOP;  // No information yet
405 
406   const TypePtr *in_type   = inn->isa_ptr();
407   const TypePtr *my_type   = _type->isa_ptr();
408   const Type *result = _type;
409   if( in_type != NULL && my_type != NULL ) {
410     TypePtr::PTR   in_ptr    = in_type->ptr();









411     if (in_ptr == TypePtr::Null) {
412       result = in_type;
413     } else if (in_ptr == TypePtr::Constant) {
414       if (my_type->isa_rawptr()) {
415         result = my_type;
416       } else {
417         const TypeOopPtr *jptr = my_type->isa_oopptr();
418         assert(jptr, "");
419         result = !in_type->higher_equal(_type)
420           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
421           : in_type;
422       }
423     } else {
424       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
425     }
426   }
427 
428   // This is the code from TypePtr::xmeet() that prevents us from
429   // having 2 ways to represent the same type. We have to replicate it
430   // here because we don't go through meet/join.

545     break;
546   }
547   return NULL;
548 }
549 
550 //------------------------------Identity---------------------------------------
551 Node* CastX2PNode::Identity(PhaseGVN* phase) {
552   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
553   return this;
554 }
555 
556 //=============================================================================
557 //------------------------------Value------------------------------------------
558 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
559   const Type* t = phase->type(in(1));
560   if (t == Type::TOP) return Type::TOP;
561   if (t->base() == Type::RawPtr && t->singleton()) {
562     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
563     return TypeX::make(bits);
564   }
















565   return CastP2XNode::bottom_type();
566 }
567 
568 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
569   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
570 }
571 
572 //------------------------------Identity---------------------------------------
573 Node* CastP2XNode::Identity(PhaseGVN* phase) {
574   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
575   return this;
576 }
577 
578 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
579   Node* cast= NULL;
580   if (type->isa_int()) {
581     cast = make_cast(Op_CastII, c, in, type, dependency);
582   } else if (type->isa_long()) {
583     cast = make_cast(Op_CastLL, c, in, type, dependency);
584   } else if (type->isa_float()) {

 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/graphKit.hpp"
 31 #include "opto/inlinetypenode.hpp"
 32 #include "opto/matcher.hpp"
 33 #include "opto/phaseX.hpp"
 34 #include "opto/rootnode.hpp"
 35 #include "opto/subnode.hpp"
 36 #include "opto/type.hpp"
 37 #include "castnode.hpp"
 38 
 39 //=============================================================================
 40 // If input is already higher or equal to cast type, then this is an identity.
 41 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 42   Node* dom = dominating_cast(phase, phase);
 43   if (dom != NULL) {
 44     return dom;
 45   }
 46   if (_dependency != RegularDependency) {
 47     return this;
 48   }
 49   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 50 }
 51 
 52 //------------------------------Value------------------------------------------
 53 // Take 'join' of input and cast-up type
 54 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {

 65       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
 66       const Type* rt = t1->join_speculative(_type);
 67       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
 68       break;
 69     }
 70     case Op_CastPP:
 71     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
 72         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
 73     assert(ft == Type::TOP, "special case #3");
 74     break;
 75   }
 76 #endif //ASSERT
 77 
 78   return ft;
 79 }
 80 
 81 //------------------------------Ideal------------------------------------------
 82 // Return a node which is more "ideal" than the current node.  Strip out
 83 // control copies
 84 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 85   if (in(0) && remove_dead_region(phase, can_reshape)) {
 86     return this;
 87   }
 88 
 89   // Push cast through InlineTypeNode
 90   InlineTypeNode* vt = in(1)->isa_InlineType();
 91   if (vt != NULL && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
 92     Node* cast = clone();
 93     cast->set_req(1, vt->get_oop());
 94     vt = vt->clone()->as_InlineType();
 95     vt->set_oop(phase->transform(cast));
 96     return vt;
 97   }
 98 
 99   return NULL;
100 }
101 
102 bool ConstraintCastNode::cmp(const Node &n) const {
103   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
104 }
105 
106 uint ConstraintCastNode::size_of() const {
107   return sizeof(*this);
108 }
109 
110 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
111   switch(opcode) {
112   case Op_CastII: {
113     Node* cast = new CastIINode(n, t, dependency);
114     cast->set_req(0, c);
115     return cast;
116   }
117   case Op_CastLL: {
118     Node* cast = new CastLLNode(n, t, dependency);
119     cast->set_req(0, c);

375       const TypeLong* tl = t->is_long();
376       const TypeLong* t_in_l = t_in->is_long();
377       assert(tl->_lo >= t_in_l->_lo && tl->_hi <= t_in_l->_hi, "CastLL type should be narrower than or equal to the type of its input");
378       assert((tl != t_in_l) == (tl->_lo > t_in_l->_lo || tl->_hi < t_in_l->_hi), "if type differs then this nodes's type must be narrower");
379       if (tl != t_in_l) {
380         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
381         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
382         Node* convi2l = in1->clone();
383         convi2l->set_req(1, castii);
384         return convi2l;
385       }
386     }
387   }
388   return optimize_integer_cast(phase, T_LONG);
389 }
390 
391 //=============================================================================
392 //------------------------------Identity---------------------------------------
393 // If input is already higher or equal to cast type, then this is an identity.
394 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
395   if (in(1)->is_InlineType() && _type->isa_instptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_instptr()->instance_klass())) {
396     return in(1);
397   }
398   Node* dom = dominating_cast(phase, phase);
399   if (dom != NULL) {
400     return dom;
401   }
402   if (_dependency != RegularDependency) {
403     return this;
404   }
405   const Type* t = phase->type(in(1));
406   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
407     if (t->higher_equal_speculative(phase->type(this))) {
408       return in(1);
409     }
410   } else if (t == phase->type(this)) {
411     // Toned down to rescue meeting at a Phi 3 different oops all implementing
412     // the same interface.
413     return in(1);
414   }
415   return this;
416 }
417 
418 //------------------------------Value------------------------------------------
419 // Take 'join' of input and cast-up type, unless working with an Interface
420 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
421   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
422 
423   const Type *inn = phase->type(in(1));
424   if( inn == Type::TOP ) return Type::TOP;  // No information yet
425 
426   const TypePtr *in_type   = inn->isa_ptr();
427   const TypePtr *my_type   = _type->isa_ptr();
428   const Type *result = _type;
429   if (in_type != NULL && my_type != NULL) {
430     if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
431       // Propagate array properties (not flat/null-free)
432       // Don't do this when StressReflectiveCode is enabled because it might lead to
433       // a dying data path while the corresponding flat/null-free check is not folded.
434       my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
435       if (my_type == NULL) {
436         return Type::TOP; // Inconsistent properties
437       }
438     }
439     TypePtr::PTR in_ptr = in_type->ptr();
440     if (in_ptr == TypePtr::Null) {
441       result = in_type;
442     } else if (in_ptr == TypePtr::Constant) {
443       if (my_type->isa_rawptr()) {
444         result = my_type;
445       } else {
446         const TypeOopPtr *jptr = my_type->isa_oopptr();
447         assert(jptr, "");
448         result = !in_type->higher_equal(_type)
449           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
450           : in_type;
451       }
452     } else {
453       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
454     }
455   }
456 
457   // This is the code from TypePtr::xmeet() that prevents us from
458   // having 2 ways to represent the same type. We have to replicate it
459   // here because we don't go through meet/join.

574     break;
575   }
576   return NULL;
577 }
578 
579 //------------------------------Identity---------------------------------------
580 Node* CastX2PNode::Identity(PhaseGVN* phase) {
581   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
582   return this;
583 }
584 
585 //=============================================================================
586 //------------------------------Value------------------------------------------
587 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
588   const Type* t = phase->type(in(1));
589   if (t == Type::TOP) return Type::TOP;
590   if (t->base() == Type::RawPtr && t->singleton()) {
591     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
592     return TypeX::make(bits);
593   }
594 
595   if (t->is_zero_type() || !t->maybe_null()) {
596     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
597       Node* u = fast_out(i);
598       if (u->Opcode() == Op_OrL) {
599         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
600           Node* cmp = u->fast_out(j);
601           if (cmp->Opcode() == Op_CmpL) {
602             // Give CmpL a chance to get optimized
603             phase->record_for_igvn(cmp);
604           }
605         }
606       }
607     }
608   }
609 
610   return CastP2XNode::bottom_type();
611 }
612 
613 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
614   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
615 }
616 
617 //------------------------------Identity---------------------------------------
618 Node* CastP2XNode::Identity(PhaseGVN* phase) {
619   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
620   return this;
621 }
622 
623 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
624   Node* cast= NULL;
625   if (type->isa_int()) {
626     cast = make_cast(Op_CastII, c, in, type, dependency);
627   } else if (type->isa_long()) {
628     cast = make_cast(Op_CastLL, c, in, type, dependency);
629   } else if (type->isa_float()) {
< prev index next >