< prev index next >

src/hotspot/share/opto/castnode.cpp

Print this page

 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 "castnode.hpp"
 26 #include "opto/addnode.hpp"
 27 #include "opto/callnode.hpp"
 28 #include "opto/castnode.hpp"
 29 #include "opto/cfgnode.hpp"
 30 #include "opto/connode.hpp"


 31 #include "opto/loopnode.hpp"
 32 #include "opto/matcher.hpp"
 33 #include "opto/phaseX.hpp"

 34 #include "opto/subnode.hpp"
 35 #include "opto/type.hpp"
 36 #include "utilities/checkedCast.hpp"
 37 
 38 //=============================================================================
 39 // If input is already higher or equal to cast type, then this is an identity.
 40 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 41   if (_dependency == UnconditionalDependency) {
 42     return this;
 43   }
 44   Node* dom = dominating_cast(phase, phase);
 45   if (dom != nullptr) {
 46     return dom;
 47   }
 48   return higher_equal_types(phase, in(1)) ? in(1) : this;
 49 }
 50 
 51 //------------------------------Value------------------------------------------
 52 // Take 'join' of input and cast-up type
 53 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {

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














105   if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) {
106     return TypeNode::Ideal(phase, can_reshape);
107   }

108   return nullptr;
109 }
110 
111 uint ConstraintCastNode::hash() const {
112   return TypeNode::hash() + (int)_dependency + (_extra_types != nullptr ? _extra_types->hash() : 0);
113 }
114 
115 bool ConstraintCastNode::cmp(const Node &n) const {
116   if (!TypeNode::cmp(n)) {
117     return false;
118   }
119   ConstraintCastNode& cast = (ConstraintCastNode&) n;
120   if (cast._dependency != _dependency) {
121     return false;
122   }
123   if (_extra_types == nullptr || cast._extra_types == nullptr) {
124     return _extra_types == cast._extra_types;
125   }
126   return _extra_types->eq(cast._extra_types);
127 }

406       const TypeLong* t_in_l = t_in->is_long();
407       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");
408       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");
409       if (tl != t_in_l) {
410         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
411         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
412         Node* convi2l = in1->clone();
413         convi2l->set_req(1, castii);
414         return convi2l;
415       }
416     }
417   }
418   // If it's a cast created by PhaseIdealLoop::short_running_loop(), don't transform it until the counted loop is created
419   // in next loop opts pass
420   if (!can_reshape || !used_at_inner_loop_exit_test()) {
421     return optimize_integer_cast(phase, T_LONG);
422   }
423   return nullptr;
424 }
425 










426 //------------------------------Value------------------------------------------
427 // Take 'join' of input and cast-up type, unless working with an Interface
428 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
429   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
430 
431   const Type *inn = phase->type(in(1));
432   if( inn == Type::TOP ) return Type::TOP;  // No information yet
433 
434   if (inn->isa_oopptr() && _type->isa_oopptr()) {
435     return ConstraintCastNode::Value(phase);
436   }
437 
438   const TypePtr *in_type = inn->isa_ptr();
439   const TypePtr *my_type = _type->isa_ptr();
440   const Type *result = _type;
441   if (in_type != nullptr && my_type != nullptr) {










442     TypePtr::PTR in_ptr = in_type->ptr();
443     if (in_ptr == TypePtr::Null) {
444       result = in_type;
445     } else if (in_ptr != TypePtr::Constant) {
446       result =  my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
447     }
448   }
449 
450   return result;
451 }
452 
453 //=============================================================================
454 //------------------------------Value------------------------------------------
455 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
456   const Type* t = phase->type(in(1));
457   if (t == Type::TOP) return Type::TOP;
458   if (t->base() == Type_X && t->singleton()) {
459     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
460     if (bits == 0)   return TypePtr::NULL_PTR;
461     return TypeRawPtr::make((address) bits);
462   }
463   return CastX2PNode::bottom_type();
464 }
465 
466 //------------------------------Idealize---------------------------------------

513     break;
514   }
515   return nullptr;
516 }
517 
518 //------------------------------Identity---------------------------------------
519 Node* CastX2PNode::Identity(PhaseGVN* phase) {
520   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
521   return this;
522 }
523 
524 //=============================================================================
525 //------------------------------Value------------------------------------------
526 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
527   const Type* t = phase->type(in(1));
528   if (t == Type::TOP) return Type::TOP;
529   if (t->base() == Type::RawPtr && t->singleton()) {
530     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
531     return TypeX::make(bits);
532   }
















533   return CastP2XNode::bottom_type();
534 }
535 
536 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
537   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
538 }
539 
540 //------------------------------Identity---------------------------------------
541 Node* CastP2XNode::Identity(PhaseGVN* phase) {
542   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
543   return this;
544 }
545 
546 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
547                                              const TypeTuple* types) {
548   if (type->isa_int()) {
549     return new CastIINode(c, in, type, dependency, false, types);
550   } else if (type->isa_long()) {
551     return new CastLLNode(c, in, type, dependency, types);
552   } else if (type->isa_half_float()) {

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

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

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

551     break;
552   }
553   return nullptr;
554 }
555 
556 //------------------------------Identity---------------------------------------
557 Node* CastX2PNode::Identity(PhaseGVN* phase) {
558   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
559   return this;
560 }
561 
562 //=============================================================================
563 //------------------------------Value------------------------------------------
564 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
565   const Type* t = phase->type(in(1));
566   if (t == Type::TOP) return Type::TOP;
567   if (t->base() == Type::RawPtr && t->singleton()) {
568     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
569     return TypeX::make(bits);
570   }
571 
572   if (t->is_zero_type() || !t->maybe_null()) {
573     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
574       Node* u = fast_out(i);
575       if (u->Opcode() == Op_OrL) {
576         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
577           Node* cmp = u->fast_out(j);
578           if (cmp->Opcode() == Op_CmpL) {
579             // Give CmpL a chance to get optimized
580             phase->record_for_igvn(cmp);
581           }
582         }
583       }
584     }
585   }
586 
587   return CastP2XNode::bottom_type();
588 }
589 
590 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
591   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
592 }
593 
594 //------------------------------Identity---------------------------------------
595 Node* CastP2XNode::Identity(PhaseGVN* phase) {
596   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
597   return this;
598 }
599 
600 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
601                                              const TypeTuple* types) {
602   if (type->isa_int()) {
603     return new CastIINode(c, in, type, dependency, false, types);
604   } else if (type->isa_long()) {
605     return new CastLLNode(c, in, type, dependency, types);
606   } else if (type->isa_half_float()) {
< prev index next >