< 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 #include "utilities/checkedCast.hpp"
 36 
 37 //=============================================================================
 38 // If input is already higher or equal to cast type, then this is an identity.
 39 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 40   Node* dom = dominating_cast(phase, phase);
 41   if (dom != nullptr) {
 42     return dom;
 43   }
 44   if (_dependency != RegularDependency) {
 45     return this;
 46   }
 47   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 48 }
 49 
 50 //------------------------------Value------------------------------------------
 51 // Take 'join' of input and cast-up type

 81         assert(ft == Type::TOP, "special case #2");
 82       }
 83       break;
 84     }
 85     case Op_CastPP:
 86     if (in_type == TypePtr::NULL_PTR &&
 87         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
 88       assert(ft == Type::TOP, "special case #3");
 89       break;
 90     }
 91   }
 92 #endif //ASSERT
 93 
 94   return ft;
 95 }
 96 
 97 //------------------------------Ideal------------------------------------------
 98 // Return a node which is more "ideal" than the current node.  Strip out
 99 // control copies
100 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
101   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;

















102 }
103 
104 bool ConstraintCastNode::cmp(const Node &n) const {
105   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
106 }
107 
108 uint ConstraintCastNode::size_of() const {
109   return sizeof(*this);
110 }
111 
112 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
113   switch(opcode) {
114   case Op_CastII: {
115     Node* cast = new CastIINode(n, t, dependency);
116     cast->set_req(0, c);
117     return cast;
118   }
119   case Op_CastLL: {
120     Node* cast = new CastLLNode(n, t, dependency);
121     cast->set_req(0, c);

387   if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
388     const Type* t = Value(phase);
389     const Type* t_in = phase->type(in1);
390     if (t != Type::TOP && t_in != Type::TOP) {
391       const TypeLong* tl = t->is_long();
392       const TypeLong* t_in_l = t_in->is_long();
393       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");
394       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");
395       if (tl != t_in_l) {
396         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
397         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
398         Node* convi2l = in1->clone();
399         convi2l->set_req(1, castii);
400         return convi2l;
401       }
402     }
403   }
404   return optimize_integer_cast(phase, T_LONG);
405 }
406 










407 //------------------------------Value------------------------------------------
408 // Take 'join' of input and cast-up type, unless working with an Interface
409 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
410   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
411 
412   const Type *inn = phase->type(in(1));
413   if( inn == Type::TOP ) return Type::TOP;  // No information yet
414 
415   if (inn->isa_oopptr() && _type->isa_oopptr()) {
416     return ConstraintCastNode::Value(phase);
417   }
418 
419   const TypePtr *in_type = inn->isa_ptr();
420   const TypePtr *my_type = _type->isa_ptr();
421   const Type *result = _type;
422   if (in_type != nullptr && my_type != nullptr) {










423     TypePtr::PTR in_ptr = in_type->ptr();
424     if (in_ptr == TypePtr::Null) {
425       result = in_type;
426     } else if (in_ptr != TypePtr::Constant) {
427       result =  my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
428     }
429   }
430 
431   return result;
432 }
433 
434 //=============================================================================
435 //------------------------------Value------------------------------------------
436 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
437   const Type* t = phase->type(in(1));
438   if (t == Type::TOP) return Type::TOP;
439   if (t->base() == Type_X && t->singleton()) {
440     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
441     if (bits == 0)   return TypePtr::NULL_PTR;
442     return TypeRawPtr::make((address) bits);
443   }
444   return CastX2PNode::bottom_type();
445 }
446 
447 //------------------------------Idealize---------------------------------------

494     break;
495   }
496   return nullptr;
497 }
498 
499 //------------------------------Identity---------------------------------------
500 Node* CastX2PNode::Identity(PhaseGVN* phase) {
501   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
502   return this;
503 }
504 
505 //=============================================================================
506 //------------------------------Value------------------------------------------
507 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
508   const Type* t = phase->type(in(1));
509   if (t == Type::TOP) return Type::TOP;
510   if (t->base() == Type::RawPtr && t->singleton()) {
511     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
512     return TypeX::make(bits);
513   }
















514   return CastP2XNode::bottom_type();
515 }
516 
517 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
518   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
519 }
520 
521 //------------------------------Identity---------------------------------------
522 Node* CastP2XNode::Identity(PhaseGVN* phase) {
523   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
524   return this;
525 }
526 
527 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
528   Node* cast= nullptr;
529   if (type->isa_int()) {
530     cast = make_cast(Op_CastII, c, in, type, dependency);
531   } else if (type->isa_long()) {
532     cast = make_cast(Op_CastLL, c, in, type, dependency);
533   } 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 #include "utilities/checkedCast.hpp"
 39 
 40 //=============================================================================
 41 // If input is already higher or equal to cast type, then this is an identity.
 42 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 43   Node* dom = dominating_cast(phase, phase);
 44   if (dom != nullptr) {
 45     return dom;
 46   }
 47   if (_dependency != RegularDependency) {
 48     return this;
 49   }
 50   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 51 }
 52 
 53 //------------------------------Value------------------------------------------
 54 // Take 'join' of input and cast-up type

 84         assert(ft == Type::TOP, "special case #2");
 85       }
 86       break;
 87     }
 88     case Op_CastPP:
 89     if (in_type == TypePtr::NULL_PTR &&
 90         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
 91       assert(ft == Type::TOP, "special case #3");
 92       break;
 93     }
 94   }
 95 #endif //ASSERT
 96 
 97   return ft;
 98 }
 99 
