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


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

 33 #include "opto/subnode.hpp"
 34 #include "opto/type.hpp"
 35 #include "utilities/checkedCast.hpp"
 36 
 37 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::FloatingNarrowing(true, true, "floating narrowing dependency"); // not pinned, narrows type
 38 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::FloatingNonNarrowing(true, false, "floating non-narrowing dependency"); // not pinned, doesn't narrow type
 39 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::NonFloatingNarrowing(false, true, "non-floating narrowing dependency"); // pinned, narrows type
 40 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::NonFloatingNonNarrowing(false, false, "non-floating non-narrowing dependency"); // pinned, doesn't narrow type
 41 
 42 //=============================================================================
 43 // If input is already higher or equal to cast type, then this is an identity.
 44 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 45   if (!_dependency.narrows_type()) {
 46     // If this cast doesn't carry a type dependency (i.e. not used for type narrowing), we cannot optimize it.
 47     return this;
 48   }
 49 
 50   // This cast node carries a type dependency. We can remove it if:
 51   // - Its input has a narrower type
 52   // - There's a dominating cast with same input but narrower type

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














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

117   return nullptr;
118 }
119 
120 uint ConstraintCastNode::hash() const {
121   return TypeNode::hash() + _dependency.hash() + (_extra_types != nullptr ? _extra_types->hash() : 0);
122 }
123 
124 bool ConstraintCastNode::cmp(const Node &n) const {
125   if (!TypeNode::cmp(n)) {
126     return false;
127   }
128   ConstraintCastNode& cast = (ConstraintCastNode&) n;
129   if (!cast._dependency.cmp(_dependency)) {
130     return false;
131   }
132   if (_extra_types == nullptr || cast._extra_types == nullptr) {
133     return _extra_types == cast._extra_types;
134   }
135   return _extra_types->eq(cast._extra_types);
136 }

394       const TypeLong* t_in_l = t_in->is_long();
395       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");
396       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");
397       if (tl != t_in_l) {
398         const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
399         Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
400         Node* convi2l = in1->clone();
401         convi2l->set_req(1, castii);
402         return convi2l;
403       }
404     }
405   }
406   // If it's a cast created by PhaseIdealLoop::short_running_loop(), don't transform it until the counted loop is created
407   // in next loop opts pass
408   if (!can_reshape || !used_at_inner_loop_exit_test()) {
409     return optimize_integer_cast(phase, T_LONG);
410   }
411   return nullptr;
412 }
413 










414 //------------------------------Value------------------------------------------
415 // Take 'join' of input and cast-up type, unless working with an Interface
416 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
417   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
418 
419   const Type *inn = phase->type(in(1));
420   if( inn == Type::TOP ) return Type::TOP;  // No information yet
421 
422   if (inn->isa_oopptr() && _type->isa_oopptr()) {
423     return ConstraintCastNode::Value(phase);
424   }
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 != nullptr && my_type != nullptr) {










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

 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 "opto/addnode.hpp"
 26 #include "opto/callnode.hpp"
 27 #include "opto/castnode.hpp"
 28 #include "opto/cfgnode.hpp"
 29 #include "opto/connode.hpp"
 30 #include "opto/graphKit.hpp"
 31 #include "opto/inlinetypenode.hpp"
 32 #include "opto/loopnode.hpp"
 33 #include "opto/matcher.hpp"
 34 #include "opto/phaseX.hpp"
 35 #include "opto/rootnode.hpp"
 36 #include "opto/subnode.hpp"
 37 #include "opto/type.hpp"
 38 #include "utilities/checkedCast.hpp"
 39 
 40 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::FloatingNarrowing(true, true, "floating narrowing dependency"); // not pinned, narrows type
 41 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::FloatingNonNarrowing(true, false, "floating non-narrowing dependency"); // not pinned, doesn't narrow type
 42 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::NonFloatingNarrowing(false, true, "non-floating narrowing dependency"); // pinned, narrows type
 43 const ConstraintCastNode::DependencyType ConstraintCastNode::DependencyType::NonFloatingNonNarrowing(false, false, "non-floating non-narrowing dependency"); // pinned, doesn't narrow type
 44 
 45 //=============================================================================
 46 // If input is already higher or equal to cast type, then this is an identity.
 47 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 48   if (!_dependency.narrows_type()) {
 49     // If this cast doesn't carry a type dependency (i.e. not used for type narrowing), we cannot optimize it.
 50     return this;
 51   }
 52 
 53   // This cast node carries a type dependency. We can remove it if:
 54   // - Its input has a narrower type
 55   // - There's a dominating cast with same input but narrower type

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

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