100 //------------------------------Ideal------------------------------------------
101 // Return a node which is more "ideal" than the current node.  Strip out
102 // control copies
103 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
104   if (in(0) && remove_dead_region(phase, can_reshape)) {
105     return this;
106   }
107 
108   // Push cast through InlineTypeNode
109   InlineTypeNode* vt = in(1)->isa_InlineType();
110   if (vt != nullptr && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
111     Node* cast = clone();
112     cast->set_req(1, vt->get_oop());
113     vt = vt->clone()->as_InlineType();
114     if (!_type->maybe_null()) {
115       vt->as_InlineType()->set_is_init(*phase);
116     }
117     vt->set_oop(phase->transform(cast));
118     return vt;
119   }
120 
121   return nullptr;
122 }
123 
124 bool ConstraintCastNode::cmp(const Node &n) const {
125   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
126 }
127 
128 uint ConstraintCastNode::size_of() const {
129   return sizeof(*this);
130 }
131 
132 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
133   switch(opcode) {
134   case Op_CastII: {
135     Node* cast = new CastIINode(n, t, dependency);
136     cast->set_req(0, c);
137     return cast;
138   }
139   case Op_CastLL: {
140     Node* cast = new CastLLNode(n, t, dependency);
141     cast->set_req(0, c);

407   if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
408     const Type* t = Value(phase);
409     const Type* t_in = phase->type(in1);
410     if (t != Type::TOP && t_in != Type::TOP) {
411       const TypeLong* tl = t->is_long();
412       const TypeLong* t_in_l = t_in->is_long();
413       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");
414       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");
415       if (tl != t_in_l) {
416         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
417         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
418         Node* convi2l = in1->clone();
419         convi2l->set_req(1, castii);
420         return convi2l;
421       }
422     }
423   }
424   return optimize_integer_cast(phase, T_LONG);
425 }
426 
427 //=============================================================================
428 //------------------------------Identity---------------------------------------
429 // If input is already higher or equal to cast type, then this is an identity.
430 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
431   if (in(1)->is_InlineType() && _type->isa_instptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_instptr()->instance_klass())) {
432     return in(1);
433   }
434   return ConstraintCastNode::Identity(phase);
435 }
436 
437 //------------------------------Value------------------------------------------
438 // Take 'join' of input and cast-up type, unless working with an Interface
439 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
440   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
441 
442   const Type *inn = phase->type(in(1));
443   if( inn == Type::TOP ) return Type::TOP;  // No information yet
444 
445   if (inn->isa_oopptr() && _type->isa_oopptr()) {
446     return ConstraintCastNode::Value(phase);
447   }
448 
449   const TypePtr *in_type = inn->isa_ptr();
450   const TypePtr *my_type = _type->isa_ptr();
451   const Type *result = _type;
452   if (in_type != nullptr && my_type != nullptr) {
453     // TODO 8302672
454     if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
455       // Propagate array properties (not flat/null-free)
456       // Don't do this when StressReflectiveCode is enabled because it might lead to
457       // a dying data path while the corresponding flat/null-free check is not folded.
458       my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
459       if (my_type == nullptr) {
460         return Type::TOP; // Inconsistent properties
461       }
462     }
463     TypePtr::PTR in_ptr = in_type->ptr();
464     if (in_ptr == TypePtr::Null) {
465       result = in_type;
466     } else if (in_ptr != TypePtr::Constant) {
467       result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
468     }
469   }
470 
471   return result;
472 }
473 
474 //=============================================================================
475 //------------------------------Value------------------------------------------
476 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
477   const Type* t = phase->type(in(1));
478   if (t == Type::TOP) return Type::TOP;
479   if (t->base() == Type_X && t->singleton()) {
480     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
481     if (bits == 0)   return TypePtr::NULL_PTR;
482     return TypeRawPtr::make((address) bits);
483   }
484   return CastX2PNode::bottom_type();
485 }
486 
487 //------------------------------Idealize---------------------------------------

534     break;
535   }
536   return nullptr;
537 }
538 
539 //------------------------------Identity---------------------------------------
540 Node* CastX2PNode::Identity(PhaseGVN* phase) {
541   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
542   return this;
543 }
544 
545 //=============================================================================
546 //------------------------------Value------------------------------------------
547 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
548   const Type* t = phase->type(in(1));
549   if (t == Type::TOP) return Type::TOP;
550   if (t->base() == Type::RawPtr && t->singleton()) {
551     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
552     return TypeX::make(bits);
553   }
554 
555   if (t->is_zero_type() || !t->maybe_null()) {
556     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
557       Node* u = fast_out(i);
558       if (u->Opcode() == Op_OrL) {
559         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
560           Node* cmp = u->fast_out(j);
561           if (cmp->Opcode() == Op_CmpL) {
562             // Give CmpL a chance to get optimized
563             phase->record_for_igvn(cmp);
564           }
565         }
566       }
567     }
568   }
569 
570   return CastP2XNode::bottom_type();
571 }
572 
573 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
574   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
575 }
576 
577 //------------------------------Identity---------------------------------------
578 Node* CastP2XNode::Identity(PhaseGVN* phase) {
579   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
580   return this;
581 }
582 
583 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
584   Node* cast= nullptr;
585   if (type->isa_int()) {
586     cast = make_cast(Op_CastII, c, in, type, dependency);
587   } else if (type->isa_long()) {
588     cast = make_cast(Op_CastLL, c, in, type, dependency);
589   } else if (type->isa_float()) {
< prev index next >